title: How to correctly instantiate a model in plugin init.rb?
body: <p>How do you correctly initialize Redmine plugins that need to instantiate a model (read a database record) defined in the plugin itself?</p>
  
  <p>For example, I have a plugin <code>my_redmine_plugin</code> which comes with a model <code>MyPluginModel</code>. On plugin initialization, I'd like to</p>
  
  <ul>
  <li>read a record of <code>MyPluginModel</code> from DB</li>
  <li>run some initialization code with the record</li>
  </ul>
  
  <p>Given the following code:</p>
  
  <pre><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
  </code></pre>
  
  <p>It looks like <code>to_prepare</code> runs before the migration:</p>
  
  <pre><code>$ bundle exec rake redmine:plugins:migrate NAME=my_redmine_plugin
  
  `table_structure': Could not find table 'mypluginmodel' (ActiveRecord::StatementInvalid)
  ...
  </code></pre>
  
  <p>When I comment out the <code>to_prepare</code> block during migration, everything works fine. Is there any way to detect the migration process?</p>