Skip to content

Commit

Permalink
Fix stall on initial database setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
MelissaAutumn committed Nov 1, 2024
1 parent ab876f0 commit 413405b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions backend/src/appointment/commands/update_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,23 @@ def run():

engine, _ = get_engine_and_session()

fresh_db = False

with engine.begin() as connection:
context = migration.MigrationContext.configure(connection)
# Returns a tuple, empty if there's no revisions saved
revisions = context.get_current_heads()

# If we have no revisions, then fully create the database from the model metadata,
# and set our revision number to the latest revision. Otherwise run any new migrations
if len(revisions) == 0:
print('Initializing database, and setting it to the latest revision')
models.Base.metadata.create_all(bind=engine)
command.stamp(alembic_cfg, 'head')
else:
print('Database already initialized, running migrations')
command.upgrade(alembic_cfg, 'head')
print('Finished checking database')
fresh_db = True

# If it's a fresh db set our revision number to the latest revision. Otherwise run any new migrations
if fresh_db:
command.stamp(alembic_cfg, 'head')
else:
print('Database already initialized, running migrations')
command.upgrade(alembic_cfg, 'head')
print('Finished checking database')
2 changes: 1 addition & 1 deletion backend/src/appointment/migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# Interpret the config file for Python logging.
# This line sets up loggers basically.
if config.config_file_name is not None:
fileConfig(config.config_file_name)
fileConfig(config.config_file_name, disable_existing_loggers=False)

# add your model's MetaData object here
# for 'autogenerate' support
Expand Down

0 comments on commit 413405b

Please sign in to comment.