|
|
@@ -0,0 +1,36 @@
|
|
|
+#!/usr/bin/env bash
|
|
|
+set -euo pipefail
|
|
|
+
|
|
|
+project_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
|
+source_path="$project_root/database/zhibaotong-stage1-stage2-stage3-mysql.sql"
|
|
|
+target_path="$project_root/database/zhibaotong-stage3-mysql.sql"
|
|
|
+
|
|
|
+uv run --project "$project_root/backend" python - "$source_path" "$target_path" <<'PY'
|
|
|
+from pathlib import Path
|
|
|
+import sys
|
|
|
+
|
|
|
+source_path = Path(sys.argv[1])
|
|
|
+target_path = Path(sys.argv[2])
|
|
|
+content = source_path.read_text(encoding="utf-8")
|
|
|
+
|
|
|
+session_start_marker = "/*!40101 SET @OLD_CHARACTER_SET_CLIENT"
|
|
|
+first_database_marker = "-- Current Database: `insurance_s1_core`"
|
|
|
+stage3_marker = "-- Current Database: `insurance_s3_core`"
|
|
|
+
|
|
|
+session_start = content.find(session_start_marker)
|
|
|
+first_database_start = content.find(first_database_marker)
|
|
|
+stage3_start = content.find(stage3_marker)
|
|
|
+if min(session_start, first_database_start, stage3_start) < 0:
|
|
|
+ raise RuntimeError("Expected stage boundaries were not found in the unified SQL.")
|
|
|
+
|
|
|
+session_preamble = content[session_start:first_database_start]
|
|
|
+stage3_body = content[stage3_start:]
|
|
|
+header = """-- Zhibaotong Stage 3 MySQL initialization script
|
|
|
+-- Source: zhibaotong-stage1-stage2-stage3-mysql.sql
|
|
|
+-- Databases: insurance_s3_core, insurance_s3_agent, insurance_s3_analytics
|
|
|
+-- Warning: importing this file rebuilds same-named tables in these databases.
|
|
|
+
|
|
|
+"""
|
|
|
+target_path.write_text(header + session_preamble + stage3_body, encoding="utf-8", newline="")
|
|
|
+print(f"Generated: {target_path}")
|
|
|
+PY
|