36 lines
954 B
Python
36 lines
954 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 main() -> None:
|
|
with engine.begin() as conn:
|
|
columns = conn.execute(
|
|
text(
|
|
"SELECT COUNT(*) FROM information_schema.COLUMNS "
|
|
"WHERE TABLE_SCHEMA = DATABASE() "
|
|
"AND TABLE_NAME = 'production_report_items' "
|
|
"AND COLUMN_NAME = 'started_at'"
|
|
)
|
|
).scalar()
|
|
if columns:
|
|
print("production_report_items.started_at already exists")
|
|
return
|
|
conn.execute(
|
|
text(
|
|
"ALTER TABLE production_report_items "
|
|
"ADD COLUMN started_at DATETIME NULL AFTER allocated_minutes"
|
|
)
|
|
)
|
|
print("added production_report_items.started_at")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|