PlaceAVote / pav-api

This repository contains the Placeavote API.
0 stars 0 forks source link

Add rollback support in migrations #52

Open sanel opened 8 years ago

sanel commented 8 years ago

Flyway does not support rollbacks of failed migrations, but AWS gives API for triggering DB snapshots (http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_CreateSnapshot.html).

With proper env variable (so it can be run on Convox only), this could be called before each migration (if detected that migration will actually be run).

sanel commented 8 years ago

More API details: http://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBSnapshot.html

johnboy14 commented 8 years ago

At what point would we use this API though?. Would we use it every time we deploy the server or only on occasions when we know we need to do a migration. Its an Asynchronous API so I say its best to do it before we deploy any migrations.

sanel commented 8 years ago

It make sense to use it only when Flyway detect actual schema changes. There is a method called DescribeDBSnapshots that returns status of current snapshots and we can extract value of Status field. From what I can see, snapshot in working will have creating value...

Its an Asynchronous API so I say its best to do it before we deploy any migrations.

If you think about manual, explicit operation, I'd go with it as last resort. It is easy to forget when one of us update schema and remember to invoke migration on deploy phase (taking into account testing, this can take day/two/three).

I envision this scenario: let the app try to create snapshot, run migration, if migration fails, try to restore snapshot. If that fails, just report with big red text that something went bad. However, this needs to have one significant addon, no matter if we run migration manually or automatically: pav-api should go to 'maintenance' phase during migration, to prevent accidental data writing that could damage db integrity.