From 43703dab15abf91586c0d4b5cd8165f55a9489d4 Mon Sep 17 00:00:00 2001 From: Ian Booth Date: Thu, 30 Nov 2023 15:24:30 +1000 Subject: [PATCH] Add DDL for block devices --- domain/schema/model.go | 68 ++++++++++++++++++++++++++++++++++++ domain/schema/schema_test.go | 6 ++++ 2 files changed, 74 insertions(+) diff --git a/domain/schema/model.go b/domain/schema/model.go index 5e181264fd1..ac62dd02aa2 100644 --- a/domain/schema/model.go +++ b/domain/schema/model.go @@ -26,6 +26,7 @@ func ModelDDL() *schema.Schema { unitSchema, spaceSchema, subnetSchema, + blockDeviceSchema, } schema := schema.New() @@ -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); +`) +} diff --git a/domain/schema/schema_test.go b/domain/schema/schema_test.go index 61d6d3919ee..3bb0ac9e800 100644 --- a/domain/schema/schema_test.go +++ b/domain/schema/schema_test.go @@ -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()) }