Skip to content

Commit

Permalink
Merge pull request juju#16654 from wallyworld/block-device-schema
Browse files Browse the repository at this point in the history
juju#16654

Add DDL to create model tables for block devices.

The tables created are:
- block_device
- block_device_link_device (block devices have 0 or more link devices)
- block_device_machine (join table for pairing block device with its machine)

## QA steps

N/A

## Links

**Jira card:** JUJU-5038
  • Loading branch information
jujubot authored Dec 1, 2023
2 parents 56b7f31 + 43703da commit cc851ed
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
68 changes: 68 additions & 0 deletions domain/schema/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func ModelDDL() *schema.Schema {
unitSchema,
spaceSchema,
subnetSchema,
blockDeviceSchema,
}

schema := schema.New()
Expand Down Expand Up @@ -325,3 +326,70 @@ CREATE UNIQUE INDEX idx_unit_net_node
ON unit (net_node_uuid);
`)
}

func blockDeviceSchema() schema.Patch {
return schema.MakePatch(`
CREATE TABLE block_device (
uuid TEXT PRIMARY KEY,
name TEXT NOT NULL,
label TEXT,
device_uuid TEXT,
hardware_id TEXT,
wwn TEXT,
bus_address TEXT,
serial_id TEXT,
filesystem_type_id INT,
size INT,
mount_point TEXT,
in_use BOOLEAN,
CONSTRAINT fk_filesystem_type
FOREIGN KEY (filesystem_type_id)
REFERENCES filesystem_type(id)
);
CREATE UNIQUE INDEX idx_block_device_name
ON block_device (name);
CREATE TABLE filesystem_type (
id INT PRIMARY KEY,
name TEXT NOT NULL
);
CREATE UNIQUE INDEX idx_filesystem_type_name
ON filesystem_type (name);
INSERT INTO filesystem_type VALUES
(0, 'ext4'),
(1, 'xfs'),
(2, 'btrfs'),
(3, 'zfs');
CREATE TABLE block_device_link_device (
block_device_uuid TEXT NOT NULL,
name TEXT NOT NULL,
CONSTRAINT fk_block_device_link_device
FOREIGN KEY (block_device_uuid)
REFERENCES block_device(uuid)
);
CREATE UNIQUE INDEX idx_block_device_link_device
ON block_device_link_device (block_device_uuid, name);
CREATE INDEX idx_block_device_link_device_device
ON block_device_link_device (block_device_uuid);
CREATE TABLE block_device_machine (
block_device_uuid TEXT PRIMARY KEY,
machine_uuid TEXT NOT NULL,
CONSTRAINT fk_block_device_machine_device
FOREIGN KEY (block_device_uuid)
REFERENCES block_device(uuid),
CONSTRAINT fk_block_device_machine
FOREIGN KEY (machine_uuid)
REFERENCES machine(uuid)
);
CREATE INDEX idx_block_device_machine
ON block_device_machine (machine_uuid);
`)
}
6 changes: 6 additions & 0 deletions domain/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ func (s *schemaSuite) TestModelDDLApply(c *gc.C) {
"provider_network_subnet",
"availability_zone",
"availability_zone_subnet",

// Block device
"block_device",
"filesystem_type",
"block_device_link_device",
"block_device_machine",
)
c.Assert(readTableNames(c, s.DB()), jc.SameContents, expected.Union(internalTableNames).SortedValues())
}
Expand Down

0 comments on commit cc851ed

Please sign in to comment.