rails db migrate locally-Multiple migrations have the version number - ruby-on-rails

I'm using docker, and I'm trying to run migrations locally using
docker-compose run app rails db:migrate
I'm getting an error though:
Multiple migrations have the version number 20211230114441.
I tried searching for this migration in db/migrate but nothing's there. I also tried checking out different versions of schema.rb but this fixed nothing.
Since I'm running using docker, and even though, my files are attached to a volume, I tried using docker-compose build before running again to make sure that the migration files are udpated. Again fixed nothing.
Any ideas on how this can be fixed?

Related

Heroku missing last 4 migrations. Migration files do exist in Git

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

issues with schema.rb file during rails 5 upgrade

After upgrading to Rails 5, I receive an error message like following every time I try to load from schema (set up a new computer on the app, run rails db:test:prepare before running tests, etc.):
ActiveRecord::StatementInvalid: PG::UndefinedObject: ERROR: type "serial" does not exist
LINE 1: SELECT 'serial'::regtype::oid
Searching around isn't yielding much help. The most relevant thread is this one: https://github.com/rails/rails/issues/30298 but I am not trying to run any new migrations, nor does the schema_plus_indexes gem seem to have anything to do with the issue (the two issues described in that thread).
In our case, we don't keep migration files around after they have been run against all databases. Because of this, when working on the upgrade to rails 5, there were 0 migration files present. The issue, it seems, is that rails will only automatically "fix" your schema.rb file for you if you are actually running a migration file (even trying rails db:migrate with no migration files present won't work).
The solution, for us, was to create a blank migration and run rails db:migrate in order to get the schema.rb file properly formatted.

removing postgres database on ubuntu from commandline

I am working on a rails app. Due to some messing up with the code I deleted the app from my local development machine and cloned the previous commit from the git repo.
Now i want to delete the db file(postgres) of the deleted one from the local machine as well. I had issues in the past that made me unable to access several features due to database conflicts(due to same db name). So i fixed that by removing the database and recreating with the cloned app. I had done it before from commandline but i forget now on how to do it. Could some one tell me where is the postgres database file located in ubuntu or how to remove from commandline? Thanks in advance.
There is a postgresql shell command dropdb which you can use.
After a bit of searching i found that doing this will remove the database. From the commandline just cd into your app directory and run this command
rake RAILS_ENV='development' db:drop
This will remove the database(although am still unable to find the exact location where its stored physically in hard drive). This is the solution if you cant access rails console, or some rake commands.
After that we can just recreate the database using
rake db:create

Rails - Cant run any rake commands db is messed up

Everything was working fine yesterday and all of a sudden when i tried to run my server or run any rake tasks i get this error
Mysql2::Error: Table 'myapp_development.key_value_stores' doesn't exist: SHOW FULL FIELDS FROM `key_value_stores`
I've tried google searching and searching on stackoverflow all morning and cant find a solution to this
Try to rollback your migration file (take backup of the migration file will help while creating new ),
rake db:migrate:down VERSION=migrations's_version
and then try to restart the rails server.If you face same problem then with same migration number search in schema_migrations table in database delete that record and make new migration again.
I was struggling with this for a while but what i ended up doing
update xcode and update command line tools
uninstall then install mysql via homebrew
then i ended up manually removing my database folder in
usr/local/var/mysql/myapp
then i did a
rake:create
and then i just pulled my production database and copied it to my development database
rake db:backup_and_load
then I was up and running again
dont know which one of that fixed it specifically but thats what i did

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.

Resources