Skip to content

Commit

Permalink
fixup dbinit statement ordering for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
internet-diglett committed Nov 16, 2023
1 parent f547f8a commit 7bf9e93
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions schema/crdb/dbinit.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2824,30 +2824,6 @@ CREATE TYPE IF NOT EXISTS omicron.public.switch_link_speed AS ENUM (
ALTER TABLE omicron.public.switch_port_settings_link_config ADD COLUMN IF NOT EXISTS fec omicron.public.switch_link_fec;
ALTER TABLE omicron.public.switch_port_settings_link_config ADD COLUMN IF NOT EXISTS speed omicron.public.switch_link_speed;

/*
* Metadata for the schema itself. This version number isn't great, as there's
* nothing to ensure it gets bumped when it should be, but it's a start.
*/
CREATE TABLE IF NOT EXISTS omicron.public.db_metadata (
-- There should only be one row of this table for the whole DB.
-- It's a little goofy, but filter on "singleton = true" before querying
-- or applying updates, and you'll access the singleton row.
--
-- We also add a constraint on this table to ensure it's not possible to
-- access the version of this table with "singleton = false".
singleton BOOL NOT NULL PRIMARY KEY,
time_created TIMESTAMPTZ NOT NULL,
time_modified TIMESTAMPTZ NOT NULL,
-- Semver representation of the DB version
version STRING(64) NOT NULL,

-- (Optional) Semver representation of the DB version to which we're upgrading
target_version STRING(64),

CHECK (singleton = true)
);


CREATE SEQUENCE IF NOT EXISTS omicron.public.ipv4_nat_version START 1 INCREMENT 1;

CREATE TABLE IF NOT EXISTS omicron.public.ipv4_nat_entry (
Expand Down Expand Up @@ -2900,6 +2876,29 @@ STORING (
time_deleted
);

/*
* Metadata for the schema itself. This version number isn't great, as there's
* nothing to ensure it gets bumped when it should be, but it's a start.
*/
CREATE TABLE IF NOT EXISTS omicron.public.db_metadata (
-- There should only be one row of this table for the whole DB.
-- It's a little goofy, but filter on "singleton = true" before querying
-- or applying updates, and you'll access the singleton row.
--
-- We also add a constraint on this table to ensure it's not possible to
-- access the version of this table with "singleton = false".
singleton BOOL NOT NULL PRIMARY KEY,
time_created TIMESTAMPTZ NOT NULL,
time_modified TIMESTAMPTZ NOT NULL,
-- Semver representation of the DB version
version STRING(64) NOT NULL,

-- (Optional) Semver representation of the DB version to which we're upgrading
target_version STRING(64),

CHECK (singleton = true)
);

INSERT INTO omicron.public.db_metadata (
singleton,
time_created,
Expand Down

0 comments on commit 7bf9e93

Please sign in to comment.