From afd2dad5f2532e9826a0fabd26c542ccce5930f5 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Mon, 20 May 2024 16:21:37 -0700 Subject: [PATCH] schema changes --- nexus/db-model/src/schema_versions.rs | 3 ++- schema/crdb/add-instance-updater-lock/up.sql | 5 +++++ schema/crdb/dbinit.sql | 10 +++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 schema/crdb/add-instance-updater-lock/up.sql diff --git a/nexus/db-model/src/schema_versions.rs b/nexus/db-model/src/schema_versions.rs index a86d030e483..6b7616b7335 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(60, 0, 0); +pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(61, 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(61, "add-instance-updater-lock"), KnownVersion::new(60, "add-lookup-vmm-by-sled-id-index"), KnownVersion::new(59, "enforce-first-as-default"), KnownVersion::new(58, "insert-default-allowlist"), diff --git a/schema/crdb/add-instance-updater-lock/up.sql b/schema/crdb/add-instance-updater-lock/up.sql new file mode 100644 index 00000000000..76eae1f7231 --- /dev/null +++ b/schema/crdb/add-instance-updater-lock/up.sql @@ -0,0 +1,5 @@ +ALTER TABLE omicron.public.instance + ADD COLUMN IF NOT EXISTS updater_id UUID + DEFAULT null, + ADD COLUMN IF NOT EXISTS updater_gen INT + NOT NULL DEFAULT 0; diff --git a/schema/crdb/dbinit.sql b/schema/crdb/dbinit.sql index e7025f24993..2badb0bb676 100644 --- a/schema/crdb/dbinit.sql +++ b/schema/crdb/dbinit.sql @@ -1002,7 +1002,15 @@ CREATE TABLE IF NOT EXISTS omicron.public.instance ( ncpus INT NOT NULL, memory INT NOT NULL, hostname STRING(63) NOT NULL, - boot_on_fault BOOL NOT NULL DEFAULT false + boot_on_fault BOOL NOT NULL DEFAULT false, + + /* ID of the instance update saga that has locked this instance for + * updating, if one exists. */ + updater_id UUID, + + /* Generation of the instance updater lock */ + updater_gen INT NOT NULL + ); -- Names for instances within a project should be unique