Skip to content

Commit

Permalink
update database schema for the upgrade case too
Browse files Browse the repository at this point in the history
  • Loading branch information
davepacheco committed Oct 30, 2023
1 parent 376a37b commit 5b7152c
Show file tree
Hide file tree
Showing 17 changed files with 105 additions and 10 deletions.
2 changes: 1 addition & 1 deletion nexus/db-model/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions schema/crdb/9.0.0/up01.sql
Original file line number Diff line number Diff line change
@@ -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
);
2 changes: 2 additions & 0 deletions schema/crdb/9.0.0/up02.sql
Original file line number Diff line number Diff line change
@@ -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);
5 changes: 5 additions & 0 deletions schema/crdb/9.0.0/up03.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE TYPE IF NOT EXISTS omicron.public.hw_power_state AS ENUM (
'A0',
'A1',
'A2'
);
4 changes: 4 additions & 0 deletions schema/crdb/9.0.0/up04.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CREATE TYPE IF NOT EXISTS omicron.public.hw_rot_slot AS ENUM (
'A',
'B'
);
9 changes: 9 additions & 0 deletions schema/crdb/9.0.0/up05.sql
Original file line number Diff line number Diff line change
@@ -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
);
2 changes: 2 additions & 0 deletions schema/crdb/9.0.0/up06.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE UNIQUE INDEX IF NOT EXISTS caboose_properties
on omicron.public.sw_caboose (board, git_commit, name, version);
6 changes: 6 additions & 0 deletions schema/crdb/9.0.0/up07.sql
Original file line number Diff line number Diff line change
@@ -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
);
2 changes: 2 additions & 0 deletions schema/crdb/9.0.0/up08.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE INDEX IF NOT EXISTS inv_collection_by_time_started
ON omicron.public.inv_collection (time_started);
5 changes: 5 additions & 0 deletions schema/crdb/9.0.0/up09.sql
Original file line number Diff line number Diff line change
@@ -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
);
2 changes: 2 additions & 0 deletions schema/crdb/9.0.0/up10.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE INDEX IF NOT EXISTS errors_by_collection
ON omicron.public.inv_collection_error (inv_collection_id, idx);
5 changes: 5 additions & 0 deletions schema/crdb/9.0.0/up11.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE TYPE IF NOT EXISTS omicron.public.sp_type AS ENUM (
'sled',
'switch',
'power'
);
15 changes: 15 additions & 0 deletions schema/crdb/9.0.0/up12.sql
Original file line number Diff line number Diff line change
@@ -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)
);
15 changes: 15 additions & 0 deletions schema/crdb/9.0.0/up13.sql
Original file line number Diff line number Diff line change
@@ -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)
);
6 changes: 6 additions & 0 deletions schema/crdb/9.0.0/up14.sql
Original file line number Diff line number Diff line change
@@ -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'
);
11 changes: 11 additions & 0 deletions schema/crdb/9.0.0/up15.sql
Original file line number Diff line number Diff line change
@@ -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)
);
19 changes: 10 additions & 9 deletions schema/crdb/dbinit.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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;

/*******************************************************************/

Expand Down Expand Up @@ -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;

0 comments on commit 5b7152c

Please sign in to comment.