test_market_sample_indexes_sql.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from pathlib import Path
  2. MIGRATION = (
  3. Path(__file__).resolve().parents[2]
  4. / 'docs/sql/migrations/2026-10-11-market-sample-indexes.sql'
  5. )
  6. EXPECTED = {
  7. 'idx_bps_market_sample_code': 'tenant_no,del_flag,sample_code',
  8. 'idx_bps_market_parent': 'tenant_no,del_flag,collection_protocol_id',
  9. 'idx_brds_market_sample_code': 'tenant_no,del_flag,sample_code',
  10. 'idx_brds_market_parent': 'tenant_no,del_flag,research_donation_id',
  11. 'idx_bsr_market_sample_progress': 'tenant_no,reception_source,sample_code,del_flag,reception_time',
  12. 'idx_bqwo_market_sample_progress': 'tenant_no,reception_source,trigger_source,sample_code,del_flag',
  13. 'idx_bsrr_market_sample_progress': 'tenant_no,reception_source,sample_code,del_flag,storage_time',
  14. 'idx_bpsc_market_parent': 'tenant_no,collection_protocol_id,del_flag',
  15. 'idx_bpft_market_parent': 'tenant_no,collection_protocol_id,del_flag',
  16. }
  17. def test_market_sample_migration_validates_exact_mysql57_index_definitions():
  18. sql = MIGRATION.read_text(encoding='utf-8')
  19. assert 'information_schema.statistics' in sql.lower()
  20. assert 'PREPARE stmt' in sql
  21. assert 'non_unique' in sql.lower()
  22. assert 'sub_part' in sql.lower()
  23. assert 'index_type' in sql.lower()
  24. for index_name, columns in EXPECTED.items():
  25. assert f"SET @index_name = '{index_name}'" in sql
  26. assert f"@index_columns = '{columns}'" in sql
  27. assert f'DROP INDEX {index_name}, ADD INDEX {index_name}' in sql
  28. def test_market_sample_migration_only_targets_required_tables():
  29. sql = MIGRATION.read_text(encoding='utf-8')
  30. expected_tables = {
  31. 'biz_protocol_sample',
  32. 'biz_research_donation_sample',
  33. 'biz_sample_reception',
  34. 'biz_qc_work_order',
  35. 'biz_storage_release_review',
  36. 'biz_protocol_storage_cert',
  37. 'biz_protocol_fullmoon_todo',
  38. }
  39. actual_tables = {
  40. line.split("'")[1]
  41. for line in sql.splitlines()
  42. if line.startswith("SET @table_name = '")
  43. }
  44. assert actual_tables == expected_tables