Hi! I have to move a complete model and its migration into a plugin. I know how can I do that for a model but what about the migration???
Regards, Mohsin
Hi! I have to move a complete model and its migration into a plugin. I know how can I do that for a model but what about the migration???
Regards, Mohsin
restful_authentication does something similar using a rake task and an erb template. If you're not already using it, you might want to install it just to see how they've solved the problem.
restful_authentication does something similar using a rake task and an erb template. If you're not already using it, you might want to install it just to see how they've solved the problem.
I've looked into it and its not yet clear to me. Actually, I only need to create a single table when my plugin is installed. No more. Should I do it manually in install.rb and uninstall.rb?
MohsinHijazee wrote:
restful_authentication does something similar using a rake task and an erb template. If you're not already using it, you might want to install it just to see how they've solved the problem.
I've looked into it and its not yet clear to me. Actually, I only need to create a single table when my plugin is installed. No more. Should I do it manually in install.rb and uninstall.rb?
It seems the Rails generator library has a migration method. The relevant code in restful authentication can be found at line 179 of "authenticated_generator.rb":
unless options[:skip_migration] m.migration_template 'migration.rb', 'db/migrate', :assigns => { :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}" }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}" end
There is obviously a lot here you won't need. You will also find a file called migration.rb in the templates directory, which get interpreted and copied across.
Mind you - I have never built a template for a migration before, so don't follow me
MohsinHijazee wrote: >> restful_authentication does something similar using a rake task and an >> erb template. If you're not already using it, you might want to >> install it just to see how they've solved the problem. > I've looked into it and its not yet clear to me. Actually, I only need > to create a single table when my plugin is installed. No more. Should > I do it manually in install.rb and uninstall.rb?
It seems the Rails generator library has a migration method. The relevant code in restful authentication can be found at line 179 of "authenticated_generator.rb":
unless options[:skip_migration] m.migration_template 'migration.rb', 'db/migrate', :assigns => { :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}" }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}" end
There is obviously a lot here you won't need. You will also find a file called migration.rb in the templates directory, which get interpreted and copied across.
Mind you - I have never built a template for a migration before, so don't follow me
So in a nutshell, there is no smart way of packing a migration with an application. Like if its a zip code plugin, the it would require to create a table called zipcodes and would need to populate it. What if we do it in install.rb and uninstall.rb? How do we do that?
engines does some 'engines migrations'