# -*- coding: utf-8 -*- # Author : Charley # Python : 3.12.10 # Date : 2026/08/02 """执行 schema.sql 建表(幂等,CREATE TABLE IF NOT EXISTS)。""" from loguru import logger from mysql_pool import MySQLConnectionPool def main(): """读取 schema.sql 并逐条执行建表语句,最后打印已建表清单。""" with open("schema.sql", "r", encoding="utf-8") as f: raw = f.read() # 去掉整行注释,再按分号切分为独立语句 lines = [ln for ln in raw.splitlines() if not ln.strip().startswith("--")] stmts = [s.strip() for s in "\n".join(lines).split(";") if s.strip()] pool = MySQLConnectionPool(log=logger) for stmt in stmts: pool._execute(stmt, commit=True) head = stmt.split("(")[0].strip().replace("\n", " ") logger.info(f"执行成功: {head}") rows = pool.select_all("SHOW TABLES LIKE 'deca\\_%'") logger.info(f"当前 deca 表: {[r[0] for r in rows]}") if __name__ == "__main__": main()