feat: establish Go service and database foundation
This commit is contained in:
23
internal/database/migrate.go
Normal file
23
internal/database/migrate.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
)
|
||||
|
||||
// Migrate applies the idempotent local MVP schema. Production migration tooling
|
||||
// can execute the same reviewed SQL from migrations/.
|
||||
func Migrate(ctx context.Context, pool *pgxpool.Pool, migration string) error {
|
||||
for statement := range strings.SplitSeq(migration, "-- statement-break") {
|
||||
if strings.TrimSpace(statement) == "" {
|
||||
continue
|
||||
}
|
||||
if _, err := pool.Exec(ctx, statement); err != nil {
|
||||
return fmt.Errorf("applying migration: %w", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user