Skip to content

Commit eda215c

Browse files
authored
fix: Call list tables once on insert if --no-migrate was used (#13327)
#### Summary Follow up to #13323 to handle `--no-migrate`. Thanks @candiduslynx for pointing it out <!--
1 parent eab200d commit eda215c

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

plugins/destination/postgresql/client/client.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ const (
4343

4444
func New(ctx context.Context, logger zerolog.Logger, specBytes []byte, opts plugin.NewClientOptions) (plugin.Client, error) {
4545
c := &Client{
46-
logger: logger.With().Str("module", "pg-dest").Logger(),
47-
pgTablesToPKConstraints: make(map[string]string),
46+
logger: logger.With().Str("module", "pg-dest").Logger(),
4847
}
4948
if opts.NoConnection {
5049
return c, nil

plugins/destination/postgresql/client/insert.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ func (c *Client) InsertBatch(ctx context.Context, messages message.WriteInserts)
2020
return err
2121
}
2222

23+
// This happens when the CLI was invoked with `sync --no-migrate`
24+
if c.pgTablesToPKConstraints == nil {
25+
// Passing nil for include and exclude lists all tables and populates c.pgTablesToPKConstraints
26+
_, err := c.listTables(ctx, nil, nil)
27+
if err != nil {
28+
return err
29+
}
30+
}
31+
2332
tables = c.normalizeTables(tables)
2433
if err != nil {
2534
return err

plugins/destination/postgresql/client/list_tables.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ ORDER BY
6363
`
6464

6565
func (c *Client) listTables(ctx context.Context, include, exclude []string) (schema.Tables, error) {
66+
c.pgTablesToPKConstraints = map[string]string{}
6667
var tables schema.Tables
6768
whereClause := c.whereClause(include, exclude)
6869
if c.pgType == pgTypeCockroachDB {

0 commit comments

Comments
 (0)