from pathlib import Path MIGRATION = ( Path(__file__).resolve().parents[2] / 'docs/sql/migrations/2026-10-11-market-sample-indexes.sql' ) EXPECTED = { 'idx_bps_market_sample_code': 'tenant_no,del_flag,sample_code', 'idx_bps_market_parent': 'tenant_no,del_flag,collection_protocol_id', 'idx_brds_market_sample_code': 'tenant_no,del_flag,sample_code', 'idx_brds_market_parent': 'tenant_no,del_flag,research_donation_id', 'idx_bsr_market_sample_progress': 'tenant_no,reception_source,sample_code,del_flag,reception_time', 'idx_bqwo_market_sample_progress': 'tenant_no,reception_source,trigger_source,sample_code,del_flag', 'idx_bsrr_market_sample_progress': 'tenant_no,reception_source,sample_code,del_flag,storage_time', 'idx_bpsc_market_parent': 'tenant_no,collection_protocol_id,del_flag', 'idx_bpft_market_parent': 'tenant_no,collection_protocol_id,del_flag', } def test_market_sample_migration_validates_exact_mysql57_index_definitions(): sql = MIGRATION.read_text(encoding='utf-8') assert 'information_schema.statistics' in sql.lower() assert 'PREPARE stmt' in sql assert 'non_unique' in sql.lower() assert 'sub_part' in sql.lower() assert 'index_type' in sql.lower() for index_name, columns in EXPECTED.items(): assert f"SET @index_name = '{index_name}'" in sql assert f"@index_columns = '{columns}'" in sql assert f'DROP INDEX {index_name}, ADD INDEX {index_name}' in sql def test_market_sample_migration_only_targets_required_tables(): sql = MIGRATION.read_text(encoding='utf-8') expected_tables = { 'biz_protocol_sample', 'biz_research_donation_sample', 'biz_sample_reception', 'biz_qc_work_order', 'biz_storage_release_review', 'biz_protocol_storage_cert', 'biz_protocol_fullmoon_todo', } actual_tables = { line.split("'")[1] for line in sql.splitlines() if line.startswith("SET @table_name = '") } assert actual_tables == expected_tables