lib/sequel_rails/railties/database.rake in sequel-rails-0.5.0 vs lib/sequel_rails/railties/database.rake in sequel-rails-0.5.1
- old
+ new
@@ -17,12 +17,14 @@
namespace :schema do
desc "Create a db/schema.rb file that can be portably used against any DB supported by Sequel"
task :dump => :environment do
db_for_current_env.extension :schema_dumper
- File.open(ENV['SCHEMA'] || "#{Rails.root}/db/schema.rb", "w") do |file|
- file.write db_for_current_env.dump_schema_migration(:same_db => true)
+ filename = ENV['SCHEMA'] || "#{Rails.root}/db/schema.rb"
+ File.open filename, "w" do |file|
+ file << db_for_current_env.dump_schema_migration(:same_db => true)
+ file << SequelRails::Migrations.dump_schema_information(:sql => false)
end
Rake::Task["db:schema:dump"].reenable
end
desc "Load a schema.rb file into the database"
@@ -40,51 +42,55 @@
namespace :structure do
desc "Dump the database structure to db/structure.sql. Specify another file with DB_STRUCTURE=db/my_structure.sql"
task :dump, [:env] => :environment do |t, args|
args.with_defaults(:env => Rails.env)
-
+
filename = ENV['DB_STRUCTURE'] || File.join(Rails.root, "db", "structure.sql")
- unless SequelRails::Storage.dump_environment args.env, filename
+ if SequelRails::Storage.dump_environment args.env, filename
+ ::File.open filename, "a" do |file|
+ file << SequelRails::Migrations.dump_schema_information(:sql => true)
+ end
+ else
abort "Could not dump structure for #{args.env}."
end
-
+
Rake::Task["db:structure:dump"].reenable
end
task :load, [:env] => :environment do |t, args|
args.with_defaults(:env => Rails.env)
-
+
filename = ENV['DB_STRUCTURE'] || File.join(Rails.root, "db", "structure.sql")
unless SequelRails::Storage.load_environment args.env, filename
abort "Could not load structure for #{args.env}."
end
end
end
-
- task dump: :environment do
+
+ task :dump => :environment do
case (SequelRails.configuration.schema_format ||= :ruby)
when :ruby
Rake::Task["db:schema:dump"].invoke
when :sql
Rake::Task["db:structure:dump"].invoke
else
abort "unknown schema format #{SequelRails.configuration.schema_format}"
end
end
-
- task load: :environment do
+
+ task :load => :environment do
case (SequelRails.configuration.schema_format ||= :ruby)
when :ruby
Rake::Task["db:schema:load"].invoke
when :sql
Rake::Task["db:structure:load"].invoke
else
abort "unknown schema format #{SequelRails.configuration.schema_format}"
end
end
-
+
namespace :create do
desc 'Create all the local databases defined in config/database.yml'
task :all => :environment do
unless SequelRails::Storage.create_all
abort "Could not create all databases."
@@ -141,25 +147,25 @@
desc 'Runs the "up" for a given migration VERSION.'
task :up => :load do
version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
raise "VERSION is required" unless version
SequelRails::Migrations.migrate_up!(version)
- Rake::Task["db:dump"].invoke unless Rails.env.test?
+ Rake::Task["db:dump"].invoke if SequelRails.configuration.schema_dump
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
SequelRails::Migrations.migrate_down!(version)
- Rake::Task["db:dump"].invoke unless Rails.env.test?
+ Rake::Task["db:dump"].invoke if SequelRails.configuration.schema_dump
end
end
desc 'Migrate the database to the latest version'
task :migrate => "migrate:load" do
SequelRails::Migrations.migrate_up!(ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
- Rake::Task["db:dump"].invoke unless Rails.env.test?
+ Rake::Task["db:dump"].invoke if SequelRails.configuration.schema_dump
end
desc 'Load the seed data from db/seeds.rb'
task :seed => :abort_if_pending_migrations do
seed_file = File.join(Rails.root, 'db', 'seeds.rb')