dy-dashboard/scripts/migrate_planning_new_old.py

29 lines
871 B
Python

"""Add the manual flag and pending snapshot; use --local on the test server."""
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
if '--local' in sys.argv:
import test_wsgi
from services.db import query
def migrate():
for table, column, definition in (
('products', 'planning_new_old', "VARCHAR(8) NOT NULL DEFAULT '否'"),
('pending_orders', 'new_old_product', 'VARCHAR(8) NULL DEFAULT NULL'),
):
exists = query(
'SELECT COLUMN_NAME FROM information_schema.COLUMNS '
'WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME=%s AND COLUMN_NAME=%s',
(table, column),
)
if not exists:
query(f'ALTER TABLE {table} ADD COLUMN {column} {definition}')
print(f'{table}.{column}: ready')
if __name__ == '__main__':
migrate()