I''m working on a plugin which needs to add both schema and data to the app database, and I''m trying to figure out the best way to do it. I''d like to use a db migration to modify the schema and load the data from a YAML fixture, but Rails doesn''t seem to support migrations for plugins. To do so, the schema_info table would need to change to include a plugin name field (with ''rails'' or NULL for the application schema version), and corresponding mod to the Rake tasks to also run plugin migrations. Is there another way I can accomplish this? Is this a feature anyone else is wanting/working-on? Is there any reason why this _wouldn''t_ work? Thanks ... -- Steve
You might want to take a look at rails engines - we''ve implemented migrations and fixtures to some extent for plugins (since engines are first and foremost simply plugins themselves) - james On 12/14/05, Steve Sloan <steve-2FdKsI0tZ45AfugRpC6u6w@public.gmane.org> wrote:> I''m working on a plugin which needs to add both schema and data to the app > database, and I''m trying to figure out the best way to do it. I''d like to use a > db migration to modify the schema and load the data from a YAML fixture, but > Rails doesn''t seem to support migrations for plugins. To do so, the schema_info > table would need to change to include a plugin name field (with ''rails'' or NULL > for the application schema version), and corresponding mod to the Rake tasks to > also run plugin migrations. > > Is there another way I can accomplish this? Is this a feature anyone else is > wanting/working-on? Is there any reason why this _wouldn''t_ work? > > Thanks ... > > -- Steve > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On 12/14/05, Steve Sloan <steve-2FdKsI0tZ45AfugRpC6u6w@public.gmane.org> wrote:> I''m working on a plugin which needs to add both schema and data to the app > database, and I''m trying to figure out the best way to do it. I''d like to use a > db migration to modify the schema and load the data from a YAML fixture, but > Rails doesn''t seem to support migrations for plugins. To do so, the schema_info > table would need to change to include a plugin name field (with ''rails'' or NULL > for the application schema version), and corresponding mod to the Rake tasks to > also run plugin migrations. > > Is there another way I can accomplish this? Is this a feature anyone else is > wanting/working-on? Is there any reason why this _wouldn''t_ work? > > Thanks ... > > -- SteveI submitted a patch for Migration generators. I''m not sure if it made it into 1.0, but it''s definitely in trunk/1.1. I have an example in the acts as authenticated generator: http://techno-weenie.net/svn/projects/plugins/acts_as_authenticated/generators/authenticated_migration/templates/ -- rick http://techno-weenie.net
James Adam wrote:> You might want to take a look at rails engines - we''ve implemented > migrations and fixtures to some extent for plugins (since engines are > first and foremost simply plugins themselves)Good idea, but this is a small plugin (no controllers or views), and right now I''d just as soon avoid the overhead of making it an engine. Rick Olson wrote: > I submitted a patch for Migration generators. I''m not sure if it made > it into 1.0, but it''s definitely in trunk/1.1. Also a good idea, but I''m not a big fan of generators in general (RoR code is *small*, and I like it that way. Why generate more?) In my case, neither of these suggestions were entirely satisfactory because, in addition to the (simple) table schema, I also have a large chunk of data that also needs to be loaded, but which I didn''t want to keep around after it was on the DB. Since rake tasks are already automagically supported for plugins, I decided this approached best suited my situation. I mimicked the Rails ''create_sessions_table'' task, which essentially is a migration. I then added my own task to fetch, unzip, parse, and load the table data on the fly. Works like a charm. :) Thanks for the help ... -- Steve