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

Talk A Little About DATABASE_URL? #1

Open
metaskills opened this issue Jan 18, 2018 · 1 comment
Open

Talk A Little About DATABASE_URL? #1

metaskills opened this issue Jan 18, 2018 · 1 comment

Comments

@metaskills
Copy link
Member

I just saw this thread on the adapter and I wonder if it would help to have a small section in the README to talk about DABASE_URL?

rails-sqlserver/activerecord-sqlserver-adapter#497 (comment)

@bf4
Copy link
Contributor

bf4 commented Feb 9, 2018

Looks to me like the recommendation for using DATABASE_URL is for the post-erb evaluated database yml to look something like

 adapter: sqlserver
  pool: 5
  timeout: 5000
  encoding: utf-8


production:
  <<: *default
  azure: true
  url: sqlserver://username:[email protected]:1433/database_name

where azure: true is not specified in the url, because

The default parsing of the DATABASE_URL by rails means that the value for :azure is a string "true" instead of true. All values coming the params of a URL are returned as strings. That is what causes this error. In the code you could !!config[:azure] to ensure its always true or false

https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/000b9c79797a8635a569ab28abfbbc1eca29d2cf/lib/active_record/connection_adapters/sqlserver_adapter.rb#L352

          azure: config[:azure]

and someone posted

When heroku attempts to precompile assets, it uses a fake database url, such that rails won't complain about not having one (in the case none is set) while running rake and bringing up the environment. When it does this, I'm pretty sure it must dynamically try to figure out the scheme from the database adapter, but in this case is not capable of doing so.

It is only an issue for me with Azure where we need to manage the connection differently than through DATABASE_URL (because of the azure:true flag). As a brief workaround, in case anyone googles this and gets stuck, you can try a deploy script like the following that will wrap your git push in an environment toggle.

#!/usr/bin/env bash

# $1 should be environment
# $2 should be branch

# set database url
heroku config:set DATABASE_URL=`heroku config -r $1 | grep -o "\(sqlserver..*\)" | head -n1` -r $1

# push code
git push $1 $2:master

# roll back database url setting
heroku config:unset DATABASE_URL -r $1

# run migations
heroku run rake db:migrate -r $1

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

2 participants