Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 

31 рядки
2.3 KiB

  1. """Verify and apply the one workflow status constraint; no business data is rewritten."""
  2. import runpy, json, hashlib, datetime
  3. from pathlib import Path
  4. import sqlparse
  5. support=runpy.run_path(str(Path(__file__).with_name('review-db.py')))
  6. source=Path(__file__).resolve().parents[2]/'unreal_tran_api/database/20260912_040_teaching_workflow_steps.sql'
  7. report=Path(__file__).resolve().parents[1]/'reports/virtual-html-full-closure-20260912/migration.json'
  8. report.parent.mkdir(parents=True,exist_ok=True)
  9. connection=support['connect']()
  10. with connection.cursor() as cursor:
  11. cursor.execute("SELECT pg_get_constraintdef(oid) AS definition FROM pg_constraint WHERE conname='ck_ut_teaching_step_run_status' AND conrelid='public.ut_teaching_step_run'::regclass")
  12. before=cursor.fetchone()
  13. cursor.execute('SHOW server_encoding')
  14. encoding=cursor.fetchone()
  15. # Temporary shadow table verifies syntax, first execution and repeat without touching public data.
  16. cursor.execute('CREATE TEMP TABLE ut_teaching_step_run (status_code varchar(32))')
  17. for attempt in range(2):
  18. for statement in sqlparse.split(source.read_text(encoding='utf-8')):cursor.execute(statement)
  19. cursor.execute("INSERT INTO pg_temp.ut_teaching_step_run VALUES ('SKIPPED')")
  20. cursor.execute('DROP TABLE pg_temp.ut_teaching_step_run')
  21. report.write_text(json.dumps({'file':source.name,'sha256':hashlib.sha256(source.read_bytes()).hexdigest(),'target':'unreal_tran/public','encoding':encoding,'before':before,'temporaryFirstAndRepeat':True,'stage':'before-public-apply'},ensure_ascii=False,indent=2),encoding='utf-8')
  22. for attempt in range(2):
  23. for statement in sqlparse.split(source.read_text(encoding='utf-8')):cursor.execute(statement)
  24. cursor.execute("SELECT pg_get_constraintdef(oid) AS definition FROM pg_constraint WHERE conname='ck_ut_teaching_step_run_status' AND conrelid='public.ut_teaching_step_run'::regclass")
  25. after=cursor.fetchone();assert 'SKIPPED' in after['definition']
  26. data=json.loads(report.read_text(encoding='utf-8'));data.update(after=after,stage='verified',time=datetime.datetime.now().astimezone().isoformat())
  27. report.write_text(json.dumps(data,ensure_ascii=False,indent=2),encoding='utf-8')
  28. connection.close()
  29. print('PASS temporary migration, repeat, public migration and constraint verification')