我已经阅读了所有
sequel的文档,但我找不到创建数据库的方法,假设我可以做到这一点.
我正在运行一个rake任务:
require 'rubygems' require 'bundler/setup' require 'pg' require 'sequel' require 'yaml' require 'erb' namespace :db do task :connect do end task :create => :connect do puts db_config Sequel.connect(db_config['production']){ |db| db.create_table :user do primary_key :id String :name String :email end user = db[:user] user.insert(:name => 'Roland',:email => 'rolandjitsu@gmail.com') } end task :drop => :connect do end end def db_config YAML.load(ERB.new(File.read('config/database.yml')).result) end
但显然如果数据库不存在则不会创建数据库,所以我有点不确定我能做些什么.当我运行任务时,我得到:
PG::ConnectionBad: FATAL: database "pulsr" does not exist
和database.yml文件:
production: &production adapter: postgres host: localhost encoding: unicode database: pulsr username: password: development: <<: *production