-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor(tenants): apikey store to use varchar array (#114)
* refactor apikey store to use varchar array * Drop default permissons after migration
- Loading branch information
Showing
6 changed files
with
128 additions
and
135 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
3 changes: 3 additions & 0 deletions
3
services/tenants/migrations/20240625081827_api_key_perms_as_array.down.sql
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,3 @@ | ||
INSERT INTO api_key_permissions (api_key_id, permission) | ||
SELECT ak.id, UNNEST(ak.permissions) AS permission | ||
FROM api_keys ak; |
16 changes: 16 additions & 0 deletions
16
services/tenants/migrations/20240625081827_api_key_perms_as_array.up.sql
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,16 @@ | ||
BEGIN; | ||
|
||
alter table api_keys add column permissions VARCHAR[] NOT NULL DEFAULT '{}'; | ||
|
||
UPDATE api_keys ak | ||
SET permissions = ( | ||
SELECT ARRAY_AGG(akp.permission) | ||
FROM api_key_permissions akp | ||
WHERE akp.api_key_id = ak.id | ||
); | ||
|
||
alter table api_keys alter column permissions drop default; | ||
|
||
drop table api_key_permissions; | ||
|
||
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