fix: fix database migration

This commit is contained in:
Ruben Fiszel
2023-07-23 12:13:56 +02:00
parent 154989c87e
commit 60d7887a8b
4 changed files with 15 additions and 10 deletions
@@ -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;
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));
@@ -0,0 +1 @@
-- Add down migration script here
@@ -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;
+7 -3
View File
@@ -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)