-
Notifications
You must be signed in to change notification settings - Fork 194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does not work with Rails multiple databases #181
Comments
I am facing the same issue, did you find any workaround to make this work? |
me too |
@lewhit, i forgot, did you have experience with multi-databases in data-migrate? do you have any ideas on what's happening here? |
@ilyakatz the gem is trying to update the data_migrations table of the secondary database. the data migration is for the primary database. so the gem seems to be unaware that multiple databases can exist. |
We have this same issue. Has anyone found a workaround? edit: We were able to get this working with an initializer:
|
I have a branch that appears to properly run migrations across all configured connections, in the same way that schema migrations work. I don't have a lot of time right now to test and fix specs, but if anyone else wants to contribute we could get a pull request submitted once this is cleaned up https://github.com/chaunce/data-migrate/tree/multiple_connection_support |
I have fixed the specs and created a pull request. Any testing and feedback anyone can offer would be helpful #249 |
Thanks for working on this issue! I'm testing the version 10.0.0 of the I created a very simple Rails app for demonstration: https://github.com/martingregoire/data-migrate-multi-db It has a primary database with a Now I'd like to add a data migration that is run on the $ rails g data_migration DoSomethingWithPosts --database primary
create db/data/20230608080311_do_something_with_posts.rb
$ rails g data_migration DoSomethingWithComments --database secondary
create db/data/20230608080320_do_something_with_comments.rb Then to run the data migrations: $ rails db:migrate:with_data
== Data =======================================================================
== 20230608080311 DoSomethingWithPosts: migrating =============================
== 20230608080311 DoSomethingWithPosts: migrated (0.0024s) ====================
== Data =======================================================================
== 20230608080320 DoSomethingWithComments: migrating ==========================
== 20230608080320 DoSomethingWithComments: migrated (0.0018s) =================
== Schema =====================================================================
== 20230608074207 CreatePosts: migrating ======================================
-- create_table(:posts)
-> 0.0010s
== 20230608074207 CreatePosts: migrated (0.0010s) =============================
== Data =======================================================================
== 20230608080311 DoSomethingWithPosts: migrating =============================
== 20230608080311 DoSomethingWithPosts: migrated (0.0004s) ====================
== Data =======================================================================
== 20230608080320 DoSomethingWithComments: migrating ==========================
== 20230608080320 DoSomethingWithComments: migrated (0.0004s) ================= What happens is that
The schema migration creates a $ sqlite3 db/primary.sqlite3 .tables
ar_internal_metadata
data_migrations
schema_migrations
posts
$ sqlite3 db/secondary.sqlite3 .tables
ar_internal_metadata
data_migrations
schema_migrations
comments
posts In Am I doing something wrong? Do I have to use a different directory for the data migrations for the secondary database? The creation of the |
It looks like this was tested on version 10.0.0, so it should include the new support for multiple databases. Regarding your two issues: The test cases added were configured on a mock application using horizontal sharding [https://guides.rubyonrails.org/active_record_multiple_databases.html#horizontal-sharding]. In this case, the data migrations may need to run on all connections. For example, if the Since data migrations piggy-back off the scheme migration tasks/code, the implementation I added uses the same configuration, and a data migration that is not built for a specific connection will run on all connections. In the data migration itself, you should be able to control what data and how the data on the current connection is migrated. a schema migration is run, but on the wrong database I can look into these issues sometime, but I don't know exactly when.. |
Thanks @chaunce! each data migration is run twiceOur use case is neither sharding nor role-based connections; we simply use multiple databases for separation of the storage of records. Imagine the main, important data in the primary database, and some not so important data in the secondary database, which has lower performance or availability. Do you happen to have an example of how to check for the current connection inside a data migration file? a schema migration is run, but on the wrong databaseWithout the I created these schema migrations using the
Running After adding the gem, running |
Hey everyone, at Gusto, we rely heavily on this gem. As of version 10, things just stopped working completely for us. @wildmaples and I have been debugging and have realized the implementation for multiple databases is...not quite right. We think that you actually don't need each database to maintain it's own data migration versions at all. We just need the single primary db to keep track since data migrations can make changes to all databases already. All the issues that folks are seeing (eg see below), can probably be addressed in other ways.
At this point we're not sure what the intention of creating a We have two paths forward:
We've reached out to @ilyakatz to schedule a Zoom call to figure out what the intention was so we know how to resolve this. |
Having a |
Hi folks, I just re-read the comments and I sounds like people use multiple databases for different usecases
Are there other usecases? From what I can tell, @chaunce solved for sharding usecase, correct?
I can see why this could be a problem as people are expecting to use it the same way as it's used in Rails, but technically it's not a requirement that it this gem has to operate the same way although not ideal.
this sounds like a big problem So where do we go from here?
|
cc @opti I know you were active more recently, see discussion above |
Some feedback on the previous comment:
However, there's also the combination of multiple strategies. I can use horizontal shading for client data (all the same tables across all databases), but also have Application Specific data only one connection, and separate connections for Reads and Writes. For example: Using the following
And [example - maybe non-functional] application code:
So all clients all exist on Last, if This is all fully supported in Rails currently. This might be an uncommon configuration now, but I imagine will become more common in the future.
The way I see it there are two options:
If I want to be able to run If we do continue to follow the rails migration patterns, we'll have to account for the complex configuration shown above, and part of that will be a
I agree, this should be fixed. I can look into it someone soon, but don't have an exact timeline. @ilyakatz I can join a call sometime, and I'm happy to provide time to updates, assuming in alignment on the end goal. You're the maintainer, so you get to decide where the project goes from here, and I don't want to get in the way of your progress if we're headed in different directions. I'd like to see the gem support migrations the way rails does the schema, but I understand that this may not fit in your vision of how the gem should work. |
@chaunce thanks, could you email me and we'll coordinate with @wildmaples to set up a call |
Hi everyone, I tend to agree with @chaunce on following the Rails approach for migrations to run on specific connections. It might sounds like an overkill, but should be more versatile. We all might have different database setups since Rails allows that, but it doesn't mean that data_migrate should pick only one to support. As long as this gem claims that data migrations act like schema migrations, similar implementation seems reasonable. However, regardless of the approach, I don't mind some breaking changes as long as there is a clear upgrade path documented somewhere. P.S. @ilyakatz We have situation similar to Gusto (maybe not that heavily using data migrations though) and as of version 10 data migrations stopped working for us completely. Hence my recent activity with some fixes. |
Hi folks, just wanted to provide an update, we had a call with @ngan and @wildmaples. They will help on gem development, particularly for multi-database support and/or rails 7.1 support. I've added them as contributors. Since v10 has introduced issues with many folks, we will need to roll it back. Thanks @chaunce for your contribution, we certainly appreciate your work but seems we'd need another approach to keep it usable for wider audience. This was a good learning experience for sure. I will yank v10.0.x versions to avoid people picking up versions that are not working |
When I configure my Rails 6.1 app to use multiple databases (via built in functionality), data-migrate doesn't work.
but running
rake data:migrate
does not create it.Is it a known limitation?
Do you plan to support multiple databases?
The text was updated successfully, but these errors were encountered: