fix(db,topics): time.Time params for TIMESTAMP + comment-aware SQL split
Two fixes surfaced by sim e2e test (which otherwise passed full
lifecycle: created → signup_open → 3 signups → allocator → debating
→ arguments → verdict gate (409 early, 201 after debate_end_at) →
completed).
1) MySQL TIMESTAMP rejects RFC3339-with-Z strings — passing those as
sqlx parameters fails with "Incorrect datetime value". Changed
CreateTopicInput lifecycle fields from string to time.Time; the
handler parses+UTCs in validateLifecycleTimes (which now returns
the parsed array along with the validation result) and passes
time.Time to the store. The mysql driver formats correctly.
2) splitSQL was naive `strings.Split(s, ";")` which split inside
comments — the 001 migration had a few `--` lines containing `;`
("signup_close_at; immutable", etc) which broke. Migration text
tidied to not use `;` inside comments, AND splitSQL upgraded to
skip both `-- ...` and `/* ... */` comment regions before splitting.
Sim verified — clean apply on fresh MySQL.
This commit is contained in:
@@ -105,10 +105,33 @@ func RunMigrations(ctx context.Context, d *sqlx.DB) error {
|
||||
}
|
||||
|
||||
func splitSQL(s string) []string {
|
||||
// Crude but adequate for our migrations (no string-literal semicolons).
|
||||
// If we ever need to embed semicolons inside strings, switch to a
|
||||
// proper SQL tokenizer.
|
||||
return strings.Split(s, ";")
|
||||
// Comment-aware splitter: skip `;` inside `-- ...` line comments
|
||||
// and `/* ... */` block comments. Doesn't handle string-literal
|
||||
// semicolons (we don't put any) — if we ever need that, swap in a
|
||||
// real SQL tokenizer.
|
||||
var b strings.Builder
|
||||
i := 0
|
||||
for i < len(s) {
|
||||
if i+1 < len(s) && s[i] == '-' && s[i+1] == '-' {
|
||||
// single-line comment — strip through end of line
|
||||
for i < len(s) && s[i] != '\n' {
|
||||
i++
|
||||
}
|
||||
continue
|
||||
}
|
||||
if i+1 < len(s) && s[i] == '/' && s[i+1] == '*' {
|
||||
// block comment — strip through `*/`
|
||||
i += 2
|
||||
for i+1 < len(s) && !(s[i] == '*' && s[i+1] == '/') {
|
||||
i++
|
||||
}
|
||||
i += 2
|
||||
continue
|
||||
}
|
||||
b.WriteByte(s[i])
|
||||
i++
|
||||
}
|
||||
return strings.Split(b.String(), ";")
|
||||
}
|
||||
|
||||
func firstLine(s string) string {
|
||||
|
||||
Reference in New Issue
Block a user