Skip to content

Commit c158789

Browse files
committed
migrations
1 parent 753630b commit c158789

File tree

5 files changed

+60
-2
lines changed

5 files changed

+60
-2
lines changed

nexus/db-model/src/schema_versions.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::{collections::BTreeMap, sync::LazyLock};
1616
///
1717
/// This must be updated when you change the database schema. Refer to
1818
/// schema/crdb/README.adoc in the root of this repository for details.
19-
pub const SCHEMA_VERSION: Version = Version::new(201, 0, 0);
19+
pub const SCHEMA_VERSION: Version = Version::new(202, 0, 0);
2020

2121
/// List of all past database schema versions, in *reverse* order
2222
///
@@ -28,6 +28,7 @@ static KNOWN_VERSIONS: LazyLock<Vec<KnownVersion>> = LazyLock::new(|| {
2828
// | leaving the first copy as an example for the next person.
2929
// v
3030
// KnownVersion::new(next_int, "unique-dirname-with-the-sql-files"),
31+
KnownVersion::new(202, "fm-sitrep"),
3132
KnownVersion::new(201, "scim-client-bearer-token"),
3233
KnownVersion::new(200, "dual-stack-network-interfaces"),
3334
KnownVersion::new(199, "multicast-pool-support"),

schema/crdb/dbinit.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6921,7 +6921,7 @@ INSERT INTO omicron.public.db_metadata (
69216921
version,
69226922
target_version
69236923
) VALUES
6924-
(TRUE, NOW(), NOW(), '201.0.0', NULL)
6924+
(TRUE, NOW(), NOW(), '202.0.0', NULL)
69256925
ON CONFLICT DO NOTHING;
69266926

69276927
COMMIT;

schema/crdb/fm-sitrep/up01.sql

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
CREATE TABLE IF NOT EXISTS omicron.public.fm_sitrep (
2+
-- The ID of this sitrep.
3+
id UUID PRIMARY KEY,
4+
-- The ID of the parent sitrep.
5+
--
6+
-- A sitrep's _parent_ is the sitrep that was current when the planning
7+
-- phase that produced that sitrep ran. The parent sitrep is a planning
8+
-- input that produced this sitrep.
9+
--
10+
-- This is effectively a foreign key back to this table; however, it is
11+
-- allowed to be NULL: the initial sitrep has no parent. Additionally,
12+
-- it may be non-NULL but no longer reference a row in this table: once a
13+
-- child sitrep has been created from a parent, it's possible for the
14+
-- parent to be deleted. We do not NULL out this field on such a deletion,
15+
-- so we can always see that there had been a particular parent even if
16+
-- it's now gone.
17+
parent_sitrep_id UUID,
18+
-- The ID of the inventory collection that was used as input to this
19+
-- sitrep.
20+
--
21+
-- This is a foreign key that references a row in the `inv_collection`
22+
-- table (and other inventory records associated with that collection).
23+
--
24+
-- Note that inventory collections are pruned on a separate schedule
25+
-- from sitreps, so the inventory collection records may not exist.
26+
inv_collection_id UUID NOT NULL,
27+
28+
-- These fields are not semantically meaningful and are intended
29+
-- debugging purposes.
30+
31+
-- The time at which this sitrep was created.
32+
time_created TIMESTAMPTZ NOT NULL,
33+
-- The Omicron zone UUID of the Nexus instance that created this
34+
-- sitrep.
35+
creator_id UUID NOT NULL,
36+
-- A human-readable description of the changes represented by this
37+
-- sitrep.
38+
comment TEXT NOT NULL
39+
);

schema/crdb/fm-sitrep/up02.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- The history of current sitreps.
2+
--
3+
-- The sitrep with the highest `version` in this table is the current sitrep.
4+
CREATE TABLE IF NOT EXISTS omicron.public.fm_sitrep_history (
5+
-- Monotonically increasing version for all FM sitreps.
6+
version INT8 PRIMARY KEY,
7+
8+
-- Effectively a foreign key into the `fm_sitrep` table, but may
9+
-- reference a fm_sitrep that has been deleted (if this sitrep is
10+
-- no longer current; the current sitrep must not be deleted).
11+
sitrep_id UUID NOT NULL,
12+
13+
-- Timestamp for when this sitrep was made current.
14+
time_made_current TIMESTAMPTZ NOT NULL
15+
);

schema/crdb/fm-sitrep/up03.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CREATE UNIQUE INDEX IF NOT EXISTS
2+
lookup_sitrep_version_by_id
3+
ON omicron.public.fm_sitrep_history (sitrep_id);

0 commit comments

Comments
 (0)