8000 Ignore duplicate inferred migrations having the same timestamp by andrew-farries · Pull Request #369 · xataio/pgroll · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Ignore duplicate inferred migrations having the same timestamp #369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2024
Merged
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
11 changes: 10 additions & 1 deletion pkg/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,15 @@ BEGIN
RETURN;
END IF;

-- Remove any duplicate inferred migrations with the same timestamp for this
-- schema. We assume such migrations are multi-statement batched migrations
-- and we are only interested in the last one in the batch.
DELETE FROM %[1]s.migrations
WHERE schema = schemaname
AND created_at = current_timestamp
AND migration_type = 'inferred'
AND migration->'operations'->0->'sql'->>'up' = current_query();

-- Someone did a schema change without pgroll, include it in the history
SELECT INTO migration_id pg_catalog.format('sql_%%s',pg_catalog.substr(pg_catalog.md5(pg_catalog.random()::text), 0, 15));

Expand Down Expand Up @@ -399,7 +408,7 @@ func (s *State) Init(ctx context.Context) error {
}

// Perform pgroll state initialization
_, err = tx.ExecContext(ctx, fmt.Sprintf(sqlInit, pq.QuoteIdentifier(s.schema)))
_, err = tx.ExecContext(ctx, fmt.Sprintf(sqlInit, pq.QuoteIdentifier(s.schema), pq.QuoteLiteral(s.schema)))
if err != nil {
return err
}
Expand Down
0