Commit 5b721faa authored by Daniele Venzano's avatar Daniele Venzano

Drop the schema before creating new tables to account for versions mismatches during testing

parent fb345e6d
......@@ -15,9 +15,15 @@
"""Create the DB tables needed by Zoe. This script is used in the CI pipeline to prevent race conditions with zoe-api automatically creating the tables while zoe-master is starting at the same time."""
import time
import zoe_lib.config as config
import zoe_api.db_init
config.load_configuration()
zoe_api.db_init.init()
print("Warning, this script will delete the database tables for the deployment '{}' before creating new ones".format(config.get_conf().deployment_name))
print("Sleeping 5 seconds before continuing, hit CTRL-C to stop and think.")
time.sleep(5)
zoe_api.db_init.init(force=True)
......@@ -108,7 +108,7 @@ def create_tables(cur):
)''')
def init():
def init(force=False):
"""DB init entrypoint."""
dsn = 'dbname=' + get_conf().dbname + \
' user=' + get_conf().dbuser + \
......@@ -121,6 +121,11 @@ def init():
version_table(cur)
cur.execute('SET search_path TO {},public'.format(get_conf().deployment_name))
if force:
cur.execute("DELETE FROM public.versions WHERE deployment = %s", (get_conf().deployment_name,))
cur.execute('DROP SCHEMA {} CASCADE'.format(get_conf().deployment_name))
if not check_schema_version(cur, get_conf().deployment_name):
create_tables(cur)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment