From 018f1f7c630fb8a221ad6fd8c4208ef692bbe5cf Mon Sep 17 00:00:00 2001 From: Sean Klein Date: Thu, 8 Aug 2024 15:23:27 -0700 Subject: [PATCH] Schemas, expectorate --- .../tests/output/cmd-stdout | 20 +++++------ nexus/db-model/src/schema_versions.rs | 3 +- .../output/region_allocate_distinct_sleds.sql | 11 +++++- .../output/region_allocate_random_sleds.sql | 11 +++++- ..._allocate_with_snapshot_distinct_sleds.sql | 11 +++++- ...on_allocate_with_snapshot_random_sleds.sql | 11 +++++- schema/crdb/blueprint-dataset/up01.sql | 4 +++ schema/crdb/blueprint-dataset/up02.sql | 4 +++ schema/crdb/blueprint-dataset/up03.sql | 9 +++++ schema/crdb/blueprint-dataset/up04.sql | 35 +++++++++++++++++++ schema/crdb/dbinit.sql | 2 +- 11 files changed, 105 insertions(+), 16 deletions(-) create mode 100644 schema/crdb/blueprint-dataset/up01.sql create mode 100644 schema/crdb/blueprint-dataset/up02.sql create mode 100644 schema/crdb/blueprint-dataset/up03.sql create mode 100644 schema/crdb/blueprint-dataset/up04.sql diff --git a/dev-tools/reconfigurator-cli/tests/output/cmd-stdout b/dev-tools/reconfigurator-cli/tests/output/cmd-stdout index a2d6d3d17b..3c6a337357 100644 --- a/dev-tools/reconfigurator-cli/tests/output/cmd-stdout +++ b/dev-tools/reconfigurator-cli/tests/output/cmd-stdout @@ -24,25 +24,25 @@ sled ..................... subnet fd00:1122:3344:101::/64 zpools (10): ..................... (zpool) - ↳ SledDisk { disk_identity: DiskIdentity { vendor: "fake-vendor", model: "fake-model", serial: "serial-....................." }, disk_id: ..................... (physical_disk), policy: InService, state: Active } + ↳ (SledDisk { disk_identity: DiskIdentity { vendor: "fake-vendor", model: "fake-model", serial: "serial-....................." }, disk_id: ..................... (physical_disk), policy: InService, state: Active }, []) ..................... (zpool) - ↳ SledDisk { disk_identity: DiskIdentity { vendor: "fake-vendor", model: "fake-model", serial: "serial-....................." }, disk_id: ..................... (physical_disk), policy: InService, state: Active } + ↳ (SledDisk { disk_identity: DiskIdentity { vendor: "fake-vendor", model: "fake-model", serial: "serial-....................." }, disk_id: ..................... (physical_disk), policy: InService, state: Active }, []) ..................... (zpool) - ↳ SledDisk { disk_identity: DiskIdentity { vendor: "fake-vendor", model: "fake-model", serial: "serial-....................." }, disk_id: ..................... (physical_disk), policy: InService, state: Active } + ↳ (SledDisk { disk_identity: DiskIdentity { vendor: "fake-vendor", model: "fake-model", serial: "serial-....................." }, disk_id: ..................... (physical_disk), policy: InService, state: Active }, []) ..................... (zpool) - ↳ SledDisk { disk_identity: DiskIdentity { vendor: "fake-vendor", model: "fake-model", serial: "serial-....................." }, disk_id: ..................... (physical_disk), policy: InService, state: Active } + ↳ (SledDisk { disk_identity: DiskIdentity { vendor: "fake-vendor", model: "fake-model", serial: "serial-....................." }, disk_id: ..................... (physical_disk), policy: InService, state: Active }, []) ..................... (zpool) - ↳ SledDisk { disk_identity: DiskIdentity { vendor: "fake-vendor", model: "fake-model", serial: "serial-....................." }, disk_id: ..................... (physical_disk), policy: InService, state: Active } + ↳ (SledDisk { disk_identity: DiskIdentity { vendor: "fake-vendor", model: "fake-model", serial: "serial-....................." }, disk_id: ..................... (physical_disk), policy: InService, state: Active }, []) ..................... (zpool) - ↳ SledDisk { disk_identity: DiskIdentity { vendor: "fake-vendor", model: "fake-model", serial: "serial-....................." }, disk_id: ..................... (physical_disk), policy: InService, state: Active } + ↳ (SledDisk { disk_identity: DiskIdentity { vendor: "fake-vendor", model: "fake-model", serial: "serial-....................." }, disk_id: ..................... (physical_disk), policy: InService, state: Active }, []) ..................... (zpool) - ↳ SledDisk { disk_identity: DiskIdentity { vendor: "fake-vendor", model: "fake-model", serial: "serial-....................." }, disk_id: ..................... (physical_disk), policy: InService, state: Active } + ↳ (SledDisk { disk_identity: DiskIdentity { vendor: "fake-vendor", model: "fake-model", serial: "serial-....................." }, disk_id: ..................... (physical_disk), policy: InService, state: Active }, []) ..................... (zpool) - ↳ SledDisk { disk_identity: DiskIdentity { vendor: "fake-vendor", model: "fake-model", serial: "serial-....................." }, disk_id: ..................... (physical_disk), policy: InService, state: Active } + ↳ (SledDisk { disk_identity: DiskIdentity { vendor: "fake-vendor", model: "fake-model", serial: "serial-....................." }, disk_id: ..................... (physical_disk), policy: InService, state: Active }, []) ..................... (zpool) - ↳ SledDisk { disk_identity: DiskIdentity { vendor: "fake-vendor", model: "fake-model", serial: "serial-....................." }, disk_id: ..................... (physical_disk), policy: InService, state: Active } + ↳ (SledDisk { disk_identity: DiskIdentity { vendor: "fake-vendor", model: "fake-model", serial: "serial-....................." }, disk_id: ..................... (physical_disk), policy: InService, state: Active }, []) ..................... (zpool) - ↳ SledDisk { disk_identity: DiskIdentity { vendor: "fake-vendor", model: "fake-model", serial: "serial-....................." }, disk_id: ..................... (physical_disk), policy: InService, state: Active } + ↳ (SledDisk { disk_identity: DiskIdentity { vendor: "fake-vendor", model: "fake-model", serial: "serial-....................." }, disk_id: ..................... (physical_disk), policy: InService, state: Active }, []) > sled-add ..................... diff --git a/nexus/db-model/src/schema_versions.rs b/nexus/db-model/src/schema_versions.rs index 921123e41f..c07a9a6e37 100644 --- a/nexus/db-model/src/schema_versions.rs +++ b/nexus/db-model/src/schema_versions.rs @@ -17,7 +17,7 @@ use std::collections::BTreeMap; /// /// This must be updated when you change the database schema. Refer to /// schema/crdb/README.adoc in the root of this repository for details. -pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(87, 0, 0); +pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(88, 0, 0); /// List of all past database schema versions, in *reverse* order /// @@ -29,6 +29,7 @@ static KNOWN_VERSIONS: Lazy> = Lazy::new(|| { // | leaving the first copy as an example for the next person. // v // KnownVersion::new(next_int, "unique-dirname-with-the-sql-files"), + KnownVersion::new(88, "blueprint-dataset"), KnownVersion::new(87, "inv-dataset"), KnownVersion::new(86, "dataset-kinds-zone-and-debug"), KnownVersion::new(85, "add-migrations-by-time-created-index"), diff --git a/nexus/db-queries/tests/output/region_allocate_distinct_sleds.sql b/nexus/db-queries/tests/output/region_allocate_distinct_sleds.sql index 4e7dde244b..9ee71b403f 100644 --- a/nexus/db-queries/tests/output/region_allocate_distinct_sleds.sql +++ b/nexus/db-queries/tests/output/region_allocate_distinct_sleds.sql @@ -271,7 +271,10 @@ WITH dataset.port, dataset.kind, dataset.size_used, - dataset.zone_name + dataset.zone_name, + dataset.quota, + dataset.reservation, + dataset.compression ) ( SELECT @@ -286,6 +289,9 @@ WITH dataset.kind, dataset.size_used, dataset.zone_name, + dataset.quota, + dataset.reservation, + dataset.compression, old_regions.id, old_regions.time_created, old_regions.time_modified, @@ -313,6 +319,9 @@ UNION updated_datasets.kind, updated_datasets.size_used, updated_datasets.zone_name, + updated_datasets.quota, + updated_datasets.reservation, + updated_datasets.compression, inserted_regions.id, inserted_regions.time_created, inserted_regions.time_modified, diff --git a/nexus/db-queries/tests/output/region_allocate_random_sleds.sql b/nexus/db-queries/tests/output/region_allocate_random_sleds.sql index b2c164a6d9..369410c68c 100644 --- a/nexus/db-queries/tests/output/region_allocate_random_sleds.sql +++ b/nexus/db-queries/tests/output/region_allocate_random_sleds.sql @@ -269,7 +269,10 @@ WITH dataset.port, dataset.kind, dataset.size_used, - dataset.zone_name + dataset.zone_name, + dataset.quota, + dataset.reservation, + dataset.compression ) ( SELECT @@ -284,6 +287,9 @@ WITH dataset.kind, dataset.size_used, dataset.zone_name, + dataset.quota, + dataset.reservation, + dataset.compression, old_regions.id, old_regions.time_created, old_regions.time_modified, @@ -311,6 +317,9 @@ UNION updated_datasets.kind, updated_datasets.size_used, updated_datasets.zone_name, + updated_datasets.quota, + updated_datasets.reservation, + updated_datasets.compression, inserted_regions.id, inserted_regions.time_created, inserted_regions.time_modified, diff --git a/nexus/db-queries/tests/output/region_allocate_with_snapshot_distinct_sleds.sql b/nexus/db-queries/tests/output/region_allocate_with_snapshot_distinct_sleds.sql index 97ee23f82e..9251139c4e 100644 --- a/nexus/db-queries/tests/output/region_allocate_with_snapshot_distinct_sleds.sql +++ b/nexus/db-queries/tests/output/region_allocate_with_snapshot_distinct_sleds.sql @@ -282,7 +282,10 @@ WITH dataset.port, dataset.kind, dataset.size_used, - dataset.zone_name + dataset.zone_name, + dataset.quota, + dataset.reservation, + dataset.compression ) ( SELECT @@ -297,6 +300,9 @@ WITH dataset.kind, dataset.size_used, dataset.zone_name, + dataset.quota, + dataset.reservation, + dataset.compression, old_regions.id, old_regions.time_created, old_regions.time_modified, @@ -324,6 +330,9 @@ UNION updated_datasets.kind, updated_datasets.size_used, updated_datasets.zone_name, + updated_datasets.quota, + updated_datasets.reservation, + updated_datasets.compression, inserted_regions.id, inserted_regions.time_created, inserted_regions.time_modified, diff --git a/nexus/db-queries/tests/output/region_allocate_with_snapshot_random_sleds.sql b/nexus/db-queries/tests/output/region_allocate_with_snapshot_random_sleds.sql index a1cc103594..c8aa8adf2e 100644 --- a/nexus/db-queries/tests/output/region_allocate_with_snapshot_random_sleds.sql +++ b/nexus/db-queries/tests/output/region_allocate_with_snapshot_random_sleds.sql @@ -280,7 +280,10 @@ WITH dataset.port, dataset.kind, dataset.size_used, - dataset.zone_name + dataset.zone_name, + dataset.quota, + dataset.reservation, + dataset.compression ) ( SELECT @@ -295,6 +298,9 @@ WITH dataset.kind, dataset.size_used, dataset.zone_name, + dataset.quota, + dataset.reservation, + dataset.compression, old_regions.id, old_regions.time_created, old_regions.time_modified, @@ -322,6 +328,9 @@ UNION updated_datasets.kind, updated_datasets.size_used, updated_datasets.zone_name, + updated_datasets.quota, + updated_datasets.reservation, + updated_datasets.compression, inserted_regions.id, inserted_regions.time_created, inserted_regions.time_modified, diff --git a/schema/crdb/blueprint-dataset/up01.sql b/schema/crdb/blueprint-dataset/up01.sql new file mode 100644 index 0000000000..cfdde5bacd --- /dev/null +++ b/schema/crdb/blueprint-dataset/up01.sql @@ -0,0 +1,4 @@ +ALTER TABLE omicron.public.dataset + ADD COLUMN IF NOT EXISTS quota INT8, + ADD COLUMN IF NOT EXISTS reservation INT8, + ADD COLUMN IF NOT EXISTS compression TEXT diff --git a/schema/crdb/blueprint-dataset/up02.sql b/schema/crdb/blueprint-dataset/up02.sql new file mode 100644 index 0000000000..a1a0dc7cb7 --- /dev/null +++ b/schema/crdb/blueprint-dataset/up02.sql @@ -0,0 +1,4 @@ +CREATE TYPE IF NOT EXISTS omicron.public.bp_dataset_disposition AS ENUM ( + 'in_service', + 'expunged' +) diff --git a/schema/crdb/blueprint-dataset/up03.sql b/schema/crdb/blueprint-dataset/up03.sql new file mode 100644 index 0000000000..2ce95db275 --- /dev/null +++ b/schema/crdb/blueprint-dataset/up03.sql @@ -0,0 +1,9 @@ +-- description of a collection of omicron datasets stored in a blueprint +CREATE TABLE IF NOT EXISTS omicron.public.bp_sled_omicron_datasets ( + -- foreign key into the `blueprint` table + blueprint_id UUID NOT NULL, + sled_id UUID NOT NULL, + generation INT8 NOT NULL, + + PRIMARY KEY (blueprint_id, sled_id) +) diff --git a/schema/crdb/blueprint-dataset/up04.sql b/schema/crdb/blueprint-dataset/up04.sql new file mode 100644 index 0000000000..121984740c --- /dev/null +++ b/schema/crdb/blueprint-dataset/up04.sql @@ -0,0 +1,35 @@ +-- description of an omicron dataset specified in a blueprint. +CREATE TABLE IF NOT EXISTS omicron.public.bp_omicron_dataset ( + -- foreign key into the `blueprint` table + blueprint_id UUID NOT NULL, + sled_id UUID NOT NULL, + id UUID NOT NULL, + + -- Dataset disposition + disposition omicron.public.bp_dataset_disposition NOT NULL, + + pool_id UUID NOT NULL, + kind omicron.public.dataset_kind NOT NULL, + -- Only valid if kind = zone + zone_name TEXT, + + -- Only valid if kind = crucible + ip INET, + port INT4 CHECK (port BETWEEN 0 AND 65535), + + quota INT8, + reservation INT8, + compression TEXT, + + CONSTRAINT zone_name_for_zone_kind CHECK ( + (kind != 'zone') OR + (kind = 'zone' AND zone_name IS NOT NULL) + ), + + CONSTRAINT ip_and_port_set_for_crucible CHECK ( + (kind != 'crucible') OR + (kind = 'crucible' AND ip IS NOT NULL and port IS NOT NULL) + ), + + PRIMARY KEY (blueprint_id, id) +) diff --git a/schema/crdb/dbinit.sql b/schema/crdb/dbinit.sql index 7bd738f867..a232ededc0 100644 --- a/schema/crdb/dbinit.sql +++ b/schema/crdb/dbinit.sql @@ -4247,7 +4247,7 @@ INSERT INTO omicron.public.db_metadata ( version, target_version ) VALUES - (TRUE, NOW(), NOW(), '87.0.0', NULL) + (TRUE, NOW(), NOW(), '88.0.0', NULL) ON CONFLICT DO NOTHING; COMMIT;