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?
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)
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 O. 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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.