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/db/diff/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func TestDiffDatabase(t *testing.T) {
// Check error
assert.Empty(t, diff)
assert.ErrorContains(t, err, `ERROR: schema "public" already exists (SQLSTATE 42P06)
At statement 0:
At statement: 0
create schema public`)
assert.Empty(t, apitest.ListUnmatchedRequests())
})
Expand Down
2 changes: 1 addition & 1 deletion internal/db/push/push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func TestMigrationPush(t *testing.T) {
err := Run(context.Background(), false, false, false, false, dbConfig, fsys, conn.Intercept)
// Check error
assert.ErrorContains(t, err, `ERROR: null value in column "version" of relation "schema_migrations" (SQLSTATE 23502)`)
assert.ErrorContains(t, err, "At statement 0:\n"+migration.INSERT_MIGRATION_VERSION)
assert.ErrorContains(t, err, "At statement: 0\n"+migration.INSERT_MIGRATION_VERSION)
})
}

Expand Down
8 changes: 7 additions & 1 deletion pkg/migration/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"crypto/sha256"
"encoding/hex"
"fmt"
"io"
"io/fs"
"path/filepath"
Expand Down Expand Up @@ -88,11 +89,16 @@ func (m *MigrationFile) ExecBatch(ctx context.Context, conn *pgx.Conn) error {
if i < len(m.Statements) {
stat = m.Statements[i]
}
var msg []string
var pgErr *pgconn.PgError
if errors.As(err, &pgErr) {
stat = markError(stat, int(pgErr.Position))
if len(pgErr.Detail) > 0 {
msg = append(msg, pgErr.Detail)
}
}
return errors.Errorf("%w\nAt statement %d:\n%s", err, i, stat)
msg = append(msg, fmt.Sprintf("At statement: %d", i), stat)
return errors.Errorf("%w\n%s", err, strings.Join(msg, "\n"))
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/migration/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ func TestMigrationFile(t *testing.T) {
err := migration.ExecBatch(context.Background(), conn.MockClient(t))
// Check error
assert.ErrorContains(t, err, "ERROR: schema \"public\" already exists (SQLSTATE 42P06)")
assert.ErrorContains(t, err, "At statement 0:\ncreate schema public")
assert.ErrorContains(t, err, "At statement: 0\ncreate schema public")
})
}
2 changes: 1 addition & 1 deletion pkg/migration/queries/drop.sql
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ begin
select *
from pg_publication p
where
p.pubname not like 'supabase_realtime%' and p.pubname not like 'realtime_messages%'
not p.pubname like any(array['supabase\_realtime%', 'realtime\_messages%'])
loop
execute format('drop publication if exists %I', rec.pubname);
end loop;
Expand Down