Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Oct 2, 2023
1 parent 73b3fea commit d8a4dc9
Show file tree
Hide file tree
Showing 5 changed files with 2,143 additions and 862 deletions.
1 change: 1 addition & 0 deletions src/backend/app/db/db_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
UserRole,
ValidationPermission,
)

from .database import Base, FmtmMetadata
from .postgis_utils import timestamp

Expand Down
2 changes: 1 addition & 1 deletion src/backend/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from .auth import auth_routes
from .central import central_routes
from .config import settings
from .db.database import Base, engine, get_db
from .db.database import get_db
from .organization import organization_routes
from .projects import project_routes
from .projects.project_crud import read_xlsforms
Expand Down
19 changes: 11 additions & 8 deletions src/backend/app/migrations/alembic_helpers.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
from alembic import op
from sqlalchemy import engine_from_config
from sqlalchemy.engine import reflection



def table_does_not_exist(table, schema=None):
config = op.get_context().config
engine = engine_from_config(
config.get_section(config.config_ini_section), prefix='sqlalchemy.')
config.get_section(config.config_ini_section), prefix="sqlalchemy."
)
insp = reflection.Inspector.from_engine(engine)
return insp.has_table(table, schema) == False
return insp.has_table(table, schema) is False


def table_has_column(table, column):
config = op.get_context().config
engine = engine_from_config(
config.get_section(config.config_ini_section), prefix='sqlalchemy.')
config.get_section(config.config_ini_section), prefix="sqlalchemy."
)
insp = reflection.Inspector.from_engine(engine)
has_column = False
for col in insp.get_columns(table):
if column not in col['name']:
if column not in col["name"]:
continue
has_column = True
return has_column
return has_column
7 changes: 4 additions & 3 deletions src/backend/app/migrations/env.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from logging.config import fileConfig
from alembic import op

from alembic import context
from config import settings
from db.db_models import Base
from geoalchemy2 import alembic_helpers
from sqlalchemy import engine_from_config, pool
from db.db_models import Base

config = context.config
config.set_main_option("sqlalchemy.url", settings.FMTM_DB_URL)
Expand All @@ -18,6 +18,7 @@

exclude_tables = config.get_section("alembic:exclude").get("tables", "").split(",")


def include_object(object, name, type_, reflected, compare_to):
"""Custom helper function that enables us to ignore our excluded tables in the autogen sweep."""
if type_ == "table" and name in exclude_tables:
Expand Down Expand Up @@ -80,4 +81,4 @@ def run_migrations_online() -> None:
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()
run_migrations_online()
Loading

0 comments on commit d8a4dc9

Please sign in to comment.