From 60d7887a8b29eb9691c37c9676bf64e52db5e4e2 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Sun, 23 Jul 2023 12:13:56 +0200 Subject: [PATCH] fix: fix database migration --- .../migrations/20230720092702_instance_groups.up.sql | 9 ++------- .../20230723101321_instance_groups_fix.down.sql | 1 + .../20230723101321_instance_groups_fix.up.sql | 5 +++++ backend/overwrite_migrations.py | 10 +++++++--- 4 files changed, 15 insertions(+), 10 deletions(-) create mode 100644 backend/migrations/20230723101321_instance_groups_fix.down.sql create mode 100644 backend/migrations/20230723101321_instance_groups_fix.up.sql diff --git a/backend/migrations/20230720092702_instance_groups.up.sql b/backend/migrations/20230720092702_instance_groups.up.sql index 7d961b99ab..f9b93c6083 100644 --- a/backend/migrations/20230720092702_instance_groups.up.sql +++ b/backend/migrations/20230720092702_instance_groups.up.sql @@ -1,8 +1,3 @@ -- Add up migration script here -CREATE TABLE instance_group (name VARCHAR(255) PRIMARY KEY, summary VARCHAR(2000)); -CREATE TABLE email_to_igroup (email VARCHAR(255), igroup VARCHAR(255) NOT NULL, PRIMARY KEY (email, igroup)); - -GRANT ALL PRIVILEGES ON TABLE instance_group TO windmill_admin; -GRANT ALL PRIVILEGES ON TABLE instance_group TO windmill_user; -GRANT ALL PRIVILEGES ON TABLE email_to_igroup TO windmill_admin; -GRANT ALL PRIVILEGES ON TABLE email_to_igroup TO windmill_user; \ No newline at end of file +CREATE TABLE instance_group (name VARCHAR(255) PRIMARY KEY, summary VARCHAR(2000), external_id VARCHAR(1000)); +CREATE TABLE email_to_igroup (email VARCHAR(255), igroup VARCHAR(255), PRIMARY KEY (email, igroup)); \ No newline at end of file diff --git a/backend/migrations/20230723101321_instance_groups_fix.down.sql b/backend/migrations/20230723101321_instance_groups_fix.down.sql new file mode 100644 index 0000000000..d2f607c5b8 --- /dev/null +++ b/backend/migrations/20230723101321_instance_groups_fix.down.sql @@ -0,0 +1 @@ +-- Add down migration script here diff --git a/backend/migrations/20230723101321_instance_groups_fix.up.sql b/backend/migrations/20230723101321_instance_groups_fix.up.sql new file mode 100644 index 0000000000..07b5757400 --- /dev/null +++ b/backend/migrations/20230723101321_instance_groups_fix.up.sql @@ -0,0 +1,5 @@ +-- Add up migration script here +GRANT ALL PRIVILEGES ON TABLE instance_group TO windmill_admin; +GRANT ALL PRIVILEGES ON TABLE instance_group TO windmill_user; +GRANT ALL PRIVILEGES ON TABLE email_to_igroup TO windmill_admin; +GRANT ALL PRIVILEGES ON TABLE email_to_igroup TO windmill_user; \ No newline at end of file diff --git a/backend/overwrite_migrations.py b/backend/overwrite_migrations.py index f4e8df6771..ccda8cf789 100644 --- a/backend/overwrite_migrations.py +++ b/backend/overwrite_migrations.py @@ -14,11 +14,15 @@ for f in os.listdir("migrations"): if f.endswith(".up.sql"): version = f.split("_")[0] cmd = f"cat migrations/{f} | openssl dgst -sha384 | cut -d ' ' -f 2" - ps = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT) + ps = subprocess.Popen( + cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT + ) digest = ps.communicate()[0].decode("utf-8").strip() cmd = f"psql '{database_url}' -c \"UPDATE _sqlx_migrations SET checksum = '\\x{digest}' WHERE version = {version};\"" - ps = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT) + ps = subprocess.Popen( + cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT + ) out = ps.communicate()[0].decode("utf-8").strip() + print(f, cmd) print(version, digest, out) -