Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
minor refine
Browse files Browse the repository at this point in the history
  • Loading branch information
CzBiX committed Sep 24, 2023
1 parent fd01336 commit a3b83ef
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import logging

logging.basicConfig(level=logging.DEBUG)
logging.root.setLevel(logging.DEBUG)

def main():
from uvicorn import run
Expand Down
8 changes: 8 additions & 0 deletions src/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .model import DB_URL, User, UserToken, get_engine

engine = get_engine(DB_URL, settings.echo)
_migrated = False

@event.listens_for(engine, 'connect')
def conn_wal_mode(conn, _):
Expand All @@ -16,10 +17,17 @@ def conn_wal_mode(conn, _):

@event.listens_for(engine, 'engine_connect')
def db_migrations(conn, _):
global _migrated

if _migrated:
return

from .migration import run_migrations

run_migrations(conn)

_migrated = True

def db_session():
with Session(engine) as session:
yield session
Expand Down
4 changes: 3 additions & 1 deletion src/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def run_migrations(conn):
while version < LATEST_VERSION:
logger.info(f'Running migration {version}')

with context.begin_transaction(_per_migration=True):
with context.begin_transaction():
action = _ACTIONS[version]
version = action(op) or (version + 1)

Expand All @@ -53,3 +53,5 @@ def run_migrations(conn):
)
)

context.connection.rollback()

0 comments on commit a3b83ef

Please sign in to comment.