From 0e9634c365ad0724f185034ce6994ba72752e343 Mon Sep 17 00:00:00 2001 From: Pavel Kirilin <win10@list.ru> Date: Sun, 2 Feb 2020 18:22:19 +0400 Subject: [PATCH] Makefile and migrations. Description: - Fixed permissions bug. - Added SCP permission. - Fixed makefile psql command. Signed-off-by: Pavel Kirilin <win10@list.ru> --- Makefile | 2 +- src/migrations/versions/0002_adding_scp.py | 42 ++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/migrations/versions/0002_adding_scp.py diff --git a/Makefile b/Makefile index 49e49d2..14f40e4 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,7 @@ rm_prod: ## Runs PostgreSQL UI. | Database psql: - @docker exec -it system_bot_postgres psql -U telegram_sysadmin -d sysadmin_db + @docker exec -it system_bot_postgres psql -U dev_telegram_sysadmin -d dev_sysadmin_db ## Runs bash shell in python container shell: diff --git a/src/migrations/versions/0002_adding_scp.py b/src/migrations/versions/0002_adding_scp.py new file mode 100644 index 0000000..e9639ee --- /dev/null +++ b/src/migrations/versions/0002_adding_scp.py @@ -0,0 +1,42 @@ +"""Adding scp permission level + +Revision ID: 86fb331dd32c +Revises: 0001 +Create Date: 2020-02-01 14:37:14.187262 + +""" +from alembic import op + +# revision identifiers, used by Alembic. + +revision = '0002' +down_revision = '0001' +branch_labels = None +depends_on = None + + +def update_enum(values): + return f""" + CREATE TYPE serverpermissions1 AS ENUM ({values}); + ALTER TABLE servers + ALTER COLUMN server_permissions DROP DEFAULT, + ALTER COLUMN server_permissions TYPE serverpermissions1 USING (server_permissions::text::serverpermissions1), + ALTER COLUMN server_permissions SET DEFAULT 'INFO'; + DROP TYPE serverpermissions; + ALTER TYPE serverpermissions1 RENAME TO serverpermissions; + """ + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.execute(update_enum("'INFO', 'SCP', 'DOCKER', 'SERVICES', 'RCE', 'DELETE'")) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.execute(f""" + UPDATE servers SET server_permissions='INFO' where server_permissions='SCP'; + {update_enum("'INFO', 'DOCKER', 'SERVICES', 'RCE', 'DELETE'")} + """) + # ### end Alembic commands ### -- GitLab