Skip to content

Commit

Permalink
Merge pull request #201 from HSF/dev
Browse files Browse the repository at this point in the history
fix alembic
  • Loading branch information
wguanicedew authored Sep 14, 2023
2 parents b332ff9 + 5b8efbb commit 8947c7b
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions main/lib/idds/orm/base/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
Utils to create the database or destroy the database
"""

import io
import os
import traceback
from typing import Union
Expand Down Expand Up @@ -51,8 +52,20 @@ def build_database(echo=True, tests=False):
# record the head version of alembic
alembic_cfg_file = os.environ.get("ALEMBIC_CONFIG")
alembic_cfg = Config(alembic_cfg_file)
command.upgrade(alembic_cfg, "head")
command.stamp(alembic_cfg, "head")

output_buffer = io.StringIO()
alembic_cfg1 = Config(alembic_cfg_file, stdout=output_buffer)
current_version = command.current(alembic_cfg1)
current_version = output_buffer.getvalue()
print("current_version: " + current_version)

if current_version is None or len(current_version) == 0:
print("no current version, stamp it")
command.stamp(alembic_cfg, "head")
command.upgrade(alembic_cfg, "head")
else:
print("has current version, try to upgrade")
command.upgrade(alembic_cfg, "head")


def destroy_database(echo=True):
Expand Down

0 comments on commit 8947c7b

Please sign in to comment.