correctly handle when the desiredSchemaVersion < schemaVersion

This commit is contained in:
2020-05-09 19:22:25 -05:00
parent 4a1924587c
commit 119d4a0052
2 changed files with 12 additions and 5 deletions

View File

@ -60,8 +60,13 @@ def init_app(app):
cursor.execute("SELECT Version FROM schemaversion")
schemaVersion = cursor.fetchall()[0][0]
# print(schemaVersion)
if schemaVersion > desiredSchemaVersion:
print("schemaVersion ({}) > desiredSchemaVersion ({}). schema downgrades are not supported yet. exiting.".format(
schemaVersion, desiredSchemaVersion
))
exit(1)
while schemaVersion < desiredSchemaVersion:
migrationKey = "%02d_up" % (schemaVersion+1)
print("schemaVersion ({}) < desiredSchemaVersion ({}). running migration {}".format(
@ -94,8 +99,8 @@ def init_app(app):
app.config['PSYCOPG2_CONNECTION_POOL'].putconn(db)
print("schema migration completed. {}current schemaVersion: \"{}\"".format(
("" if actionWasTaken else "(no action was taken). "), schemaVersion
print("{} current schemaVersion: \"{}\"".format(
("schema migration completed." if actionWasTaken else "schema is already up to date. "), schemaVersion
))
app.teardown_appcontext(close_db)