-
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.
feat: update migrations to include role creation and permissions mana…
…gement, with support for privileged user migration execution
- Loading branch information
1 parent
2f79eb3
commit 93d2237
Showing
25 changed files
with
922 additions
and
414 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
kolomoni_migrations/migrations/M0001_prepare-database/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,27 @@ | ||
DROP SCHEMA kolomoni CASCADE; | ||
DROP SCHEMA migrations CASCADE; | ||
|
||
GRANT | ||
ALL PRIVILEGES | ||
ON SCHEMA public | ||
TO PUBLIC; | ||
|
||
|
||
REVOKE | ||
CONNECT, TEMPORARY | ||
ON DATABASE stari_kolomoni | ||
FROM kolomoni_backend; | ||
|
||
REVOKE | ||
ALL PRIVILEGES | ||
ON DATABASE stari_kolomoni | ||
FROM kolomoni_migrator; | ||
|
||
GRANT | ||
ALL PRIVILEGES | ||
ON DATABASE stari_kolomoni | ||
TO PUBLIC; | ||
|
||
|
||
DROP ROLE kolomoni_backend; | ||
DROP ROLE kolomoni_migrator; |
38 changes: 38 additions & 0 deletions
38
kolomoni_migrations/migrations/M0001_prepare-database/migration.toml
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,38 @@ | ||
### | ||
# Migration | ||
# version 0001 | ||
# name prepare-database | ||
# | ||
# Created on: 2024-09-01T14:20:11Z | ||
### | ||
# | ||
# Note that it is impossible to modify the version or name of the migration in | ||
# this configuration file *by design*. Both the version and name are | ||
# *always* parsed from the parent directory name for consistency. | ||
# | ||
|
||
|
||
# Whether to run the migration (up and down) as a privileged user instead of the normal user. | ||
# Depending on setup, this might be required for things like creating databases and granting permissions. | ||
run_as_privileged_user = true | ||
|
||
|
||
## | ||
# Configuration that impacts the up.sql migration script. | ||
## | ||
[up] | ||
# Certain statements, such as CREATE INDEX CONCURRENTLY, cannot be run inside a transaction. | ||
# Using those statements in your migration script will require you to run the migration | ||
# without a transaction. | ||
run_inside_transaction = true | ||
|
||
|
||
|
||
## | ||
# Configuration that impacts the down.sql rollback script. | ||
## | ||
[down] | ||
# Certain statements, such as CREATE INDEX CONCURRENTLY, cannot be run inside a transaction. | ||
# Using those statements in your migration script will require you to run the migration | ||
# without a transaction. | ||
run_inside_transaction = true |
78 changes: 78 additions & 0 deletions
78
kolomoni_migrations/migrations/M0001_prepare-database/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,78 @@ | ||
CREATE | ||
ROLE kolomoni_migrator | ||
LOGIN | ||
PASSWORD 'kolomoni_migrator'; | ||
|
||
CREATE | ||
ROLE kolomoni_backend | ||
LOGIN | ||
PASSWORD 'kolomoni_backend'; | ||
|
||
|
||
REVOKE | ||
ALL PRIVILEGES | ||
ON DATABASE stari_kolomoni | ||
FROM PUBLIC; | ||
|
||
GRANT | ||
ALL PRIVILEGES | ||
ON DATABASE stari_kolomoni | ||
TO kolomoni_migrator; | ||
|
||
GRANT | ||
CONNECT, TEMPORARY | ||
ON DATABASE stari_kolomoni | ||
TO kolomoni_backend; | ||
|
||
|
||
|
||
REVOKE | ||
ALL PRIVILEGES | ||
ON SCHEMA public | ||
FROM PUBLIC; | ||
|
||
|
||
|
||
CREATE | ||
SCHEMA migrations | ||
AUTHORIZATION kolomoni_migrator; | ||
|
||
GRANT | ||
ALL PRIVILEGES | ||
ON SCHEMA migrations | ||
TO kolomoni_migrator; | ||
|
||
|
||
|
||
CREATE | ||
SCHEMA kolomoni | ||
AUTHORIZATION kolomoni_migrator; | ||
|
||
GRANT | ||
ALL PRIVILEGES | ||
ON SCHEMA kolomoni | ||
TO kolomoni_migrator; | ||
|
||
GRANT | ||
USAGE | ||
ON SCHEMA kolomoni | ||
TO kolomoni_backend; | ||
|
||
|
||
|
||
ALTER DEFAULT PRIVILEGES | ||
FOR ROLE postgres | ||
IN SCHEMA migrations | ||
GRANT | ||
ALL PRIVILEGES | ||
ON TABLES | ||
TO kolomoni_migrator; | ||
|
||
|
||
ALTER DEFAULT PRIVILEGES | ||
FOR ROLE kolomoni_migrator | ||
IN SCHEMA kolomoni | ||
GRANT | ||
SELECT, INSERT, UPDATE, DELETE | ||
ON TABLES | ||
TO kolomoni_backend; |
File renamed without changes.
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
Oops, something went wrong.