diff --git a/nexus/db-model/src/schema_versions.rs b/nexus/db-model/src/schema_versions.rs index ad80039d57c..9fcc215496b 100644 --- a/nexus/db-model/src/schema_versions.rs +++ b/nexus/db-model/src/schema_versions.rs @@ -16,7 +16,7 @@ use std::{collections::BTreeMap, sync::LazyLock}; /// /// 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: Version = Version::new(309, 0, 0); +pub const SCHEMA_VERSION: Version = Version::new(310, 0, 0); /// List of all past database schema versions, in *reverse* order /// @@ -28,6 +28,7 @@ pub static KNOWN_VERSIONS: LazyLock> = LazyLock::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(310, "add-unadopted-sled-and-rack-tables"), KnownVersion::new(309, "fm-certificate-de"), KnownVersion::new(308, "inv-power-shelf-psu"), KnownVersion::new(307, "add-rack-id-to-inv-sled-agent"), diff --git a/schema/crdb/add-unadopted-sled-and-rack-tables/up01.sql b/schema/crdb/add-unadopted-sled-and-rack-tables/up01.sql new file mode 100644 index 00000000000..438337dcd7c --- /dev/null +++ b/schema/crdb/add-unadopted-sled-and-rack-tables/up01.sql @@ -0,0 +1,21 @@ +-- Tracks other racks that have joined the underlay network but haven't been +-- adopted into the multirack cluster. +-- +-- If/when a rack is adopted, its row in this table should be marked deleted, +-- and a corresponding row should be inserted into the `rack` table. +CREATE TABLE IF NOT EXISTS omicron.public.unadopted_rack ( + -- This should be the same id that gets used for the `rack` table, as well + -- as the `rack_id` column in `unadopted_sled`: + id UUID PRIMARY KEY, + + time_created TIMESTAMPTZ NOT NULL, + time_modified TIMESTAMPTZ NOT NULL, + time_deleted TIMESTAMPTZ, + + -- The IPv6 underlay /56 prefix for the rack: + rack_subnet INET NOT NULL, + + -- Underlay address of the particular sled-agent instance on the unadopted + -- rack that's running the multirack join service: + join_service_ip INET NOT NULL +); diff --git a/schema/crdb/add-unadopted-sled-and-rack-tables/up02.sql b/schema/crdb/add-unadopted-sled-and-rack-tables/up02.sql new file mode 100644 index 00000000000..36e8eaa5ded --- /dev/null +++ b/schema/crdb/add-unadopted-sled-and-rack-tables/up02.sql @@ -0,0 +1,34 @@ +-- Tracks sleds from other racks that have joined the underlay network but +-- haven't been adopted into the multirack cluster. +-- +-- If/when these sleds are adopted, these rows should be marked deleted, and +-- there will subsequently be corresponding rows created in the `sled` and +-- `inv_sled_agent` tables via the normal mechanisms. +CREATE TABLE IF NOT EXISTS omicron.public.unadopted_sled ( + id UUID PRIMARY KEY, + -- Foreign key into the `unadopted_rack` table (though, also, the rack ID + -- that gets used in the `rack` table should be the same if/when the rack + -- is adopted) + rack_id UUID NOT NULL, + + time_created TIMESTAMPTZ NOT NULL, + time_modified TIMESTAMPTZ NOT NULL, + time_deleted TIMESTAMPTZ, + + -- Baseboard information about the sled + serial_number STRING(63) NOT NULL, + part_number STRING(63) NOT NULL, + + sled_agent_ip INET NOT NULL, + + -- This tracks whether this particular sled's sled-agent has been + -- successfully started by the multirack join service: + sled_agent_started BOOL NOT NULL, + -- This nullable column should be set to the last error we've seen for this + -- particular sled's sled-agent startup process, if any: + last_start_error_seen TEXT, + + CONSTRAINT start_error_is_null_if_started CHECK ( + (NOT sled_agent_started) OR (last_start_error_seen IS NULL) + ) +); diff --git a/schema/crdb/add-unadopted-sled-and-rack-tables/up03.sql b/schema/crdb/add-unadopted-sled-and-rack-tables/up03.sql new file mode 100644 index 00000000000..55a678732fd --- /dev/null +++ b/schema/crdb/add-unadopted-sled-and-rack-tables/up03.sql @@ -0,0 +1,3 @@ +CREATE UNIQUE INDEX IF NOT EXISTS lookup_unadopted_rack_by_id ON omicron.public.unadopted_rack ( + id +) WHERE time_deleted IS NULL; diff --git a/schema/crdb/add-unadopted-sled-and-rack-tables/up03.verify.sql b/schema/crdb/add-unadopted-sled-and-rack-tables/up03.verify.sql new file mode 100644 index 00000000000..109627899aa --- /dev/null +++ b/schema/crdb/add-unadopted-sled-and-rack-tables/up03.verify.sql @@ -0,0 +1,2 @@ +-- DO NOT EDIT. Generated by test_migration_verification_files. +SELECT CAST(IF((SELECT true WHERE EXISTS (SELECT index_name FROM omicron.crdb_internal.table_indexes WHERE descriptor_name = 'unadopted_rack' AND index_name = 'lookup_unadopted_rack_by_id')),'true','Schema change verification failed: index lookup_unadopted_rack_by_id on table unadopted_rack does not exist') AS BOOL); diff --git a/schema/crdb/add-unadopted-sled-and-rack-tables/up04.sql b/schema/crdb/add-unadopted-sled-and-rack-tables/up04.sql new file mode 100644 index 00000000000..b35285c83ee --- /dev/null +++ b/schema/crdb/add-unadopted-sled-and-rack-tables/up04.sql @@ -0,0 +1,3 @@ +CREATE UNIQUE INDEX IF NOT EXISTS lookup_unadopted_sled_by_id ON omicron.public.unadopted_sled ( + id +) WHERE time_deleted IS NULL; diff --git a/schema/crdb/add-unadopted-sled-and-rack-tables/up04.verify.sql b/schema/crdb/add-unadopted-sled-and-rack-tables/up04.verify.sql new file mode 100644 index 00000000000..957185e5e74 --- /dev/null +++ b/schema/crdb/add-unadopted-sled-and-rack-tables/up04.verify.sql @@ -0,0 +1,2 @@ +-- DO NOT EDIT. Generated by test_migration_verification_files. +SELECT CAST(IF((SELECT true WHERE EXISTS (SELECT index_name FROM omicron.crdb_internal.table_indexes WHERE descriptor_name = 'unadopted_sled' AND index_name = 'lookup_unadopted_sled_by_id')),'true','Schema change verification failed: index lookup_unadopted_sled_by_id on table unadopted_sled does not exist') AS BOOL); diff --git a/schema/crdb/dbinit.sql b/schema/crdb/dbinit.sql index 695be128c8b..92742f3b6d4 100644 --- a/schema/crdb/dbinit.sql +++ b/schema/crdb/dbinit.sql @@ -9730,6 +9730,70 @@ CREATE TABLE IF NOT EXISTS omicron.public.fm_config ( ) ); +-- Tracks other racks that have joined the underlay network but haven't been +-- adopted into the multirack cluster. +-- +-- If/when a rack is adopted, its row in this table should be marked deleted, +-- and a corresponding row should be inserted into the `rack` table. +CREATE TABLE IF NOT EXISTS omicron.public.unadopted_rack ( + -- This should be the same id that gets used for the `rack` table, as well + -- as the `rack_id` column in `unadopted_sled`: + id UUID PRIMARY KEY, + + time_created TIMESTAMPTZ NOT NULL, + time_modified TIMESTAMPTZ NOT NULL, + time_deleted TIMESTAMPTZ, + + -- The IPv6 underlay /56 prefix for the rack: + rack_subnet INET NOT NULL, + + -- Underlay address of the particular sled-agent instance on the unadopted + -- rack that's running the multirack join service: + join_service_ip INET NOT NULL +); + +CREATE UNIQUE INDEX IF NOT EXISTS lookup_unadopted_rack_by_id ON omicron.public.unadopted_rack ( + id +) WHERE time_deleted IS NULL; + +-- Tracks sleds from other racks that have joined the underlay network but +-- haven't been adopted into the multirack cluster. +-- +-- If/when these sleds are adopted, these rows should be marked deleted, and +-- there will subsequently be corresponding rows created in the `sled` and +-- `inv_sled_agent` tables via the normal mechanisms. +CREATE TABLE IF NOT EXISTS omicron.public.unadopted_sled ( + id UUID PRIMARY KEY, + -- Foreign key into the `unadopted_rack` table (though, also, the rack ID + -- that gets used in the `rack` table should be the same if/when the rack + -- is adopted) + rack_id UUID NOT NULL, + + time_created TIMESTAMPTZ NOT NULL, + time_modified TIMESTAMPTZ NOT NULL, + time_deleted TIMESTAMPTZ, + + -- Baseboard information about the sled + serial_number STRING(63) NOT NULL, + part_number STRING(63) NOT NULL, + + sled_agent_ip INET NOT NULL, + + -- This tracks whether this particular sled's sled-agent has been + -- successfully started by the multirack join service: + sled_agent_started BOOL NOT NULL, + -- This nullable column should be set to the last error we've seen for this + -- particular sled's sled-agent startup process, if any: + last_start_error_seen TEXT, + + CONSTRAINT start_error_is_null_if_started CHECK ( + (NOT sled_agent_started) OR (last_start_error_seen IS NULL) + ) +); + +CREATE UNIQUE INDEX IF NOT EXISTS lookup_unadopted_sled_by_id ON omicron.public.unadopted_sled ( + id +) WHERE time_deleted IS NULL; -- Keep this at the end of file so that the database does not contain a version -- until it is fully populated. @@ -9740,7 +9804,7 @@ INSERT INTO omicron.public.db_metadata ( version, target_version ) VALUES - (TRUE, NOW(), NOW(), '309.0.0', NULL) + (TRUE, NOW(), NOW(), '310.0.0', NULL) ON CONFLICT DO NOTHING; COMMIT;