customink / secondbase

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

Migration generator doesn't respect `config.paths['db']` #51

Closed MrJoy closed 7 years ago

MrJoy commented 7 years ago

I wanted to set things up so I had db_oltp and db_olap directories, so in config/application.rb I set things up like this:

    config.paths['db'] = ['db_oltp']
    config.paths['db/migrate'] = ['db_oltp/migrate']
    config.paths['db/seeds.rb'] = ['db_oltp/seeds.rb']
    config.second_base.path = 'db_olap'
    config.second_base.config_key = 'olap'

Unfortunately, when generating migrations, SecondBase assumes that the path it will see begins with db/migrate.

If you change migration_template like this, you should get the desired effect all the time:

      def migration_template(*args)
        path = Pathname.new(Rails.application.config.paths['db/migrate'].first).relative_path_from(Rails.root).to_s

        args[1].sub! path, "#{Railtie.config_path}/migrate" if args[1]

        super(*args)
      end
metaskills commented 7 years ago

Nice, I believe you are right. Are you participating in Hacktoberfest and would you care to make a pull request with that simple change?

MrJoy commented 7 years ago

Not participating in Hacktoberfest, but I do believe I can submit a PR. Will get to that once I'm in the office.