diff --git a/scripts/create_tables.py b/scripts/create_tables.py index d0abafe..661df3d 100644 --- a/scripts/create_tables.py +++ b/scripts/create_tables.py @@ -22,6 +22,21 @@ from ahserver.globalEnv import initEnv TABLE_MODULES = ['product_management', 'discount', 'pricing', 'unipay', 'smssend'] +# appbase 系统级配置表(幂等建表 + 默认参数,不 DROP 以免清空运行时数据) +_PARAMS_DDL = """ +CREATE TABLE IF NOT EXISTS params ( + `id` VARCHAR(32) comment 'id', + `params_name` VARCHAR(255) comment '参数名称', + `params_value` VARCHAR(4000) comment '参数值', + primary key(id) +) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci engine=innodb comment '系统参数表'; +""" + +_PARAMS_INIT = [ + ("workspace_base", "/d/pipeline/workspaces"), +] + + def split_ddl(ddl): """按分号分割 DDL,跳过注释行和空语句。""" stmts = [] @@ -57,6 +72,19 @@ async def main(): n += 1 print(f' tables: {mod} created ({n} statements)') + # appbase params 表幂等建表 + 默认参数 + try: + await sor.execute(_PARAMS_DDL, {}) + for pname, pval in _PARAMS_INIT: + await sor.execute( + "INSERT INTO params (id, params_name, params_value) " + "VALUES (${id}$, ${n}$, ${v}$) " + "ON DUPLICATE KEY UPDATE params_value=${v}$", + {"id": pname, "n": pname, "v": pval}) + print(' tables: appbase params ensured (workspace_base)') + except Exception as e: + print(f' WARN: appbase params ensure failed: {e}') + if __name__ == '__main__': asyncio.run(main())