schema out of xaction

main
bel 2025-05-04 10:56:57 -06:00
parent 0399fc9316
commit 31f7facac7
1 changed files with 2 additions and 4 deletions

View File

@ -3,7 +3,6 @@ package db
import (
"context"
"fmt"
"strings"
"time"
)
@ -28,11 +27,10 @@ func InitializeSchema(ctx context.Context, k string, mods []string) error {
mods = append([]string{""}, mods...)
for i := v.V + 1; i < len(mods); i++ {
q := mods[i]
q = strings.TrimSpace(q)
q = strings.TrimSuffix(q, ";")
q = fmt.Sprintf(`BEGIN; %s; INSERT INTO "database_version.%s" (v, t) VALUES (?, ?); COMMIT;`, q, k)
if err := Exec(ctx, q, i, time.Now()); err != nil {
return fmt.Errorf("[%s][%d] failed mod %s: %w", k, i, mods[i], err)
} else if err := Exec(ctx, fmt.Sprintf(`INSERT INTO "database_version.%s" (v, t) VALUES (?, ?)`, k), i, time.Now()); err != nil {
return fmt.Errorf("[%s][%d] failed ack mod %s: %w", k, i, mods[i], err)
}
}