Skip to content

Commit

Permalink
fix clickhouse_keeper order. mgd not necessary because it's at the end
Browse files Browse the repository at this point in the history
  • Loading branch information
david-crespo committed Nov 10, 2023
1 parent 5acc7fc commit e5f8e46
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 5 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(9, 0, 0);
pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(10, 0, 0);

allow_tables_to_appear_in_same_query!(
system_update,
Expand Down
12 changes: 12 additions & 0 deletions schema/crdb/10.0.0/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Why?

This migration is part of a PR that adds a check to the schema tests ensuring that the order of enum members is the same when starting from scratch with `dbinit.sql` as it is when building up from existing deployments by running the migrations. The problem: there were already two enums, `dataset_kind` and `service_kind` where the order did not match, so we have to fix that by putting the enums in the "right" order even on an existing deployment where the order is wrong. To do that, for each of those enums, we:

1. add `clickhouse_keeper2` member
1. change existing uses of `clickhouse_keeper` to `clickhouse_keeper2`
1. drop `clickhouse_keeper` member
1. add `clickhouse_keeper` back in the right order using `AFTER 'clickhouse'`
1. change uses of `clickhouse_keeper2` back to `clickhouse_keeper`
1. drop `clickhouse_keeper2`

As there are 6 steps here and two different enums to do them for, there are 12 `up*.sql` files.
1 change: 1 addition & 0 deletions schema/crdb/10.0.0/up01.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TYPE omicron.public.dataset_kind ADD VALUE IF NOT EXISTS 'clickhouse_keeper2' AFTER 'clickhouse';
1 change: 1 addition & 0 deletions schema/crdb/10.0.0/up02.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TYPE omicron.public.service_kind ADD VALUE IF NOT EXISTS 'clickhouse_keeper2' AFTER 'clickhouse';
3 changes: 3 additions & 0 deletions schema/crdb/10.0.0/up03.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
UPDATE omicron.public.dataset
SET kind = 'clickhouse_keeper2'
WHERE kind = 'clickhouse_keeper';
3 changes: 3 additions & 0 deletions schema/crdb/10.0.0/up04.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
UPDATE omicron.public.service
SET kind = 'clickhouse_keeper2'
WHERE kind = 'clickhouse_keeper';
1 change: 1 addition & 0 deletions schema/crdb/10.0.0/up05.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TYPE omicron.public.dataset_kind DROP VALUE 'clickhouse_keeper';
1 change: 1 addition & 0 deletions schema/crdb/10.0.0/up06.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TYPE omicron.public.service_kind DROP VALUE 'clickhouse_keeper';
1 change: 1 addition & 0 deletions schema/crdb/10.0.0/up07.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TYPE omicron.public.dataset_kind ADD VALUE 'clickhouse_keeper' AFTER 'clickhouse';
1 change: 1 addition & 0 deletions schema/crdb/10.0.0/up08.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TYPE omicron.public.service_kind ADD VALUE 'clickhouse_keeper' AFTER 'clickhouse';
3 changes: 3 additions & 0 deletions schema/crdb/10.0.0/up09.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
UPDATE omicron.public.dataset
SET kind = 'clickhouse_keeper'
WHERE kind = 'clickhouse_keeper2';
3 changes: 3 additions & 0 deletions schema/crdb/10.0.0/up10.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
UPDATE omicron.public.service
SET kind = 'clickhouse_keeper'
WHERE kind = 'clickhouse_keeper2';
1 change: 1 addition & 0 deletions schema/crdb/10.0.0/up11.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TYPE omicron.public.dataset_kind DROP VALUE 'clickhouse_keeper2';
1 change: 1 addition & 0 deletions schema/crdb/10.0.0/up12.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TYPE omicron.public.service_kind DROP VALUE 'clickhouse_keeper2';
8 changes: 4 additions & 4 deletions schema/crdb/dbinit.sql
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS lookup_switch_by_rack ON omicron.public.switch

CREATE TYPE IF NOT EXISTS omicron.public.service_kind AS ENUM (
'clickhouse',
'clickhouse_keeper',
'cockroach',
'crucible',
'crucible_pantry',
Expand All @@ -201,7 +202,6 @@ CREATE TYPE IF NOT EXISTS omicron.public.service_kind AS ENUM (
'ntp',
'oximeter',
'tfport',
'clickhouse_keeper',
'mgd'
);

Expand Down Expand Up @@ -402,9 +402,9 @@ CREATE TYPE IF NOT EXISTS omicron.public.dataset_kind AS ENUM (
'crucible',
'cockroach',
'clickhouse',
'clickhouse_keeper',
'external_dns',
'internal_dns',
'clickhouse_keeper'
'internal_dns'
);

/*
Expand Down Expand Up @@ -2838,7 +2838,7 @@ INSERT INTO omicron.public.db_metadata (
version,
target_version
) VALUES
( TRUE, NOW(), NOW(), '9.0.0', NULL)
( TRUE, NOW(), NOW(), '10.0.0', NULL)
ON CONFLICT DO NOTHING;

COMMIT;

0 comments on commit e5f8e46

Please sign in to comment.