Skip to content

Commit

Permalink
Use RenameDuplicatedColumn in set not null op
Browse files Browse the repository at this point in the history
This ensures that any FK constraints on the duplicated column get
renamed back to their original names.
  • Loading branch information
andrew-farries committed Jan 15, 2024
1 parent 1346ef6 commit 12238cd
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions pkg/migrations/op_set_notnull.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,9 @@ func (o *OpSetNotNull) Complete(ctx context.Context, conn *sql.DB, s *schema.Sch
}

// Rename the new column to the old column name
_, err = conn.ExecContext(ctx, fmt.Sprintf("ALTER TABLE IF EXISTS %s RENAME COLUMN %s TO %s",
pq.QuoteIdentifier(o.Table),
pq.QuoteIdentifier(TemporaryName(o.Column)),
pq.QuoteIdentifier(o.Column)))
if err != nil {
table := s.GetTable(o.Table)
column := table.GetColumn(o.Column)
if err := RenameDuplicatedColumn(ctx, conn, table, column); err != nil {
return err
}

Expand Down

0 comments on commit 12238cd

Please sign in to comment.