Note: I am using Apartment gem to manage my multi schema database, and this article is written with expectation you know and use that gem.

When you have multiple schema in your rails application, it is important for them to remain consistent. Rails migration is run by keeping track of the timestamp prefixed in front of its file name. It stores the database. So when you restore a schema that hasn’t ran the migration, but rest of the schemas has it, rails thinks it has already ran the migration. Rails look at the main / default schema to know if it has ran the migrations and then follow up on the rest.

To run the migrations in that schema you just restored, log on to the rails console. rails c, switch to the restored schema (Apartment::Tenant.switch!('restored_schema')) and run the following code.


to rollback:

1"db/migrate").rollback 1