- boot/ (Java/Maven, JNPF 7.0) — 移除旧的 boot/.git,源码直接纳入仓库
- web/ (Vue 3 + Vite + Ant Design Vue, pnpm)
- docs/, scard/, nax/
- refs/INDEX.md + refs/国标/(其余 refs/* 开源子仓库不纳入)
- 已忽略: connector_data/, jweb/, log/, web/{dist,node_modules,.pnpm}, boot/*/target/, .DS_Store, .idea, .vscode
54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
"""按文件顺序执行 SQL 迁移。
|
|
|
|
用法:apply.py <db名> <sql文件> [<sql文件> ...]
|
|
|
|
项目里没上 Flyway,迁移是手动执行的。两个坑必须处理:
|
|
1) 注释里可能带分号,先按行剥掉 `--` 注释再切语句,否则会切碎;
|
|
2) 语句里出现 `$$ ... $$` 的函数体不能按分号切——本项目暂时没有,先不处理,
|
|
真出现了这里会报错,比静默切错强。
|
|
"""
|
|
import sys
|
|
import psycopg2
|
|
|
|
HOST, PORT, USER, PWD = "127.0.0.1", 15432, "dacli", "dacli123"
|
|
|
|
|
|
def split_statements(sql: str):
|
|
lines = []
|
|
for line in sql.splitlines():
|
|
idx = line.find("--")
|
|
if idx >= 0:
|
|
line = line[:idx]
|
|
lines.append(line)
|
|
cleaned = "\n".join(lines)
|
|
if "$$" in cleaned:
|
|
raise SystemExit("检测到 $$ 块,本脚本不支持,请手动执行")
|
|
return [s.strip() for s in cleaned.split(";") if s.strip()]
|
|
|
|
|
|
def main():
|
|
if len(sys.argv) < 3:
|
|
raise SystemExit(__doc__)
|
|
db, files = sys.argv[1], sys.argv[2:]
|
|
conn = psycopg2.connect(host=HOST, port=PORT, user=USER, password=PWD, dbname=db)
|
|
conn.autocommit = True
|
|
cur = conn.cursor()
|
|
for path in files:
|
|
with open(path, "r", encoding="utf-8") as f:
|
|
stmts = split_statements(f.read())
|
|
ok = 0
|
|
for s in stmts:
|
|
try:
|
|
cur.execute(s)
|
|
ok += 1
|
|
except Exception as e:
|
|
print(f" [FAIL] {s[:90]}...\n {e}")
|
|
print(f"[{db}] {path}: {ok}/{len(stmts)} 条执行成功")
|
|
cur.close()
|
|
conn.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|