2024-07-20 15:48:46 +03:30
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# dbmigrate.py: migrate the local database
|
|
|
|
# - run either on dev machine or at server
|
|
|
|
#
|
2024-08-12 18:51:40 +03:30
|
|
|
# Author: Tomi.Mickelsson@iki.fi & Edited by sepehr.ha@gmail.com
|
2024-07-20 15:48:46 +03:30
|
|
|
|
|
|
|
import os
|
|
|
|
import config
|
2024-08-12 18:51:40 +03:30
|
|
|
from urllib.parse import quote
|
2024-07-20 15:48:46 +03:30
|
|
|
|
|
|
|
if config.DATABASE_HOST.startswith("/"):
|
|
|
|
# sqlite
|
|
|
|
# note: can't use full path here!
|
|
|
|
# db will appear in "/app/data/mydb.sqlite" (mapped volume locally)
|
|
|
|
cmd = "pw_migrate migrate --directory=/app/migrations_sqlite --database=sqlite:/data/mydb.sqlite"
|
|
|
|
else:
|
|
|
|
# postgresql
|
2024-08-12 18:51:40 +03:30
|
|
|
cmd = "pw_migrate migrate --database='postgresql://{}:{}/{}?user={}&password={}'".format(
|
2024-07-20 15:48:46 +03:30
|
|
|
config.DATABASE_HOST,
|
|
|
|
config.DATABASE_PORT,
|
2024-08-12 18:51:40 +03:30
|
|
|
config.DATABASE_NAME,
|
|
|
|
config.DATABASE_USER,
|
|
|
|
quote(config.DATABASE_PASSWORD))
|
2024-07-20 15:48:46 +03:30
|
|
|
|
|
|
|
print(cmd)
|
|
|
|
|
|
|
|
ret = os.system(cmd)
|
|
|
|
if ret:
|
|
|
|
print("migrate ERROR", ret)
|
|
|
|
else:
|
|
|
|
print("migrate OK")
|
|
|
|
|