Sha256: 3220d86e303af0b7a003e11c2b5b9d23e34287ab774fac3d4423b7377a373b79

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

namespace :db do
	task :load_config => :environment do
		database_tasks = ActiveRecord::Tasks::DatabaseTasks
		
		unless root = ActiveRecord::Migrations.root
			abort "ActiveRecord::Migrations.root needs to be set!"
		end
		
		unless DATABASE_ENV
			abort "DATABASE_ENV needs to be set!"
		end
		
		if ActiveRecord::Base.configurations.empty?
			abort "ActiveRecord::Base.configurations needs to be setup!"
		end
		
		database_tasks.root = root
		database_tasks.db_dir = File.join(root, 'db')
		database_tasks.env = DATABASE_ENV.to_s
		database_tasks.database_configuration = ActiveRecord::Base.configurations
		database_tasks.migrations_paths = File.join(root, 'db/migrate')
		
		database_tasks.send(:define_method, :load_seed) do
			load File.join(root, 'db/seed.rb')
		end
	end
	
	task 'Setup a new database if required and run migrations.'
	task :deploy => :load_config do
		database_tasks = ActiveRecord::Tasks::DatabaseTasks
		
		schema_path = File.join(database_tasks.db_dir, 'schema.rb')
		unless File.exist? schema_path
			abort "Missing #{schema_path}, cannot deploy!"
		end
		
		if ActiveRecord::Migrations.database?
			Rake::Task['db:migrate'].invoke
		else
			Rake::Task['db:setup'].invoke
		end
	end
	
	task :connection_config => :environment do
		require 'pp'
		
		pp ActiveRecord::Base.connection_config
	end
end

# Loading this AFTER we define our own load_config task is critical, we need to make sure things are set up correctly before we run the task of the same name from ActiveRecord.
load 'active_record/railties/databases.rake'

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activerecord-migrations-1.0.0.pre.rc1 lib/activerecord/migrations/tasks/db.rb