stripe / pg-schema-diff

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

Cleanup Orphaned Temporary Databases #41

Open bplunkett-stripe opened 1 year ago

bplunkett-stripe commented 1 year ago

If a migration is canceled, temporary databases will be orphaned. This problem should be pretty rare.

Temp db factories should clean up (some) orphaned databases each time they create a new database. This will ensure that # of orphaned temporary databases inevitably reaches 0.

Cleanup safety checks:

  1. Make sure temp database matches expected name
  2. Make sure metadata table is present
  3. Attempt to validate the database contains no data

Additional thought: It might be worth splitting the context in the temp database cleanup code and giving it a strict timeout to reduce the likelihood a temporary database becomes orphaned.