Skip to content

Commit

Permalink
sketch db migration
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkw committed Sep 1, 2024
1 parent 1b3fcad commit 1f2c04b
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 3 deletions.
3 changes: 2 additions & 1 deletion nexus/db-model/src/schema_versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(94, 0, 0);
pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(95, 0, 0);

/// List of all past database schema versions, in *reverse* order
///
Expand All @@ -29,6 +29,7 @@ static KNOWN_VERSIONS: Lazy<Vec<KnownVersion>> = 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(95, "turn-boot-on-fault-into-auto-restart"),
KnownVersion::new(94, "put-back-creating-vmm-state"),
KnownVersion::new(93, "dataset-kinds-zone-and-debug"),
KnownVersion::new(92, "lldp-link-config-nullable"),
Expand Down
23 changes: 21 additions & 2 deletions schema/crdb/dbinit.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,20 @@ CREATE TYPE IF NOT EXISTS omicron.public.vmm_state AS ENUM (
'saga_unwound'
);

CREATE TYPE IF NOT EXISTS omicron.public.instance_auto_restart AS ENUM (
/*
* The instance should not, under any circumstances, be automatically
* rebooted by the control plane.
*/
'never',
/*
* The instance should be automatically restarted any time a fault is
* detected
*/
'all_failures',
);


/*
* TODO consider how we want to manage multiple sagas operating on the same
* Instance -- e.g., reboot concurrent with destroy or concurrent reboots or the
Expand Down Expand Up @@ -1059,7 +1073,6 @@ 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,

/* ID of the instance update saga that has locked this instance for
* updating, if one exists. */
Expand All @@ -1077,6 +1090,12 @@ CREATE TABLE IF NOT EXISTS omicron.public.instance (
*/
state omicron.public.instance_state_v2 NOT NULL,

/*
* What failures should result in an instance being automatically restarted
* by the control plane.
*/
auto_restart_policy omicron.public.instance_auto_restart NOT NULL,

CONSTRAINT vmm_iff_active_propolis CHECK (
((state = 'vmm') AND (active_propolis_id IS NOT NULL)) OR
((state != 'vmm') AND (active_propolis_id IS NULL))
Expand Down Expand Up @@ -4233,7 +4252,7 @@ INSERT INTO omicron.public.db_metadata (
version,
target_version
) VALUES
(TRUE, NOW(), NOW(), '94.0.0', NULL)
(TRUE, NOW(), NOW(), '95.0.0', NULL)
ON CONFLICT DO NOTHING;

COMMIT;
12 changes: 12 additions & 0 deletions schema/crdb/turn-boot-on-fault-into-auto-restart/up01.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CREATE TYPE IF NOT EXISTS omicron.public.instance_auto_restart AS ENUM (
/*
* The instance should not, under any circumstances, be automatically
* rebooted by the control plane.
*/
'never',
/*
* The instance should be automatically restarted any time a fault is
* detected
*/
'all_failures',
);
2 changes: 2 additions & 0 deletions schema/crdb/turn-boot-on-fault-into-auto-restart/up02.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE omicron.public.instance
ADD COLUMN IF NOT EXISTS auto_restart_policy omicron.public.auto_restart_policy;
5 changes: 5 additions & 0 deletions schema/crdb/turn-boot-on-fault-into-auto-restart/up03.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SET LOCAL disallow_full_table_scans = off;
UPDATE omicron.public.instance SET auto_restart_policy = CASE
WHEN boot_on_fault = true THEN 'all_failures'
ELSE 'never'
END;
1 change: 1 addition & 0 deletions schema/crdb/turn-boot-on-fault-into-auto-restart/up04.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE omicron.public.instance ALTER COLUMN auto_restart_policy SET NOT NULL;
1 change: 1 addition & 0 deletions schema/crdb/turn-boot-on-fault-into-auto-restart/up05.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE omicron.public.instance DROP COLUMN IF EXISTS boot_on_fault;

0 comments on commit 1f2c04b

Please sign in to comment.