Navigation Menu

Skip to content

Commit

Permalink
Allow sequel command line tool to work with yaml config files with sy…
Browse files Browse the repository at this point in the history
…mbol keys

This commit will try the following in order to find the parameters to
use:

  # Assume yaml_hash is the hash returned by YAML.load for the
  # file given on the command line, and env is the environment
  # specified by the user (or 'development' by default)
  params = yaml_hash[env] || yaml_hash[env.to_sym] || yaml_hash

Notice that in addition to supporting symbol keys (such as
:development), Sequel now also supports a plain yaml file for
parameters, such as:

  ---
  :adapter: sqlite
  :database: ':memory:'
  • Loading branch information
jeremyevans committed Jan 29, 2009
1 parent 5df9a37 commit 392963a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -1,5 +1,7 @@
=== HEAD

* Support symbol keys and unnested hashes in the sequel command line tool's yaml config support (jeremyevans)

* Add schema parsing support to the JDBC adapter (jeremyevans)

* Add per-database type translation support for schema changes, translating ruby classes to database specific types (jeremyevans)
Expand Down
13 changes: 5 additions & 8 deletions bin/sequel
Expand Up @@ -83,18 +83,15 @@ end

if File.exist?(db)
require 'yaml'
db_config = YAML.load_file(db)[env || "development"]
db_config.each {|(k,v)| db_config[k.to_sym] = db_config.delete(k)}
env ||= "development"
db_config = YAML.load_file(db)
db_config = db_config[env] || db_config[env.to_sym] || db_config
db_config.each{|(k,v)| db_config[k.to_sym] = db_config.delete(k)}
db_config.merge!(db_opts)
end

begin
if db_config
opts = [db_config]
else
opts = [db, db_opts]
end
DB = Sequel.connect(*opts)
DB = Sequel.connect(*(db_config ? [db_config] : [db, db_opts]))
DB.test_connection
if migrate_dir
Sequel::Migrator.apply(DB, migrate_dir, migrate_ver)
Expand Down

0 comments on commit 392963a

Please sign in to comment.