Skip to content

Commit

Permalink
Abort with error on helios server if DATABASE_URL is set to a non-pos…
Browse files Browse the repository at this point in the history
…tgres database
  • Loading branch information
mattt committed May 10, 2013
1 parent efc8620 commit 6655308
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/helios/commands/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def validate_database_settings!

say_error "DATABASE_URL environment variable not set in .env or in Rails config/database.yml" and abort if ENV['DATABASE_URL'].nil?

uri = URI(ENV['DATABASE_URL'])

say_error "DATABASE_URL environment variable not set to PostgreSQL database" and abort unless ["postgres", "postgresql"].include?(uri.scheme)

begin
db = Sequel.connect(ENV['DATABASE_URL'])
db.test_connection
Expand All @@ -36,7 +40,6 @@ def validate_database_settings!
case error.message
when /database "(.+)" does not exist/
if agree "Would you like to create this database now? (y/n)"
uri = URI(db.uri)
host, database = uri.host, uri.path.delete("/")

log 'createdb', database
Expand Down

0 comments on commit 6655308

Please sign in to comment.