Skip to content
This repository has been archived by the owner on Apr 21, 2022. It is now read-only.

Commit

Permalink
Changes after merges
Browse files Browse the repository at this point in the history
  • Loading branch information
brasten committed Aug 2, 2010
1 parent 1b737db commit 28ae285
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 37 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
@@ -1,3 +1,6 @@
== 0.1.4
* Merged in changes to rake tasks and timestamp migrations

== 0.1.3
* update sequel dependency, configuration change

Expand Down
63 changes: 26 additions & 37 deletions lib/sequel-rails/railties/database.rake
Expand Up @@ -24,58 +24,47 @@ namespace :db do

namespace :create do
desc 'Create all the local databases defined in config/database.yml'
task :all do
Rails.configuration.database_configuration.each_value do |config|
next unless config['database']
database = config.delete('database')
DB = Sequel.connect(config)
default_options = "DEFAULT CHARSET utf8 COLLATE utf8_unicode_ci"
puts "Creating database \"#{config['database']}\" if it doesn't already exist"
DB.run "CREATE DATABASE IF NOT EXISTS `#{config['database']}` /*!40100 #{default_options} */"
end
task :all, :needs => :environment do
require 'sequel-rails/storage'
Rails::Sequel::Storage.create_all
end
end

desc "Create the database defined in config/database.yml for the current Rails.env - also creates the test database if Rails.env.development?"
task :create do
connect_options = Rails.configuration.database_configuration[Rails.env]
connect_options.delete('database')
DB = Sequel.connect(connect_options)
default_options = "DEFAULT CHARSET utf8 COLLATE utf8_unicode_ci"
puts "Creating database \"#{Rails.configuration.database_configuration[Rails.env]['database']}\" if it doesn't already exist"
DB.run "CREATE DATABASE IF NOT EXISTS `#{Rails.configuration.database_configuration[Rails.env]['database']}` /*!40100 #{default_options} */"
task :create, :env, :needs => :environment do |t, args|
args.with_defaults(:env => Rails.env)

require 'sequel-rails/storage'
Rails::Sequel::Storage.new(args.env).create

if Rails.env.development? && Rails.configuration.database_configuration['test']
puts "Creating database \"#{Rails.configuration.database_configuration['test']['database']}\" if it doesn't already exist"
DB.run "CREATE DATABASE IF NOT EXISTS `#{Rails.configuration.database_configuration['test']['database']}` /*!40100 #{default_options} */"
Rails::Sequel::Storage.new('test').create
end
end

namespace :drop do
desc 'Drops all the local databases defined in config/database.yml'
task :all do
Rails.configuration.database_configuration.each_value do |config|
next unless config['database']
database = config.delete('database')
DB = Sequel.connect(config)
puts "Dropping database #{database} if it exists"
DB.run "DROP DATABASE IF EXISTS `#{database}`"
end
task :all, :needs => :environment do
require 'sequel-rails/storage'
Rails::Sequel::Storage.drop_all
end
end

desc "Create the database defined in config/database.yml for the current Rails.env - also creates the test database if Rails.env.development?"
task :drop do
connect_options = Rails.configuration.database_configuration[Rails.env]
connect_options.delete('database')
DB = Sequel.connect(connect_options)

puts "Dropping database #{Rails.configuration.database_configuration[Rails.env]['database']} if it exists"
DB.run "DROP DATABASE IF EXISTS `#{Rails.configuration.database_configuration[Rails.env]['database']}`"
task :drop, :env, :needs => :environment do |t, args|
args.with_defaults(:env => Rails.env)

require 'sequel-rails/storage'
Rails::Sequel::Storage.new(args.env).drop

if Rails.env.development? && Rails.configuration.database_configuration['test']
Rails::Sequel::Storage.new('test').drop
end
end

namespace :migrate do
task :load do
require File.expand_path('../../sequel_migration', __FILE__)
require 'sequel-rails/migrations'
end

desc 'Rollbacks the database one migration and re migrate up. If you want to rollback more than one step, define STEP=x. Target specific version with VERSION=x.'
Expand All @@ -97,22 +86,22 @@ namespace :db do
task :up => :load do
version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
raise "VERSION is required" unless version
Sequel::Migrator.run(:up, "db/migrate/", version)
Rails::Sequel::Migrations.migrate_up!(version)
Rake::Task["db:schema:dump"].invoke
end

desc 'Runs the "down" for a given migration VERSION.'
task :down => :load do
version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
raise "VERSION is required" unless version
Sequel::Migrator.run(:down, "db/migrate/", version)
Rails::Sequel::Migrations.migrate_down!(version)
Rake::Task["db:schema:dump"].invoke
end
end

desc 'Migrate the database to the latest version'
task :migrate => :'migrate:load' do
Sequel::Migrator.migrate("db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
Rails::Sequel::Migrations.migrate_up!(ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
Rake::Task["db:schema:dump"].invoke
end

Expand Down
2 changes: 2 additions & 0 deletions lib/sequel-rails/storage.rb
Expand Up @@ -25,6 +25,8 @@ def self.drop_environment(config)
end

def self.new(config)
config = Rails::Sequel.configuration.environments[config.to_s] unless config.kind_of?(Hash)

klass = lookup_class(config['adapter'])
if klass.equal?(self)
super(config)
Expand Down

0 comments on commit 28ae285

Please sign in to comment.