Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/migration/repair/repair.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func UpdateMigrationTable(ctx context.Context, conn *pgx.Conn, version []string,
if err != nil {
return err
}
batch.Queue(migration.INSERT_MIGRATION_VERSION, f.Version, f.Name, f.Statements)
batch.Queue(migration.UPSERT_MIGRATION_VERSION, f.Version, f.Name, f.Statements)
}
case Reverted:
if !repairAll {
Expand Down
10 changes: 7 additions & 3 deletions internal/migration/repair/repair_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"os"
"path/filepath"
"strings"
"testing"

"github.com/jackc/pgconn"
Expand Down Expand Up @@ -37,7 +38,7 @@ func TestRepairCommand(t *testing.T) {
conn := pgtest.NewConn()
defer conn.Close(t)
helper.MockMigrationHistory(conn).
Query(migration.INSERT_MIGRATION_VERSION, "0", "test", []string{"select 1"}).
Query(migration.UPSERT_MIGRATION_VERSION, "0", "test", []string{"select 1"}).
Reply("INSERT 0 1")
// Run test
err := Run(context.Background(), dbConfig, []string{"0"}, Applied, fsys, conn.Intercept)
Expand Down Expand Up @@ -87,7 +88,7 @@ func TestRepairCommand(t *testing.T) {
conn := pgtest.NewConn()
defer conn.Close(t)
helper.MockMigrationHistory(conn).
Query(migration.INSERT_MIGRATION_VERSION, "0", "test", nil).
Query(migration.UPSERT_MIGRATION_VERSION, "0", "test", nil).
ReplyError(pgerrcode.DuplicateObject, `relation "supabase_migrations.schema_migrations" does not exist`)
// Run test
err := Run(context.Background(), dbConfig, []string{"0"}, Applied, fsys, conn.Intercept)
Expand All @@ -107,7 +108,10 @@ func TestRepairAll(t *testing.T) {
conn := pgtest.NewConn()
defer conn.Close(t)
helper.MockMigrationHistory(conn).
Query(migration.TRUNCATE_VERSION_TABLE + `;INSERT INTO supabase_migrations.schema_migrations(version, name, statements) VALUES( '0' , 'test' , '{select 1}' )`).
Query(strings.Join([]string{
migration.TRUNCATE_VERSION_TABLE,
strings.ReplaceAll(migration.UPSERT_MIGRATION_VERSION, "$1, $2, $3", " '0' , 'test' , '{select 1}' "),
}, ";")).
Reply("TRUNCATE TABLE").
Reply("INSERT 0 1")
// Run test
Expand Down
1 change: 1 addition & 0 deletions pkg/migration/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (
ADD_STATEMENTS_COLUMN = "ALTER TABLE supabase_migrations.schema_migrations ADD COLUMN IF NOT EXISTS statements text[]"
ADD_NAME_COLUMN = "ALTER TABLE supabase_migrations.schema_migrations ADD COLUMN IF NOT EXISTS name text"
INSERT_MIGRATION_VERSION = "INSERT INTO supabase_migrations.schema_migrations(version, name, statements) VALUES($1, $2, $3)"
UPSERT_MIGRATION_VERSION = INSERT_MIGRATION_VERSION + " ON CONFLICT (version) DO UPDATE SET name = EXCLUDED.name, statements = EXCLUDED.statements"
DELETE_MIGRATION_VERSION = "DELETE FROM supabase_migrations.schema_migrations WHERE version = ANY($1)"
DELETE_MIGRATION_BEFORE = "DELETE FROM supabase_migrations.schema_migrations WHERE version <= $1"
TRUNCATE_VERSION_TABLE = "TRUNCATE supabase_migrations.schema_migrations"
Expand Down