Skip to content

Commit

Permalink
Merge branch 'main' into rules-range-differ
Browse files Browse the repository at this point in the history
  • Loading branch information
lunakv authored Feb 7, 2024
2 parents a68fa35 + f42c372 commit 020d9c2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
4 changes: 2 additions & 2 deletions alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from sqlalchemy import engine_from_config, pool

from alembic import context
from models import Base
from src.models import get_full_base

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
Expand All @@ -19,7 +19,7 @@
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
target_metadata = Base.metadata
target_metadata = get_full_base().metadata

# other values from the config, defined by the needs of env.py,
# can be acquired:
Expand Down
2 changes: 1 addition & 1 deletion src/cr/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


def get_latest_cr(db: Session) -> Cr:
stmt = select(Cr).order_by(Cr.creation_day.desc())
stmt = select(Cr).order_by(Cr.creation_day.desc()).limit(1)
result = db.execute(stmt).scalars().first()
return result

Expand Down
4 changes: 2 additions & 2 deletions src/diffs/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ def get_cr_diff(db: Session, old_code: str | None, new_code: str | None) -> CrDi
stmt = stmt.order_by(CrDiff.creation_day.desc()).limit(1)
else:
if old_code:
stmt = stmt.where(src.set_code == old_code)
stmt = stmt.where(src.set_code == old_code).limit(1)
if new_code:
stmt = stmt.where(dst.set_code == new_code)
stmt = stmt.where(dst.set_code == new_code).limit(1)

return db.execute(stmt).scalars().first()

Expand Down
15 changes: 15 additions & 0 deletions src/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
from sqlalchemy.orm import declarative_base

Base = declarative_base()


# noinspection PyUnresolvedReferences


def get_full_base():
"""Imports all database models before returning the Base object. Used for alembic migrations"""

import src.cr.models # noqa: F401
import src.diffs.models # noqa: F401
import src.ipg.models # noqa: F401
import src.link.models # noqa: F401
import src.mtr.models # noqa: F401

return Base
2 changes: 1 addition & 1 deletion src/mtr/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


def get_current_mtr(db: Session) -> Mtr:
stmt = select(Mtr).order_by(Mtr.creation_day.desc())
stmt = select(Mtr).order_by(Mtr.creation_day.desc()).limit(1)
result = db.execute(stmt).scalars().first()
return result

Expand Down

0 comments on commit 020d9c2

Please sign in to comment.