stripe / pg-schema-diff

Go library for diffing Postgres schemas and generating SQL migrations
MIT License
316 stars 23 forks source link

Fix column renames for indexes #147

Closed bplunkett-stripe closed 1 month ago

bplunkett-stripe commented 1 month ago

Description

Index columns effectively have two occurrences in pg_attribute, one is a "virtual column" created for the index and the other is the actual referenced column. For our purposes, we care about the latter, i.e., ensuring an index is deleted before its owning column is dropped, otherwise the index will be implicitly deleted (and not concurrently).

When a column is renamed, the virtual column name stays the same, but the underlying column name obviously changes. pg-schema-diff contained a bug where it referenced the virtual column name. Effectively, a column would be renamed but the column names in the fetched index would not change, leading to incorrectly generated dependencies.

I found this thread in the Postgres maling list to be very useful.

What I did:

Motivation

Bug fix

Testing

See added test case