-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(server): add composite primary key for single row resources (#3155)
- Loading branch information
Showing
8 changed files
with
155 additions
and
22 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
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,67 @@ | ||
BEGIN; | ||
|
||
ALTER TABLE data_stores | ||
DROP CONSTRAINT data_stores_pkey, | ||
ADD PRIMARY KEY (id), | ||
ALTER COLUMN tenant_id DROP DEFAULT, | ||
ALTER COLUMN tenant_id DROP NOT NULL; | ||
|
||
UPDATE data_stores | ||
SET tenant_id = null | ||
WHERE tenant_id = ''; | ||
|
||
ALTER TABLE data_stores ALTER COLUMN tenant_id TYPE uuid using tenant_id::uuid; | ||
|
||
|
||
ALTER TABLE demos | ||
DROP CONSTRAINT demos_pkey, | ||
ADD PRIMARY KEY (id), | ||
ALTER COLUMN tenant_id DROP DEFAULT, | ||
ALTER COLUMN tenant_id DROP NOT NULL; | ||
|
||
UPDATE demos | ||
SET tenant_id = null | ||
WHERE tenant_id = ''; | ||
|
||
ALTER TABLE demos ALTER COLUMN tenant_id TYPE uuid using tenant_id::uuid; | ||
|
||
|
||
ALTER TABLE polling_profiles | ||
DROP CONSTRAINT polling_profiles_pkey, | ||
ADD PRIMARY KEY (id), | ||
ALTER COLUMN tenant_id DROP DEFAULT, | ||
ALTER COLUMN tenant_id DROP NOT NULL; | ||
|
||
UPDATE polling_profiles | ||
SET tenant_id = null | ||
WHERE tenant_id = ''; | ||
|
||
ALTER TABLE polling_profiles ALTER COLUMN tenant_id TYPE uuid using tenant_id::uuid; | ||
|
||
|
||
ALTER TABLE linters | ||
DROP CONSTRAINT linters_pkey, | ||
ADD PRIMARY KEY (id), | ||
ALTER COLUMN tenant_id DROP DEFAULT, | ||
ALTER COLUMN tenant_id DROP NOT NULL; | ||
|
||
UPDATE linters | ||
SET tenant_id = null | ||
WHERE tenant_id = ''; | ||
|
||
ALTER TABLE linters ALTER COLUMN tenant_id TYPE uuid using tenant_id::uuid; | ||
|
||
|
||
ALTER TABLE test_runners | ||
DROP CONSTRAINT test_runners_pkey, | ||
ADD PRIMARY KEY (id), | ||
ALTER COLUMN tenant_id DROP DEFAULT, | ||
ALTER COLUMN tenant_id DROP NOT NULL; | ||
|
||
UPDATE test_runners | ||
SET tenant_id = null | ||
WHERE tenant_id = ''; | ||
|
||
ALTER TABLE test_runners ALTER COLUMN tenant_id TYPE uuid using tenant_id::uuid; | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
BEGIN; | ||
|
||
ALTER TABLE data_stores ALTER COLUMN tenant_id TYPE varchar; | ||
|
||
UPDATE data_stores | ||
SET tenant_id = '' | ||
WHERE tenant_id is null; | ||
|
||
ALTER TABLE data_stores | ||
DROP CONSTRAINT data_stores_pkey, | ||
ADD PRIMARY KEY (id, tenant_id), | ||
ALTER COLUMN tenant_id SET DEFAULT ''; | ||
|
||
|
||
ALTER TABLE demos ALTER COLUMN tenant_id TYPE varchar; | ||
|
||
UPDATE demos | ||
SET tenant_id = '' | ||
WHERE tenant_id is null; | ||
|
||
ALTER TABLE demos | ||
DROP CONSTRAINT demos_pkey, | ||
ADD PRIMARY KEY (id, tenant_id), | ||
ALTER COLUMN tenant_id SET DEFAULT ''; | ||
|
||
|
||
ALTER TABLE polling_profiles ALTER COLUMN tenant_id TYPE varchar; | ||
|
||
UPDATE polling_profiles | ||
SET tenant_id = '' | ||
WHERE tenant_id is null; | ||
|
||
ALTER TABLE polling_profiles | ||
DROP CONSTRAINT polling_profiles_pkey, | ||
ADD PRIMARY KEY (id, tenant_id), | ||
ALTER COLUMN tenant_id SET DEFAULT ''; | ||
|
||
|
||
ALTER TABLE linters ALTER COLUMN tenant_id TYPE varchar; | ||
|
||
UPDATE linters | ||
SET tenant_id = '' | ||
WHERE tenant_id is null; | ||
|
||
ALTER TABLE linters | ||
DROP CONSTRAINT linters_pkey, | ||
ADD PRIMARY KEY (id, tenant_id), | ||
ALTER COLUMN tenant_id SET DEFAULT ''; | ||
|
||
|
||
ALTER TABLE test_runners ALTER COLUMN tenant_id TYPE varchar; | ||
|
||
UPDATE test_runners | ||
SET tenant_id = '' | ||
WHERE tenant_id is null; | ||
|
||
ALTER TABLE test_runners | ||
DROP CONSTRAINT test_runners_pkey, | ||
ADD PRIMARY KEY (id, tenant_id), | ||
ALTER COLUMN tenant_id SET DEFAULT ''; | ||
|
||
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