Files
windmill/backend/overwrite_migrations.py
Ruben Fiszel 08374e7984 feat: db users: admin -> windmill_admin, app -> windmill_user (#404)
* feat: db users: admin -> windmill_admin, app -> windmill_user

* clean up

* backend tests

* backend tests

* backend tests

* lock roles in first migration

* check if user is superuser too

* add init-db

* add init-db
2022-08-14 18:20:27 +02:00

25 lines
840 B
Python

import sys
import os
import subprocess
database_url = sys.argv[1]
print(f"database_url: {database_url}")
if database_url is None:
print("Please provide a database url")
sys.exit(1)
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)
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)
out = ps.communicate()[0].decode("utf-8").strip()
print(version, digest, out)