-
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.
clarify and clean up migrations, remove a couple of TODOs
- Loading branch information
1 parent
dc9de62
commit ee0f363
Showing
5 changed files
with
30 additions
and
24 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 |
---|---|---|
@@ -1,22 +1,26 @@ | ||
-- copy existing fleet associations into association table. treat all existing | ||
-- pools as fleet-associated because that is the current behavior | ||
-- Fleet-scoped pools are going away, but we recreate the equivalent of a fleet | ||
-- link for existing fleet-scoped pools by associating them with every existing | ||
-- silo, i.e., inserting a row into the association table for each (pool, silo) | ||
-- pair. | ||
-- | ||
-- Note special handling is required for conflicts between a fleet default and | ||
-- a silo default. If pool P1 is a fleet default and pool P2 is a silo default | ||
-- on silo S1, we cannot link both to S1 with is_default = true. What we really | ||
-- want in that case is link it to S1 with is_default = false. So first, here we | ||
-- copy the "original" value of is_default to the link between P1 and S1. Then, | ||
-- in up5, we flip is_default to false on P1 when we see that P2 wants to be the | ||
-- default for S1. | ||
INSERT INTO omicron.public.ip_pool_resource (ip_pool_id, resource_type, resource_id, is_default) | ||
SELECT | ||
p.id AS ip_pool_id, | ||
'silo' AS resource_type, | ||
s.id AS resource_id, | ||
-- note problem solved by up5.sql after this regarding is_default: if pool P1 | ||
-- is a fleet default and pool P2 is a silo default on silo S1, we cannot link | ||
-- both to S1 with is_default = true. what we really want in that case is link | ||
-- it to S1 with is_default = false. So first, here we copy the "original" | ||
-- value of is_default, and then in up5 we flip is_default to false if there | ||
-- is a conflicting default silo-linked pool | ||
p.is_default | ||
FROM ip_pool AS p | ||
CROSS JOIN silo AS s | ||
FROM omicron.public.ip_pool AS p | ||
CROSS JOIN omicron.public.silo AS s | ||
WHERE p.time_deleted IS null | ||
AND p.silo_id IS null -- means it's a fleet pool | ||
AND s.time_deleted IS null | ||
-- make this idempotent | ||
-- this makes it idempotent | ||
ON CONFLICT (ip_pool_id, resource_type, resource_id) | ||
DO NOTHING; |
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 |
---|---|---|
@@ -1,10 +1,12 @@ | ||
-- turn any former fleet defaults into non-defaults if there's going to be a | ||
-- silo conflicting with it | ||
-- Preemptively turn any former fleet defaults into non-defaults if there's | ||
-- going to be a silo conflicting with it after up6 | ||
UPDATE omicron.public.ip_pool_resource AS ipr | ||
SET is_default = false | ||
FROM omicron.public.ip_pool as ip | ||
WHERE ipr.is_default = true | ||
WHERE ipr.resource_type = 'silo' -- technically unnecessary because there is only silo | ||
AND ipr.is_default = true | ||
AND ip.is_default = true -- both being default is the conflict being resolved | ||
AND ip.silo_id IS NOT NULL | ||
AND ip.silo_id = ipr.resource_id | ||
AND ip.id = ipr.ip_pool_id; | ||
|
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 |
---|---|---|
@@ -1,9 +1,13 @@ | ||
-- copy existing ip_pool-to-silo associations into association table | ||
INSERT INTO omicron.public.ip_pool_resource (ip_pool_id, resource_type, resource_id, is_default) | ||
SELECT id, 'silo', silo_id, is_default | ||
FROM ip_pool | ||
SELECT | ||
id as ip_pool_id, | ||
'silo' as resource_type, | ||
silo_id as resource_id, | ||
is_default | ||
FROM omicron.public.ip_pool AS ip | ||
WHERE silo_id IS NOT null | ||
AND time_deleted IS null | ||
-- make this idempotent | ||
-- this makes it idempotent | ||
ON CONFLICT (ip_pool_id, resource_type, resource_id) | ||
DO NOTHING; |