Rails 6.1 failed migrations no longer block rails from running? - ruby-on-rails

In the past when there were migrations which didn't run yet, there would be an error 'pending migrations' that would prohibit rails (server, console) from starting.
I've updated to Rails 6.1 and have a failing migration. Nevertheless the server is running and I can go into the console without any warning.
The migration that is failing is a ActiveRecord::Migration[6.1] migration.
Is this intended? Is there a way of going back to the old behavior? We use Kubernetes and a failed migration just blocks the new pod from coming live which is perfect.

Related

Rails - All test database opertaions hanging

I was running a small migration to the test database (already run fine on local database), when it hung up. I terminated the process, and tried to re-run, I keep getting the error:
Cannot run migrations because another migration process is currently running.
So I try to reset the database, by running rails db:reset RAILS_ENV=test, but this again keeps running and giving no response. Desperate I thus try dropping and rebuilding the database, by first rails db:drop RAILS_ENV=test that again runs forever and gives no response.
How can I get the migration to run normally again?
You can try restarting the test database to clear any connections.
Depending on the platform you're using:
brew services restart mysql
or
docker-compose restart mysql

rails db migrate locally-Multiple migrations have the version number

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?

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.

Rails 5.1.4 after upgrade DuplicateMigrationNameError

I recently updated a Rails 4.2 app to 5.1.4. After upgrading, whenever I try to run rake db:migrate, I get a DuplicateMigrationNameError. The first few times, the error pointed to a file so I just changed the name of the migration class and the file name. But after 4 such changes, the rake task threw the error for the file I just changed, with the new file name/class name. If I changed it back, it still threw the same error. If I changed it to something totally new the same thing happened; it picked up the new filename and threw a DuplicateMigrationNameError. I do not have a duplicate file, there are no cached files that I can find. I am running the rails app in a vagrant vm running ubuntu 16.04. The migrations all ran fine on rails 4.2.
This can also happen when the class name of the migration is duplicated. Open the migrations and see if the class names are identical.

Rails + Elastic Beanstalk: Abort deployments when database migration fails

I've got a Rails 5/Ruby 2.3 app running on Elastic Beanstalk. I want deployments to abort when a database migration fails.
My RAILS_SKIP_MIGRATIONS is set to false, so migrations execute when deployment. However, I had an issue where one migration failed but the deployment completed. This of course resulted in several 500 afterwards.
I've considered writing an ebextension which runs on post-deployment and checks whether there's an issue. If there is, then I rollback to the previous app version. However, I'm not sure if this approach is the right one.

Resources