Skip to content

Commit

Permalink
Stop giving FKs temporary names on creation
Browse files Browse the repository at this point in the history
There is no need to create FK constraints with a temporary name prefix -
they only need to be validated on migration completion, not renamed.
  • Loading branch information
andrew-farries committed Jan 18, 2024
1 parent d915966 commit 1c8503a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/migrations/op_set_fk.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (o *OpSetForeignKey) Complete(ctx context.Context, conn *sql.DB, s *schema.
// Validate the foreign key constraint
_, err := conn.ExecContext(ctx, fmt.Sprintf("ALTER TABLE IF EXISTS %s VALIDATE CONSTRAINT %s",
pq.QuoteIdentifier(o.Table),
pq.QuoteIdentifier(TemporaryName(o.References.Name))))
pq.QuoteIdentifier(o.References.Name)))
if err != nil {
return err
}
Expand Down Expand Up @@ -173,7 +173,7 @@ func (o *OpSetForeignKey) addForeignKeyConstraint(ctx context.Context, conn *sql

_, err := conn.ExecContext(ctx, fmt.Sprintf("ALTER TABLE %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s) NOT VALID",
pq.QuoteIdentifier(o.Table),
pq.QuoteIdentifier(TemporaryName(o.References.Name)),
pq.QuoteIdentifier(o.References.Name),
pq.QuoteIdentifier(tempColumnName),
pq.QuoteIdentifier(o.References.Table),
pq.QuoteIdentifier(o.References.Column),
Expand Down

0 comments on commit 1c8503a

Please sign in to comment.