✨ feat: add auto table creation and per-PK sync verification
- Add new Access table mappings for transmitter contracts (25/26年变送器) and tube bending workshop (弯管车间烘洗) - Add auto-create target table from Access schema when table does not exist (db_utils + init_full_sync) - Implement per-primary-key verification in incremental sync: verify deletes are gone and inserts are present before marking Synced=1 - Add post-commit re-verification with Synced rollback on failure for automatic retry - Batch IN clause parameters to stay under SQL Server limit - Adjust poll interval from 5s to 30s - Improve IDENTITY_INSERT cleanup in finally blocks Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -140,9 +140,18 @@ def run_full_sync():
|
||||
log_info( f" 检测到 {len(columns)} 个列")
|
||||
insert_sql = db_utils.generate_insert_sql(target_schema, target_table, columns)
|
||||
|
||||
# 3. TRUNCATE 目标表
|
||||
sql_cursor.execute(f"TRUNCATE TABLE {full_target_name}")
|
||||
log_info( f" 已清空目标表")
|
||||
# 3. 检查目标表是否存在,不存在则自动创建
|
||||
if not db_utils.table_exists(sql_cursor, target_schema, target_table):
|
||||
db_utils.ensure_schema(sql_cursor, target_schema)
|
||||
db_utils.create_table_from_access(
|
||||
sql_cursor, target_schema, target_table,
|
||||
acc_cursor.description, target_config['pk_col']
|
||||
)
|
||||
sql_conn.commit() # DDL 必须单独提交,否则 pyodbc 参数绑定无法获取正确的列元数据
|
||||
log_info( f" 目标表不存在,已自动创建")
|
||||
else:
|
||||
sql_cursor.execute(f"TRUNCATE TABLE {full_target_name}")
|
||||
log_info( f" 已清空目标表")
|
||||
|
||||
# 4. 检查并启用 IDENTITY_INSERT
|
||||
has_identity = has_identity_column(sql_cursor, target_schema, target_table)
|
||||
|
||||
Reference in New Issue
Block a user