Skip to content

Commit

Permalink
Merge pull request juju#16495 from nvinuesa/juju-4833-1
Browse files Browse the repository at this point in the history
juju#16495

This patch adds the new spaces(/subnets) schema to create the following tables:
- spaces
- spaces_life

## Checklist

*If an item is not applicable, use `~strikethrough~`.*

- [X] Code style: imports ordered, good names, simple structure, etc
- [ ] ~Comments saying why design decisions were made~
- [X] Go unit tests, with comments saying what you're testing
- [ ] ~[Integration tests](https://github.com/juju/juju/tree/main/tests), with comments saying what you're testing~
- [ ] ~[doc.go](https://discourse.charmhub.io/t/readme-in-packages/451) added or updated in changed packages~

## QA steps

```
go test github.com/juju/juju/domain/schema/... -gocheck.v
```


## Links

**Jira card:** JUJU-4833
  • Loading branch information
jujubot authored Oct 26, 2023
2 parents d4c1bf6 + 36c89cf commit cae338e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
23 changes: 23 additions & 0 deletions domain/schema/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func ModelDDL() *schema.Schema {
changeLogModelNamespace,
modelConfig,
changeLogTriggersForTable("model_config", "key", tableModelConfig),
spacesSchema,
}

schema := schema.New()
Expand All @@ -44,3 +45,25 @@ CREATE TABLE model_config (
);
`)
}

func spacesSchema() schema.Patch {
return schema.MakePatch(`
CREATE TABLE provider_spaces (
uuid TEXT PRIMARY KEY,
name TEXT
);
CREATE TABLE spaces (
uuid TEXT PRIMARY KEY,
name TEXT NOT NULL,
is_public BOOLEAN,
provider_uuid TEXT,
CONSTRAINT fk_lease_pin_lease
FOREIGN KEY (provider_uuid)
REFERENCES provider_spaces(uuid)
);
CREATE UNIQUE INDEX idx_spaces_uuid_name
ON spaces (uuid, name);
`)
}
4 changes: 4 additions & 0 deletions domain/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ func (s *schemaSuite) TestModelDDLApply(c *gc.C) {

// Model config
"model_config",

// Spaces
"spaces",
"provider_spaces",
)
c.Assert(readTableNames(c, s.DB()), jc.SameContents, expected.Union(internalTableNames).SortedValues())
}
Expand Down

0 comments on commit cae338e

Please sign in to comment.