在前后端开发联调前 的提交20260223
This commit is contained in:
93
scripts/ops/_archive_phase2.py
Normal file
93
scripts/ops/_archive_phase2.py
Normal file
@@ -0,0 +1,93 @@
|
||||
"""
|
||||
第二轮归档:迁移脚本 + 过时的变更记录文档。
|
||||
保留:seeds、fdw、create_test_db、数据字典类 BD_Manual。
|
||||
|
||||
用法:cd C:\\NeoZQYY && python scripts/ops/_archive_phase2.py
|
||||
"""
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
from datetime import date
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent.parent
|
||||
ARCHIVE_BASE = ROOT / "db" / "_archived" / f"ddl_baseline_{date.today().isoformat()}"
|
||||
|
||||
# ── 1. db/ 下的迁移脚本 ──────────────────────────────────────────────────
|
||||
MIGRATION_FILES = []
|
||||
for d in ["db/etl_feiqiu/migrations", "db/zqyy_app/migrations"]:
|
||||
p = ROOT / d
|
||||
if p.exists():
|
||||
for f in sorted(p.glob("*.sql")):
|
||||
MIGRATION_FILES.append(str(f.relative_to(ROOT)))
|
||||
|
||||
# 一次性数据迁移脚本
|
||||
MIGRATION_FILES.append("db/scripts/migrate_test_data.sql")
|
||||
|
||||
# ── 2. docs/database/ 下的迁移变更记录(非数据字典) ─────────────────────
|
||||
# 迁移变更记录:记录某次 ALTER/DROP/CREATE 操作的 BD_Manual
|
||||
MIGRATION_DOCS = [
|
||||
"docs/database/BD_Manual_dim_member_add_birthday.md", # C1 加列
|
||||
"docs/database/BD_Manual_drop_assistant_abolish_tables.md", # 删表
|
||||
"docs/database/BD_Manual_dws_assistant_monthly_uk_change.md", # 改约束
|
||||
"docs/database/BD_Manual_dws_assistant_salary_uk_change.md", # 改约束
|
||||
"docs/database/BD_Manual_fix_bc_sentinel_dates.md", # 修数据
|
||||
"docs/database/BD_Manual_fdw_reverse_member_birthday.md", # FDW 变更
|
||||
"docs/database/BD_Manual_member_birthday_manual.md", # 新建表
|
||||
"docs/database/etl_feiqiu_schema_migration.md", # 迁移汇总
|
||||
"docs/database/zqyy_app_admin_web_tables.md", # 新建表
|
||||
]
|
||||
|
||||
# docs 归档到 docs/database/_archived/
|
||||
DOCS_ARCHIVE = ROOT / "docs" / "database" / "_archived"
|
||||
|
||||
|
||||
def move_file(src_rel, dest_base):
|
||||
"""移动文件,保留相对路径结构。"""
|
||||
src = ROOT / src_rel
|
||||
if not src.exists():
|
||||
return None
|
||||
dest = dest_base / src_rel
|
||||
dest.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.move(str(src), str(dest))
|
||||
return src_rel
|
||||
|
||||
|
||||
def main():
|
||||
moved_db = []
|
||||
moved_docs = []
|
||||
|
||||
# 归档迁移 SQL
|
||||
print("── 归档迁移脚本 → db/_archived/ ──")
|
||||
for rel in MIGRATION_FILES:
|
||||
result = move_file(rel, ARCHIVE_BASE)
|
||||
if result:
|
||||
moved_db.append(result)
|
||||
print(f" ✅ {result}")
|
||||
|
||||
# 归档迁移变更文档
|
||||
print("\n── 归档迁移变更文档 → docs/database/_archived/ ──")
|
||||
for rel in MIGRATION_DOCS:
|
||||
src = ROOT / rel
|
||||
if not src.exists():
|
||||
continue
|
||||
dest = DOCS_ARCHIVE / src.name
|
||||
DOCS_ARCHIVE.mkdir(parents=True, exist_ok=True)
|
||||
shutil.move(str(src), str(dest))
|
||||
moved_docs.append(rel)
|
||||
print(f" ✅ {src.name}")
|
||||
|
||||
# 补充 .gitkeep
|
||||
for d in ["db/etl_feiqiu/migrations", "db/zqyy_app/migrations", "db/scripts"]:
|
||||
gk = ROOT / d / ".gitkeep"
|
||||
dp = ROOT / d
|
||||
if dp.exists() and not gk.exists():
|
||||
# 检查目录是否只剩 .gitkeep 或为空
|
||||
remaining = [f for f in dp.iterdir() if f.name != ".gitkeep"]
|
||||
if not remaining:
|
||||
gk.touch()
|
||||
print(f" 📄 补充 {d}/.gitkeep")
|
||||
|
||||
print(f"\n✅ 完成:归档 {len(moved_db)} 个迁移 SQL + {len(moved_docs)} 个变更文档")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user