Summary: _split_statements() splits SQL on ; before stripping -- line comments, so a semicolon inside a -- comment breaks the statement mid-way. Severity: high (migrations fail unpredictably; the trigger is invisible — a ; in a comment).
Version: tina4-python 3.13.37.
Where
tina4_python/migration/runner.py::_split_statements() (~lines 301–347). It saves $$…$$///…// blocks as placeholders and strips /* */, then:
clean = re.sub(r"/\*.*?\*/", "", processed, flags=re.DOTALL)
...
for stmt in clean.split(delimiter): # <-- splits on ';' FIRST (~line 328)
for line in stmt.split("\n"): # <-- only NOW removes '--' comments, too late
stripped = line.strip()
if stripped and not stripped.startswith("--"):
...
By the time -- comments are handled per-line, the ; inside a comment has already split the statement into broken fragments.
Repro / regression test
from tina4_python.migration.runner import _split_statements
sql = "CREATE TABLE x (id int)\n-- note: drop; then re-add\n;\nSELECT 1;"
stmts = [s for s in _split_statements(sql) if s.strip()]
assert len(stmts) == 2, f"semicolon in -- comment broke the split: {stmts!r}"
Today returns 3+ fragments (split at the ; inside the comment); 2 after the fix.
Suggested fix
Strip ---to-EOL comments before splitting (the $$/// blocks are already placeholders, so this won't touch them):
clean = re.sub(r"/\*.*?\*/", "", processed, flags=re.DOTALL)
clean = re.sub(r"--[^\n]*", "", clean) # NEW: strip line comments first
for stmt in clean.split(delimiter): # then split on ';'
... # (the now-redundant per-line '--' handling can go)
Summary:
_split_statements()splits SQL on;before stripping--line comments, so a semicolon inside a--comment breaks the statement mid-way. Severity: high (migrations fail unpredictably; the trigger is invisible — a;in a comment).Version: tina4-python 3.13.37.
Where
tina4_python/migration/runner.py::_split_statements()(~lines 301–347). It saves$$…$$///…//blocks as placeholders and strips/* */, then:By the time
--comments are handled per-line, the;inside a comment has already split the statement into broken fragments.Repro / regression test
Today returns 3+ fragments (split at the
;inside the comment); 2 after the fix.Suggested fix
Strip
---to-EOL comments before splitting (the$$///blocks are already placeholders, so this won't touch them):