-
Notifications
You must be signed in to change notification settings - Fork 36
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
Migrations #5
Comments
I'd not considered this as an option... but it's made me think about migrations in engines. Off the top of my head, there are three options:
And then, here's what I think matters from both Rails app developer and engine developer perspectives:
Option 1 takes care of the third point, but it splits migrations over more than one location, and also introduces separate numbering systems (I don't want my migration version numbers reflecting when an engine developer added a migration, but when I added that update to my app). Option 3 takes care of the first and second points, but it then gets messy from a maintenance perspective - unless the engine developer adds new migration generators instead of modifying the existing generator templates. Option 2 covers off all three points, hence why I'm happy to stick with it. Of course, I only thought through all of this today. I'm sure there's perspectives and advantages I've not considered. |
rake engine:install:migrations is the cleanest option as it changes the date stamp of the migration to the moment you ran the rake task. The order of migrations in your app could be important. |
Good points, I hadn't considered them all. I had only thought about someone updating the engine code and forgetting to run the migration. We really need to work on the engine docs. Look what I ended up having to do here: https://github.com/mbleigh/acts-as-taggable-on/pull/343/files#L2R47 :) |
Yeah, that's not cool at all. That's the main reason why I'm not a fan of migrations through generators. |
@pat You mean that you'd rather dump 'em all in "db/migrate/1_gutentag_tables.rb"? It all comes down to the same thing in Rails engines, though. It sorts them and copies them. |
In my opinion, option 2 Before |
Thanks all for the feedback - I'm going to close this ticket. The opportunity to think through this and get your opinions is appreciated :) If anyone else wishes to chime in, they can certainly do so. |
I agree with @pat and @parndt on this issue (although probably a bit late!). We have a consistent problem with Spree where people will upgrade their Spree version and then forget to run the migrations! The second option is still the best way to solve this problem, as far as I know. You could go one step further and provide a binary that does the copying+running of the migrations, something like |
I'd be interested to hear Jose Valim's take on this since he's the one who introduced me to 'option 1', and his book is all about the engines and their craftiness. There @josevalim wrote:
@benjaminleesmith also advocated 'option 1', in the context of modularizing an existing app cc: @zzak , @senny , @fx, @steveklabnik , @Dracco Anyone want to work on the engines guide in docrails with me? Disclaimer: haven't started yet. |
@bf4 I think "trust" was a poor choice of word in there. Ownership is a better word. I would use the first approach just if you "own" the engine, not for 3rd parties one. So if you are splitting your applications into multiple engines, the 1st approach is a good option. The 2nd approach should definitely be the recommended one for the majority of the cases. I will amend the comment. :) |
There's an alternative configuration we forgot: Rather than depend on the rake task, the end user can add his/her/zer/their codebase in config/application.rb or in an initializer, if the end user prefers to automatically run migrations. config.paths["db/migrate"] += Gutentag::Engine.paths["db/migrate"].existent |
Sure, but then the migration version numbers are out of the developer's control - it's the equivalent of the first option in my list. |
I see you require running
rake gutentag:install:migrations
(and I gather that this works without a configuration in the engine because you used a sortable migration name https://github.com/pat/gutentag/blob/e9af72b/db/migrate/1_gutentag_tables.rb )Did you consider including the migrations without need of a rake task?
The text was updated successfully, but these errors were encountered: