Skip to content

Commit 5cd7538

Browse files
committed
Patch Translation_Tests expectations to match EXISTS rewrite
The EXISTS rewrite of sync_column_key_info (needed because Turso doesn't implement SQLite's "bare column alongside aggregate" extension) changes the emitted SQL string. Six Translation_Tests assert on the old row-value SET form and now fail on string mismatch even though driver behavior is correct. Replace expected strings in the test file at CI time via python regex. Safe because behavior is unchanged; the tests check implementation detail (exact SQL text) which intentionally diverges under Turso.
1 parent f4dee46 commit 5cd7538

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

.github/workflows/phpunit-tests-turso.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,67 @@ jobs:
10721072
assert old in src, 'CHECK TABLE handler not found'
10731073
open(path, 'w').write(src.replace(old, new, 1))
10741074
print('patched CHECK TABLE missing-table check')
1075+
1076+
# 11. 6 Translation_Tests assert on the exact SQL emitted by
1077+
# sync_column_key_info. Our EXISTS rewrite (needed because
1078+
# Turso doesn't implement SQLite's "bare column alongside
1079+
# aggregate" extension) changes the emitted string, so the
1080+
# assertions fail even though behavior is correct. Update the
1081+
# expected strings in the test file to match the EXISTS form.
1082+
import re
1083+
path = 'tests/WP_SQLite_Driver_Translation_Tests.php'
1084+
src = open(path).read()
1085+
old_pattern = re.compile(
1086+
r"UPDATE `_wp_sqlite_mysql_information_schema_columns` AS c "
1087+
r"SET \(column_key, is_nullable\) = \( SELECT "
1088+
r"CASE WHEN MAX\(s\.index_name = 'PRIMARY'\) THEN 'PRI' "
1089+
r"WHEN MAX\(s\.non_unique = 0 AND s\.seq_in_index = 1\) THEN 'UNI' "
1090+
r"WHEN MAX\(s\.seq_in_index = 1\) THEN 'MUL' ELSE '' END, "
1091+
r"CASE WHEN MAX\(s\.index_name = 'PRIMARY'\) THEN 'NO' "
1092+
r"ELSE c\.is_nullable END "
1093+
r"FROM `_wp_sqlite_mysql_information_schema_statistics` AS s "
1094+
r"WHERE s\.table_schema = c\.table_schema "
1095+
r"AND s\.table_name = c\.table_name "
1096+
r"AND s\.column_name = c\.column_name \) "
1097+
r"WHERE c\.table_schema = 'sqlite_database' "
1098+
r"AND c\.table_name = '(?P<tbl>[^']+)'"
1099+
)
1100+
def build_new(m):
1101+
tbl = m.group('tbl')
1102+
return (
1103+
"UPDATE `_wp_sqlite_mysql_information_schema_columns` AS c "
1104+
"SET column_key = CASE "
1105+
"WHEN EXISTS ( SELECT 1 FROM `_wp_sqlite_mysql_information_schema_statistics` AS s "
1106+
"WHERE s.table_schema = c.table_schema "
1107+
"AND s.table_name = c.table_name "
1108+
"AND s.column_name = c.column_name "
1109+
"AND s.index_name = 'PRIMARY' ) THEN 'PRI' "
1110+
"WHEN EXISTS ( SELECT 1 FROM `_wp_sqlite_mysql_information_schema_statistics` AS s "
1111+
"WHERE s.table_schema = c.table_schema "
1112+
"AND s.table_name = c.table_name "
1113+
"AND s.column_name = c.column_name "
1114+
"AND s.non_unique = 0 "
1115+
"AND s.seq_in_index = 1 ) THEN 'UNI' "
1116+
"WHEN EXISTS ( SELECT 1 FROM `_wp_sqlite_mysql_information_schema_statistics` AS s "
1117+
"WHERE s.table_schema = c.table_schema "
1118+
"AND s.table_name = c.table_name "
1119+
"AND s.column_name = c.column_name "
1120+
"AND s.seq_in_index = 1 ) THEN 'MUL' "
1121+
"ELSE '' END, "
1122+
"is_nullable = CASE "
1123+
"WHEN EXISTS ( SELECT 1 FROM `_wp_sqlite_mysql_information_schema_statistics` AS s "
1124+
"WHERE s.table_schema = c.table_schema "
1125+
"AND s.table_name = c.table_name "
1126+
"AND s.column_name = c.column_name "
1127+
"AND s.index_name = 'PRIMARY' ) THEN 'NO' "
1128+
"ELSE c.is_nullable END "
1129+
f"WHERE c.table_schema = 'sqlite_database' "
1130+
f"AND c.table_name = '{tbl}'"
1131+
)
1132+
new_src, n = old_pattern.subn(build_new, src)
1133+
assert n > 0, 'no Translation_Tests UPDATE expectations matched'
1134+
open(path, 'w').write(new_src)
1135+
print(f'patched {n} Translation_Tests UPDATE expectations to EXISTS form')
10751136
PY
10761137
10771138
- name: Run PHPUnit tests against Turso DB

0 commit comments

Comments
 (0)