37 lines
1001 B
Python
37 lines
1001 B
Python
from pathlib import Path
|
|
import sys
|
|
|
|
from sqlalchemy import text
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT))
|
|
|
|
from app.database import engine # noqa: E402
|
|
|
|
|
|
def _column_exists(conn, table_name: str, column_name: str) -> bool:
|
|
return bool(conn.execute(
|
|
text("""
|
|
SELECT COUNT(1)
|
|
FROM information_schema.columns
|
|
WHERE table_schema = DATABASE()
|
|
AND table_name = :table_name
|
|
AND column_name = :column_name
|
|
"""),
|
|
{"table_name": table_name, "column_name": column_name},
|
|
).scalar())
|
|
|
|
|
|
def main() -> None:
|
|
with engine.begin() as conn:
|
|
if not _column_exists(conn, "production_reports", "review_remark"):
|
|
conn.execute(text("""
|
|
ALTER TABLE production_reports
|
|
ADD COLUMN review_remark VARCHAR(500) NULL AFTER reject_reason
|
|
"""))
|
|
print("report review remark column migrated")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|