Skip to content

Commit 5474044

Browse files
authored
fix: escape underscore in sql like syntax (#3586)
1 parent e59304e commit 5474044

File tree

5 files changed

+11
-5
lines changed

5 files changed

+11
-5
lines changed

internal/db/diff/diff_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ func TestDiffDatabase(t *testing.T) {
268268
// Check error
269269
assert.Empty(t, diff)
270270
assert.ErrorContains(t, err, `ERROR: schema "public" already exists (SQLSTATE 42P06)
271-
At statement 0:
271+
At statement: 0
272272
create schema public`)
273273
assert.Empty(t, apitest.ListUnmatchedRequests())
274274
})

internal/db/push/push_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func TestMigrationPush(t *testing.T) {
105105
err := Run(context.Background(), false, false, false, false, dbConfig, fsys, conn.Intercept)
106106
// Check error
107107
assert.ErrorContains(t, err, `ERROR: null value in column "version" of relation "schema_migrations" (SQLSTATE 23502)`)
108-
assert.ErrorContains(t, err, "At statement 0:\n"+migration.INSERT_MIGRATION_VERSION)
108+
assert.ErrorContains(t, err, "At statement: 0\n"+migration.INSERT_MIGRATION_VERSION)
109109
})
110110
}
111111

pkg/migration/file.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"crypto/sha256"
77
"encoding/hex"
8+
"fmt"
89
"io"
910
"io/fs"
1011
"path/filepath"
@@ -88,11 +89,16 @@ func (m *MigrationFile) ExecBatch(ctx context.Context, conn *pgx.Conn) error {
8889
if i < len(m.Statements) {
8990
stat = m.Statements[i]
9091
}
92+
var msg []string
9193
var pgErr *pgconn.PgError
9294
if errors.As(err, &pgErr) {
9395
stat = markError(stat, int(pgErr.Position))
96+
if len(pgErr.Detail) > 0 {
97+
msg = append(msg, pgErr.Detail)
98+
}
9499
}
95-
return errors.Errorf("%w\nAt statement %d:\n%s", err, i, stat)
100+
msg = append(msg, fmt.Sprintf("At statement: %d", i), stat)
101+
return errors.Errorf("%w\n%s", err, strings.Join(msg, "\n"))
96102
}
97103
return nil
98104
}

pkg/migration/file_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,6 @@ func TestMigrationFile(t *testing.T) {
7575
err := migration.ExecBatch(context.Background(), conn.MockClient(t))
7676
// Check error
7777
assert.ErrorContains(t, err, "ERROR: schema \"public\" already exists (SQLSTATE 42P06)")
78-
assert.ErrorContains(t, err, "At statement 0:\ncreate schema public")
78+
assert.ErrorContains(t, err, "At statement: 0\ncreate schema public")
7979
})
8080
}

pkg/migration/queries/drop.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ begin
103103
select *
104104
from pg_publication p
105105
where
106-
p.pubname not like 'supabase_realtime%' and p.pubname not like 'realtime_messages%'
106+
not p.pubname like any(array['supabase\_realtime%', 'realtime\_messages%'])
107107
loop
108108
execute format('drop publication if exists %I', rec.pubname);
109109
end loop;

0 commit comments

Comments
 (0)