customink / secondbase

Seamless second database integration for Rails.
MIT License
220 stars 31 forks source link

SeconBase db:structure:dump #50

Closed workgena closed 6 years ago

workgena commented 7 years ago

I have database. And want to dump current state to structure.sql. And there is no task for this.

This task also needed for migrations when set this option:

# config/application.rb
config.active_record.schema_format = :sql

For this reason I added task:

namespace :db do
  namespace :second_base do
    namespace :structure do
      task dump: ['db:load_config'] do
        SecondBase.on_base { Rake::Task['db:structure:dump'].execute }
      end
    end
  end
end

And it works with

config.active_record.dump_schemas = :all

But dump is wrong. because of missing :environment task.

This is my fork with fix (no tests): https://github.com/workgena/secondbase/blob/master/lib/second_base/databases.rake

metaskills commented 7 years ago

Hmm... we also do not have a defined schema:dump as well. The idea here is that as other tasks call out to ActiveRecord's task, we have already enabled SecondBase as being on_base. I wonder if we should make a _dump tasks and that would work for both? https://github.com/rails/rails/blob/master/activerecord/lib/active_record/railties/databases.rake#L64-L77

workgena commented 7 years ago

Need to double check this(and write some test, when have some time).

In current protect we prefer to use config.second_base.run_with_db_tasks = false and use separate command for migrations. And when run this command rake db:second_base:migrate there was two strange mistakes:

When I have some time, I'll do tests fro this cases. And it will be clear what is wrong.

metaskills commented 7 years ago

Ah! So yea... I kind of suspect that turning off the task shadowing opens up those issues. In some ways I would like to promote that issues like this can happen and to not use said feature or encourage documented workarounds like yours.

When I have some time, I'll do tests fro this cases. And it will be clear what is wrong.

Very cool, appreciate that. I would be open to docs only (maybe #advanced-usage section) PRs too, whatever you find is best. Our tests are pretty easy to clone and run, TravisCI will also run pull requests too. Lastly, we have a little side/demo app that is fun to play around with for quick integration checks. See here:

Thanks again!