JhHardwareWRS_BackPoint/scripts/migrate_reconciliation_ledger.py
2026-06-24 15:19:14 +08:00

34 lines
1.1 KiB
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:
conn.execute(text("""
CREATE TABLE IF NOT EXISTS reconciliation_ledger_entries (
year INT NOT NULL,
month INT NOT NULL,
product_name VARCHAR(255) NOT NULL,
reconciled_good_qty DECIMAL(14, 2) NOT NULL DEFAULT 0,
return_qty DECIMAL(14, 2) NOT NULL DEFAULT 0,
updated_by VARCHAR(20) NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (year, month, product_name),
INDEX idx_reconciliation_product (product_name),
INDEX idx_reconciliation_updated (updated_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
"""))
print("reconciliation ledger migrated")
if __name__ == "__main__":
main()