From 5b7152ccabc7938f9276622b3dc05993150b1b8b Mon Sep 17 00:00:00 2001 From: David Pacheco Date: Mon, 30 Oct 2023 14:03:35 -0700 Subject: [PATCH] update database schema for the upgrade case too --- nexus/db-model/src/schema.rs | 2 +- schema/crdb/9.0.0/up01.sql | 5 +++++ schema/crdb/9.0.0/up02.sql | 2 ++ schema/crdb/9.0.0/up03.sql | 5 +++++ schema/crdb/9.0.0/up04.sql | 4 ++++ schema/crdb/9.0.0/up05.sql | 9 +++++++++ schema/crdb/9.0.0/up06.sql | 2 ++ schema/crdb/9.0.0/up07.sql | 6 ++++++ schema/crdb/9.0.0/up08.sql | 2 ++ schema/crdb/9.0.0/up09.sql | 5 +++++ schema/crdb/9.0.0/up10.sql | 2 ++ schema/crdb/9.0.0/up11.sql | 5 +++++ schema/crdb/9.0.0/up12.sql | 15 +++++++++++++++ schema/crdb/9.0.0/up13.sql | 15 +++++++++++++++ schema/crdb/9.0.0/up14.sql | 6 ++++++ schema/crdb/9.0.0/up15.sql | 11 +++++++++++ schema/crdb/dbinit.sql | 19 ++++++++++--------- 17 files changed, 105 insertions(+), 10 deletions(-) create mode 100644 schema/crdb/9.0.0/up01.sql create mode 100644 schema/crdb/9.0.0/up02.sql create mode 100644 schema/crdb/9.0.0/up03.sql create mode 100644 schema/crdb/9.0.0/up04.sql create mode 100644 schema/crdb/9.0.0/up05.sql create mode 100644 schema/crdb/9.0.0/up06.sql create mode 100644 schema/crdb/9.0.0/up07.sql create mode 100644 schema/crdb/9.0.0/up08.sql create mode 100644 schema/crdb/9.0.0/up09.sql create mode 100644 schema/crdb/9.0.0/up10.sql create mode 100644 schema/crdb/9.0.0/up11.sql create mode 100644 schema/crdb/9.0.0/up12.sql create mode 100644 schema/crdb/9.0.0/up13.sql create mode 100644 schema/crdb/9.0.0/up14.sql create mode 100644 schema/crdb/9.0.0/up15.sql diff --git a/nexus/db-model/src/schema.rs b/nexus/db-model/src/schema.rs index cefdd9f006..cff261e01a 100644 --- a/nexus/db-model/src/schema.rs +++ b/nexus/db-model/src/schema.rs @@ -1243,7 +1243,7 @@ table! { /// /// This should be updated whenever the schema is changed. For more details, /// refer to: schema/crdb/README.adoc -pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(8, 0, 0); +pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(9, 0, 0); allow_tables_to_appear_in_same_query!( system_update, diff --git a/schema/crdb/9.0.0/up01.sql b/schema/crdb/9.0.0/up01.sql new file mode 100644 index 0000000000..88439c433b --- /dev/null +++ b/schema/crdb/9.0.0/up01.sql @@ -0,0 +1,5 @@ +CREATE TABLE IF NOT EXISTS omicron.public.hw_baseboard_id ( + id UUID PRIMARY KEY, + part_number TEXT NOT NULL, + serial_number TEXT NOT NULL +); diff --git a/schema/crdb/9.0.0/up02.sql b/schema/crdb/9.0.0/up02.sql new file mode 100644 index 0000000000..d98f896fb0 --- /dev/null +++ b/schema/crdb/9.0.0/up02.sql @@ -0,0 +1,2 @@ +CREATE UNIQUE INDEX IF NOT EXISTS lookup_baseboard_id_by_props + ON omicron.public.hw_baseboard_id (part_number, serial_number); diff --git a/schema/crdb/9.0.0/up03.sql b/schema/crdb/9.0.0/up03.sql new file mode 100644 index 0000000000..3bd036be7e --- /dev/null +++ b/schema/crdb/9.0.0/up03.sql @@ -0,0 +1,5 @@ +CREATE TYPE IF NOT EXISTS omicron.public.hw_power_state AS ENUM ( + 'A0', + 'A1', + 'A2' +); diff --git a/schema/crdb/9.0.0/up04.sql b/schema/crdb/9.0.0/up04.sql new file mode 100644 index 0000000000..1590ec4e88 --- /dev/null +++ b/schema/crdb/9.0.0/up04.sql @@ -0,0 +1,4 @@ +CREATE TYPE IF NOT EXISTS omicron.public.hw_rot_slot AS ENUM ( + 'A', + 'B' +); diff --git a/schema/crdb/9.0.0/up05.sql b/schema/crdb/9.0.0/up05.sql new file mode 100644 index 0000000000..1042282fb0 --- /dev/null +++ b/schema/crdb/9.0.0/up05.sql @@ -0,0 +1,9 @@ +CREATE TABLE IF NOT EXISTS omicron.public.sw_caboose ( + id UUID PRIMARY KEY, + board TEXT NOT NULL, + git_commit TEXT NOT NULL, + name TEXT NOT NULL, + -- The MGS response that provides this field indicates that it can be NULL. + -- But that's only to support old software that we no longer support. + version TEXT NOT NULL +); diff --git a/schema/crdb/9.0.0/up06.sql b/schema/crdb/9.0.0/up06.sql new file mode 100644 index 0000000000..aa614fa2fb --- /dev/null +++ b/schema/crdb/9.0.0/up06.sql @@ -0,0 +1,2 @@ +CREATE UNIQUE INDEX IF NOT EXISTS caboose_properties + on omicron.public.sw_caboose (board, git_commit, name, version); diff --git a/schema/crdb/9.0.0/up07.sql b/schema/crdb/9.0.0/up07.sql new file mode 100644 index 0000000000..945f5a44c8 --- /dev/null +++ b/schema/crdb/9.0.0/up07.sql @@ -0,0 +1,6 @@ +CREATE TABLE IF NOT EXISTS inv_collection ( + id UUID PRIMARY KEY, + time_started TIMESTAMPTZ NOT NULL, + time_done TIMESTAMPTZ NOT NULL, + collector TEXT NOT NULL +); diff --git a/schema/crdb/9.0.0/up08.sql b/schema/crdb/9.0.0/up08.sql new file mode 100644 index 0000000000..1abeb9203f --- /dev/null +++ b/schema/crdb/9.0.0/up08.sql @@ -0,0 +1,2 @@ +CREATE INDEX IF NOT EXISTS inv_collection_by_time_started + ON omicron.public.inv_collection (time_started); diff --git a/schema/crdb/9.0.0/up09.sql b/schema/crdb/9.0.0/up09.sql new file mode 100644 index 0000000000..770c771775 --- /dev/null +++ b/schema/crdb/9.0.0/up09.sql @@ -0,0 +1,5 @@ +CREATE TABLE IF NOT EXISTS omicron.public.inv_collection_error ( + inv_collection_id UUID NOT NULL, + idx INT4 NOT NULL, + message TEXT +); diff --git a/schema/crdb/9.0.0/up10.sql b/schema/crdb/9.0.0/up10.sql new file mode 100644 index 0000000000..57665ee468 --- /dev/null +++ b/schema/crdb/9.0.0/up10.sql @@ -0,0 +1,2 @@ +CREATE INDEX IF NOT EXISTS errors_by_collection + ON omicron.public.inv_collection_error (inv_collection_id, idx); diff --git a/schema/crdb/9.0.0/up11.sql b/schema/crdb/9.0.0/up11.sql new file mode 100644 index 0000000000..40da69af5b --- /dev/null +++ b/schema/crdb/9.0.0/up11.sql @@ -0,0 +1,5 @@ +CREATE TYPE IF NOT EXISTS omicron.public.sp_type AS ENUM ( + 'sled', + 'switch', + 'power' +); diff --git a/schema/crdb/9.0.0/up12.sql b/schema/crdb/9.0.0/up12.sql new file mode 100644 index 0000000000..9089ac93ba --- /dev/null +++ b/schema/crdb/9.0.0/up12.sql @@ -0,0 +1,15 @@ +CREATE TABLE IF NOT EXISTS omicron.public.inv_service_processor ( + inv_collection_id UUID NOT NULL, + hw_baseboard_id UUID NOT NULL, + time_collected TIMESTAMPTZ NOT NULL, + source TEXT NOT NULL, + + sp_type omicron.public.sp_type NOT NULL, + sp_slot INT4 NOT NULL, + + baseboard_revision INT8 NOT NULL, + hubris_archive_id TEXT NOT NULL, + power_state omicron.public.hw_power_state NOT NULL, + + PRIMARY KEY (inv_collection_id, hw_baseboard_id) +); diff --git a/schema/crdb/9.0.0/up13.sql b/schema/crdb/9.0.0/up13.sql new file mode 100644 index 0000000000..241c5d9e80 --- /dev/null +++ b/schema/crdb/9.0.0/up13.sql @@ -0,0 +1,15 @@ +CREATE TABLE IF NOT EXISTS omicron.public.inv_root_of_trust ( + inv_collection_id UUID NOT NULL, + hw_baseboard_id UUID NOT NULL, + time_collected TIMESTAMPTZ NOT NULL, + source TEXT NOT NULL, + + slot_active omicron.public.hw_rot_slot NOT NULL, + slot_boot_pref_transient omicron.public.hw_rot_slot, + slot_boot_pref_persistent omicron.public.hw_rot_slot NOT NULL, + slot_boot_pref_persistent_pending omicron.public.hw_rot_slot, + slot_a_sha3_256 TEXT, + slot_b_sha3_256 TEXT, + + PRIMARY KEY (inv_collection_id, hw_baseboard_id) +); diff --git a/schema/crdb/9.0.0/up14.sql b/schema/crdb/9.0.0/up14.sql new file mode 100644 index 0000000000..6725d35acf --- /dev/null +++ b/schema/crdb/9.0.0/up14.sql @@ -0,0 +1,6 @@ +CREATE TYPE IF NOT EXISTS omicron.public.caboose_which AS ENUM ( + 'sp_slot_0', + 'sp_slot_1', + 'rot_slot_A', + 'rot_slot_B' +); diff --git a/schema/crdb/9.0.0/up15.sql b/schema/crdb/9.0.0/up15.sql new file mode 100644 index 0000000000..48a68d167a --- /dev/null +++ b/schema/crdb/9.0.0/up15.sql @@ -0,0 +1,11 @@ +CREATE TABLE IF NOT EXISTS omicron.public.inv_caboose ( + inv_collection_id UUID NOT NULL, + hw_baseboard_id UUID NOT NULL, + time_collected TIMESTAMPTZ NOT NULL, + source TEXT NOT NULL, + + which omicron.public.caboose_which NOT NULL, + sw_caboose_id UUID NOT NULL, + + PRIMARY KEY (inv_collection_id, hw_baseboard_id, which) +); diff --git a/schema/crdb/dbinit.sql b/schema/crdb/dbinit.sql index 307a2888b7..64da76adbb 100644 --- a/schema/crdb/dbinit.sql +++ b/schema/crdb/dbinit.sql @@ -2514,14 +2514,6 @@ CREATE TABLE IF NOT EXISTS omicron.public.bootstore_keys ( generation INT8 NOT NULL ); -/* - * The `sled_instance` view's definition needs to be modified in a separate - * transaction from the transaction that created it. - */ - -COMMIT; -BEGIN; - /* * Hardware/software inventory * @@ -2736,6 +2728,15 @@ CREATE TABLE IF NOT EXISTS omicron.public.inv_caboose ( PRIMARY KEY (inv_collection_id, hw_baseboard_id, which) ); +/*******************************************************************/ + +/* + * The `sled_instance` view's definition needs to be modified in a separate + * transaction from the transaction that created it. + */ + +COMMIT; +BEGIN; /*******************************************************************/ @@ -2837,7 +2838,7 @@ INSERT INTO omicron.public.db_metadata ( version, target_version ) VALUES - ( TRUE, NOW(), NOW(), '8.0.0', NULL) + ( TRUE, NOW(), NOW(), '9.0.0', NULL) ON CONFLICT DO NOTHING; COMMIT;