My migration files for my Rails Heroku-hosted project had gotten very messy, so I wanted to consolidate them. I figured I could:
do a Heroku database backup with
heroku pg:backups:capture --app appname
,add a new migration file dropping all my tables and run it on development and production,
delete all my migration files and add new, neater migration files with all the information in my old schema.rb, and run them on development and production, and then
restore my Heroku database with
heroku pg:backups:restore b001 DATABASE_URL --app appname
.
This is exactly what I did. I assumed a database restore would simply populate my current database with the records in the backed up database. However, what actually happens is that it replaces the entire current database with the old one. This is a problem because my existing migration files are now all viewed as new, and they can't be run because the tables they are meant to create already exist. This means I can't add any new migrations, because the existing ones can't be run. I could just delete all my existing migration files, but that seems like extremely bad practice.
Is the situation salvagable? Ideally I'd just run my migrations and populate the database with the records from my backed up database - is that possible?