-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[nexus] Silo IP pools schema change (#3981)
This is quite small, but I'm pretty confident it's a sufficient basis for the rest of the work in #3926, so we might as well review and merge already. A couple of minor pain points I ran into while doing this: * Needed guidance on version number (3.0.0 it is) — it will be more obvious when there are more, but I added a line to the readme anyway * Diff output for [`dbinit_equals_sum_of_all_up`](https://github.com/oxidecomputer/omicron/blob/fb16870de8c0dba92d0868a984dd715749141b73/nexus/tests/integration_tests/schema.rs#L601) is terrible — thousands of lines with only a few relevant ones. It turns out the column order matters, so if you add columns to a table in a migration, you have to add them to the _end_ of the `create table` in `dbinit.sql`.
- Loading branch information
1 parent
fb16870
commit f5d8e09
Showing
5 changed files
with
77 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
-- CRDB documentation recommends the following: | ||
-- "Execute schema changes either as single statements (as an implicit transaction), | ||
-- or in an explicit transaction consisting of the single schema change statement." | ||
-- | ||
-- For each schema change, we transactionally: | ||
-- 1. Check the current version | ||
-- 2. Apply the idempotent update | ||
|
||
BEGIN; | ||
|
||
SELECT CAST( | ||
IF( | ||
( | ||
SELECT version = '2.0.0' and target_version = '3.0.0' | ||
FROM omicron.public.db_metadata WHERE singleton = true | ||
), | ||
'true', | ||
'Invalid starting version for schema change' | ||
) AS BOOL | ||
); | ||
|
||
ALTER TABLE omicron.public.ip_pool | ||
ADD COLUMN IF NOT EXISTS silo_ID UUID, | ||
ADD COLUMN IF NOT EXISTS project_id UUID, | ||
|
||
-- if silo_id is null, then project_id must be null | ||
ADD CONSTRAINT IF NOT EXISTS project_implies_silo CHECK ( | ||
NOT ((silo_id IS NULL) AND (project_id IS NOT NULL)) | ||
), | ||
|
||
-- if internal = true, non-null silo_id and project_id are not allowed | ||
ADD CONSTRAINT IF NOT EXISTS internal_pools_have_null_silo_and_project CHECK ( | ||
NOT (INTERNAL AND ((silo_id IS NOT NULL) OR (project_id IS NOT NULL))) | ||
); | ||
|
||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters