am-freescan/scripts/apply_fixture_trajectory.py
lixiaolong ba0f749d40 feat: 完善检测任务、夹具轨迹与设备工作流
完善扫描成果与比对资料管理,精简业务菜单和任务工作台,更新批量导入模板。

适配机械臂新协议、坐标系管理及目标位姿组件,增加扫描参数字典和角色自动分配。

修复试运行终止状态与过期扫描任务资源释放,补充回归测试、迁移脚本及接口文档。
2026-11-06 10:50:49 +08:00

27 lines
1.8 KiB
Python

"""Create the additive fixture association table in the designated dev database only."""
from pathlib import Path
import json,sys
ROOT=Path(__file__).resolve().parents[1]
sys.path.insert(0,str(ROOT/'scripts'))
from bootstrap_db import validate_target
def apply():
import pymysql
runtime=json.loads((ROOT/'.local/runtime.json').read_text(encoding='utf-8-sig'))['mysql'];validate_target(runtime)
sql=(ROOT/'am-backend/sql/freescan/015_fixture_trajectory.sql').read_text(encoding='utf-8')
statements=['\n'.join(line for line in part.splitlines() if not line.lstrip().startswith('--')).strip() for part in sql.split(';')]
if any(not s.upper().startswith('CREATE TABLE IF NOT EXISTS LAB_FIXTURE_TRAJECTORY ') for s in statements if s):raise ValueError('Unexpected migration')
db=pymysql.connect(host=runtime['host'],port=int(runtime.get('port',3306)),user=runtime['user'],password=runtime['password'],database=runtime['database'],charset='utf8mb4',autocommit=True)
with db.cursor() as cursor:
cursor.execute('SELECT DATABASE()');assert cursor.fetchone()[0]=='am-freescan'
before={}
for table in ['lab_fixture','lab_fixture_framework','lab_test_task','lab_execution','lab_resource_occupation']:
cursor.execute('SELECT COUNT(*) FROM `'+table+'`');before[table]=cursor.fetchone()[0]
for statement in statements:
if statement:cursor.execute(statement)
for table,count in before.items():
cursor.execute('SELECT COUNT(*) FROM `'+table+'`');assert cursor.fetchone()[0]==count,table
cursor.execute('SELECT COUNT(*) FROM lab_fixture_trajectory');associations=cursor.fetchone()[0]
(ROOT/'.local/fixture-trajectory-migration.json').write_text(json.dumps({'baselineCounts':before,'associationRows':associations,'customerCountsPreserved':True},indent=2),encoding='utf-8')
db.close();print('Fixture trajectory table ready; existing rows preserved.')
if __name__=='__main__':apply()