Heroku missing last 4 migrations. Migration files do exist in Git - ruby-on-rails

Heroku is missing the last 4 migrations for a RoR app. The files exist in the git repository and are named/numbered accordingly. I tried manually forcing that version to run, but it simply can't find it. I tried this:
heroku run rake db:migrate:up VERSION=20190328183515
and the result was
ActiveRecord::UnknownMigrationVersionError: No migration with version number 20190328183515
Trying to redeploy from local to heroku stage does nothing since it states everything is up to date. I tried touching the files in case they weren't included in the deployed files, but looking at the git repository confirmed that's not the case.
Any ideas on what's going on here and how to get heroku to recognize that it is missing 4 migration files that still need to be processed? Resetting the database is not an option. I tried rolling back the database and running the migrations again but it stops on the migration file for 3/27/2019

Related

Rails Git Migration Issue With Branches

Still a newbie. I'm working on a new feature for a RoR app. I created a local branch and generated a migration. Unfortunately I didn't save my changes to the migration file and then ran db:migrate. Wanting to start over, I switched back to master and repulled from my git and did a hard reset with the following commands (I never committed the files in the branch either locally or remotely):
git fetch --all
git reset --hard origin/master
I then remade a local branch, recreated the migration (correctly this time) and ran db:migrate. I get an error that the table already exists in the database, however, when I look in schema.db the table isn't there.
All I want is to go back to where I was based on the remote git. For what it's worth, I'm using Cloud9 on AWS for development. Thanks!
There is nothing to do with database when you make changes regarding git. Once you run rake task like rake db:migrate to make database changes, it will get reverted automatically once you change branch, You have to prepare rollback steps. (As down methods in migrations are run conventionally)
Your old migration version was different than new recreated migration so application tried to run migration file without checking whether table exists.
Whenever you run rake db:migrate in for particular database, it store migration version in your schema_migrations table in db. So calling again and again same rake will not try to create table with same name. In above case you have different migration files to create same table and schema_migration table do not know whether you deleted branch with old migration file or whether table already exists
So run following in your rails console,
ActiveRecord::Migration.drop_table :table_name
And then run your rake db:migrate

Recovering app files on Heroku to their state prior to a wrong push

I have a hobby-dev rails app on Heroku. I dumped my database to seed.rb using "heroku run rake db:seed:dump". Then I pushed my local branch to Heroku, which replaced the seed.rb file. Then I did something terrible which deleted many things from my database.
Is there any way to recover the version of seed.rb file before I pushed my local branch? (Note that if I revert to the previous commit, the seed.rb file does not contain the dump data).
You should be able to go back to the previous release using the heroku rollback command.
See https://devcenter.heroku.com/articles/releases#rollback for details.

Multiple Migrations whit same Version Number on Deployng Rails to Heroku

Im have this problem many times, i search much and not found any solution to solve, my problem is this:
After the run
git push heroku push master
When i run
heroku run rake db:migrate
i get this error:
Multiple migrations have the version number 20130615132808
im search by this problem and found this:
rails database migration - multiple migrations have the version number x
but when execute git rm appear some options i dont understand much about git so i need solve this problem, in localhost im delete the archives but the problem persists, thanks very much by the help.
Just rename the files with duplicate timestamps (add 1 to the last digit) and then add, commit and push files. When you run heroku run rake db:migrate again all will be dandy.
And for the future remember to not copy and rename migrations by hand (so you don't get repeated version numbers)
This might occur when you copy-paste multiple "rails generate" commands to generate migrations. The migrations generated may have the same time stamp. If you type them in (or copy-paste them) separately, they will have different timestamps.
When this happens, you can simply rename the migration files under db/migrate to contain different timestamps.

rails database migration - multiple migrations have the version number x

Ok, I have stuffed up my migrations. I tried to sort it by deleting duplicates, sorting the schema.rb etc but I don't think I have done it properly.
When I try to deploy to heroku, or rather heroku run rake db:migrate, I get
Multiple migrations have the version number 20130307005437
The migrate works fine on localhost but not heroku.
Unfortunately when I look for migration no 20130307005437, it's not there in my db/migrate.
How can I find it to sort the problem?
While this file might not be visible within your directory listing, I suspect that there might already be a file within your Git repository, which is what is causing this error from appearing on Heroku and not locally.
Please ensure that you've only got one migration inside that Git repo with that number.

Should I keep all migrations since the dawn of time in my Heroku-pushing repo?

In the past (without Heroku), I've deleted my migration files once I've run them and don't expect to roll back. However, I've noticed that Heroku likes to run every migration every time I run
heroku run rake db:migrate
Is it going to get upset if I remove the files?

Resources