stripe / pg-schema-diff

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

Add unique constraint support #74

Closed bplunkett-stripe closed 9 months ago

bplunkett-stripe commented 9 months ago

Description

Add unique constraint support

Motivation

Closes #72

Testing

Tested with unit tests

bplunkett-stripe commented 9 months ago

Looks amazing!

thought: I wonder if we should have a hazard for operations like adding a unique constraint where adding the constraint can fail because of duplicate rows. I guess not since there's nothing functionally wrong with that outcome, and the UX wouldn't be great?

I think that's an interesting idea! Hypothetically, if building a unique index fails, the database could be left in a somewhat dirty state. I think it's a bit of scope of this PR, but we might want to start thinking about overhauling the migration hazards a bit. Identifying:

It might also be interesting if schema migration hazards include some list of "id" targets, such as for deletes