Please sign in to comment.
Refactor migration to move migrations paths to connection
Rails has some support for multiple databases but it can be hard to handle migrations with those. The easiest way to implement multiple databases is to contain migrations into their own folder ("db/migrate" for the primary db and "db/seconddb_migrate" for the second db). Without this you would need to write code that allowed you to switch connections in migrations. I can tell you from experience that is not a fun way to implement multiple databases. This refactoring is a pre-requisite for implementing other features related to parallel testing and improved handling for multiple databases. The refactoring here moves the class methods from the `Migrator` class into it's own new class `MigrationContext`. The goal was to move the `migrations_paths` method off of the `Migrator` class and onto the connection. This allows users to do the following in their `database.yml`: ``` development: adapter: mysql2 username: root password: development_seconddb: adapter: mysql2 username: root password: migrations_paths: "db/second_db_migrate" ``` Migrations for the `seconddb` can now be store in the `db/second_db_migrate` directory. Migrations for the primary database are stored in `db/migrate`". The refactoring here drastically reduces the internal API for migrations since we don't need to pass `migrations_paths` around to every single method. Additionally this change does not require any Rails applications to make changes unless they want to use the new public API. All of the class methods from the `Migrator` class were `nodoc`'d except for the `migrations_paths` and `migrations_path` getter/setters respectively.
- Loading branch information...
Showing with 417 additions and 308 deletions.
- +2 −2 activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
- +8 −0 activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
- +2 −2 activerecord/lib/active_record/connection_adapters/schema_cache.rb
- +137 −119 activerecord/lib/active_record/migration.rb
- +1 −0 activerecord/lib/active_record/railtie.rb
- +8 −11 activerecord/lib/active_record/railties/databases.rake
- +1 −1 activerecord/lib/active_record/schema.rb
- +1 −1 activerecord/lib/active_record/schema_dumper.rb
- +8 −4 activerecord/lib/active_record/tasks/database_tasks.rb
- +1 −1 activerecord/test/cases/adapters/mysql2/schema_migrations_test.rb
- +2 −2 activerecord/test/cases/ar_schema_test.rb
- +25 −25 activerecord/test/cases/migration/pending_migrations_test.rb
- +43 −28 activerecord/test/cases/migration_test.rb
- +80 −68 activerecord/test/cases/migrator_test.rb
- +83 −41 activerecord/test/cases/tasks/database_tasks_test.rb
- +1 −1 activestorage/test/database/setup.rb
- +1 −1 railties/lib/rails/info.rb
- +12 −0 railties/test/application/rake/migrations_test.rb
- +1 −1 railties/test/railties/engine_test.rb
Oops, something went wrong.