Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Changing environment config in runtime" not working #148

Open
landovsky opened this issue Sep 3, 2018 · 2 comments
Open

"Changing environment config in runtime" not working #148

landovsky opened this issue Sep 3, 2018 · 2 comments

Comments

@landovsky
Copy link

landovsky commented Sep 3, 2018

Having this

.env vars

DATABASE_URL_TEST=postgres://postgres:hele@postgres/techloop_automator_testik

db/config.yml

test:
  database: techloop_automator_test
  ...

Rakefile

require 'standalone_migrations'

StandaloneMigrations::Tasks.load_tasks

StandaloneMigrations::Configurator.environments_config do |env|
  env.on "test" do
    if (ENV['DATABASE_URL_TEST  '])
      db = URI.parse(ENV['DATABASE_URL_TEST'])
      return {
        :adapter  => db.scheme == 'postgres' ? 'postgresql' : db.scheme,
        :host     => db.host,
        :username => db.user,
        :password => db.password,
        :database => db.path[1..-1],
        :encoding => 'utf8'
      }
    end

    nil
  end
end

When I run rake db:create RAILS_ENV=test, I get:

root@f0db907210df:/automator# rake db:create RAILS_ENV=test
Created database 'techloop_automator_test'

>> it creates techloop_automator_test as opposed to techloop_automator_testik

@lacostenycoder
Copy link

Why are you using a different name in DATABASE_URL_TEST=postgres://postgres:hele@postgres/techloop_automator_testik than in your config? Did you try changing in yaml file

test:
  database: techloop_automator_testik

But also maybe try setting the config before loading the tasks? So move
StandaloneMigrations::Tasks.load_tasks to after your config do/end block.

@mattes
Copy link

mattes commented Jan 7, 2019

Same issue here. Here is a snippet that worked for me:

require 'tasks/standalone_migrations'
require 'yaml'

StandaloneMigrations::Configurator.environments_config do |env|
  f = YAML.load_file('config.yml')
  db = URI.parse(f['postgres'])
  env.on "default" do |c|
    c["adapter"]  = db.scheme == 'postgres' ? 'postgresql' : db.scheme
    c["host"]     = db.host
    c["port"]     = db.port
    c["username"] = db.user
    c["password"] = db.password
    c["database"] = db.path[1..-1]
    c["encoding"] = 'utf8'
    return c
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants