Auto-sync permit competitors in monitoring PF
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 35s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 35s
This commit is contained in:
13
app/db.py
13
app/db.py
@@ -30,6 +30,7 @@ def init_db():
|
||||
|
||||
Base.metadata.create_all(bind=engine)
|
||||
_migrate_employees_portal_user_id()
|
||||
_migrate_competitor_listings_auto_fields()
|
||||
|
||||
|
||||
def _migrate_employees_portal_user_id() -> None:
|
||||
@@ -43,3 +44,15 @@ def _migrate_employees_portal_user_id() -> None:
|
||||
conn.execute(
|
||||
text("CREATE UNIQUE INDEX IF NOT EXISTS ix_employees_portal_user_id ON employees (portal_user_id)")
|
||||
)
|
||||
|
||||
|
||||
def _migrate_competitor_listings_auto_fields() -> None:
|
||||
inspector = inspect(engine)
|
||||
if "competitor_listings" not in inspector.get_table_names():
|
||||
return
|
||||
columns = {col["name"] for col in inspector.get_columns("competitor_listings")}
|
||||
with engine.begin() as conn:
|
||||
if "permit_number" not in columns:
|
||||
conn.execute(text("ALTER TABLE competitor_listings ADD COLUMN permit_number VARCHAR(100)"))
|
||||
if "auto_discovered" not in columns:
|
||||
conn.execute(text("ALTER TABLE competitor_listings ADD COLUMN auto_discovered BOOLEAN NOT NULL DEFAULT 0"))
|
||||
|
||||
Reference in New Issue
Block a user