How do you correctly initialize Redmine plugins that need to instantiate a model (read a database record) defined in the plugin itself?
For example, I have a plugin my_redmine_plugin
which comes with a model MyPluginModel
. On plugin initialization, I'd like to
- read a record of
MyPluginModel
from DB - run some initialization code with the record
Given the following code:
require 'redmine'
Redmine::Plugin.register :my_redmine_plugin do
name 'My Redmine Plugin'
# ...
end
Rails.configuration.to_prepare do
m = MyPluginModel.find(1)
run_some_init_code(m)
end
It looks like to_prepare
runs before the migration:
$ bundle exec rake redmine:plugins:migrate NAME=my_redmine_plugin
`table_structure': Could not find table 'mypluginmodel' (ActiveRecord::StatementInvalid)
...
When I comment out the to_prepare
block during migration, everything works fine. Is there any way to detect the migration process?