dicemy's picture
Upload 655 files
e8c001c verified
Raw
History Blame Contribute Delete
2.64 kB
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
mysql_016 ground truth: 应用X模型与组织关系小时表全量迁移
Task:
Full migration from source table to target table,
no filtering, no transformation, all columns preserved.
"""
import pymysql
import sys
DB_NAME = "internal_platform_db"
INPUT_TABLE = "t_app_xmodel_and_org_relation_hour_src_mysql_016"
OUTPUT_TABLE = "t_app_xmodel_and_org_relation_hour_cand_mysql_016"
MYSQL_CONFIG = {
"host": "localhost",
"port": 3306,
"user": "root",
"password": "root123",
"charset": "utf8mb4",
}
gt_sql = f"""
INSERT INTO {DB_NAME}.{OUTPUT_TABLE}
(xsoa_id, principal, xsoa_org_principal, xsoa_team_name, xsoa_team_id,
xsoa_center_name, xsoa_center_id, xsoa_dept_name, xsoa_dept_id,
xsoa_principal_index, xsoa_dimension, ds)
SELECT
xsoa_id,
principal,
xsoa_org_principal,
xsoa_team_name,
xsoa_team_id,
xsoa_center_name,
xsoa_center_id,
xsoa_dept_name,
xsoa_dept_id,
xsoa_principal_index,
xsoa_dimension,
ds
FROM {DB_NAME}.{INPUT_TABLE}
"""
def main():
conn = pymysql.connect(**MYSQL_CONFIG)
try:
with conn.cursor() as cur:
# Ensure output table exists
cur.execute(f"""
CREATE TABLE IF NOT EXISTS {DB_NAME}.{OUTPUT_TABLE} (
xsoa_id VARCHAR(256) NOT NULL,
principal VARCHAR(256) NOT NULL,
xsoa_org_principal VARCHAR(256) NOT NULL,
xsoa_team_name VARCHAR(256) NOT NULL,
xsoa_team_id VARCHAR(256) NOT NULL,
xsoa_center_name VARCHAR(256) NOT NULL,
xsoa_center_id VARCHAR(256) NOT NULL,
xsoa_dept_name VARCHAR(256) NOT NULL,
xsoa_dept_id VARCHAR(256) NOT NULL,
xsoa_principal_index BIGINT NOT NULL,
xsoa_dimension VARCHAR(256) NOT NULL,
ds BIGINT NOT NULL,
PRIMARY KEY (xsoa_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
""")
# Truncate + insert
cur.execute(f"TRUNCATE TABLE {DB_NAME}.{OUTPUT_TABLE}")
cur.execute(gt_sql)
conn.commit()
print("mysql_016 ground_truth done: 8 rows written to output table")
except Exception as e:
print(f"ground_truth error: {e}", file=sys.stderr)
conn.rollback()
sys.exit(1)
finally:
conn.close()
if __name__ == "__main__":
main()