diff --git a/internal/db/diff/diff_test.go b/internal/db/diff/diff_test.go index 71b03223e2..498c88da1b 100644 --- a/internal/db/diff/diff_test.go +++ b/internal/db/diff/diff_test.go @@ -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()) }) diff --git a/internal/db/push/push_test.go b/internal/db/push/push_test.go index f25ba2090f..9bc1baf582 100644 --- a/internal/db/push/push_test.go +++ b/internal/db/push/push_test.go @@ -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) }) } diff --git a/pkg/migration/file.go b/pkg/migration/file.go index 8dd254326e..fbd4a3b7fd 100644 --- a/pkg/migration/file.go +++ b/pkg/migration/file.go @@ -5,6 +5,7 @@ import ( "context" "crypto/sha256" "encoding/hex" + "fmt" "io" "io/fs" "path/filepath" @@ -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 } diff --git a/pkg/migration/file_test.go b/pkg/migration/file_test.go index 15bd5c7511..45bee71b65 100644 --- a/pkg/migration/file_test.go +++ b/pkg/migration/file_test.go @@ -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") }) } diff --git a/pkg/migration/queries/drop.sql b/pkg/migration/queries/drop.sql index 4aacc641dc..ff2f1b22b8 100644 --- a/pkg/migration/queries/drop.sql +++ b/pkg/migration/queries/drop.sql @@ -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;