0
-if defined?(Rake.application) && Rake.application && ENV["SKIP_AR_JDBC_RAKE_REDEFINES"].nil?
0
- jdbc_rakefile = File.dirname(__FILE__) + "/jdbc.rake"
0
- if Rake.application.lookup("environment")
0
- # rails tasks already defined; load the override tasks now
0
- # rails tasks not loaded yet; load as an import
0
- Rake.application.add_import(jdbc_rakefile)
0
+if defined?(namespace) && RUBY_PLATFORM =~ /java/ && ENV["SKIP_AR_JDBC_RAKE_REDEFINES"].nil?
0
+ def redefine_task(*args, &block)
0
+ task_name = Hash === args.first ? args.first.keys[0] : args.first
0
+ existing_task = Rake.application.lookup task_name
0
+ class << existing_task; public :instance_variable_set; end
0
+ existing_task.instance_variable_set "@prerequisites", FileList[]
0
+ existing_task.instance_variable_set "@actions", []
0
+ redefine_task :create => :environment do
0
+ create_database(ActiveRecord::Base.configurations[RAILS_ENV])
0
+ def create_database(config)
0
+ ActiveRecord::Base.establish_connection(config)
0
+ ActiveRecord::Base.connection
0
+ ActiveRecord::Base.establish_connection(config.merge({'database' => nil, 'url' => url}))
0
+ ActiveRecord::Base.connection.create_database(config['database'])
0
+ ActiveRecord::Base.establish_connection(config)
0
+ if (config['driver'] || config['adapter']) =~ /postgr/
0
+ `createdb "#{config['database']}" -E utf8`
0
+ warn "couldn't create database #{config['database']}"
0
+ redefine_task :drop => :environment do
0
+ config = ActiveRecord::Base.configurations[environment_name]
0
+ ActiveRecord::Base.establish_connection(config)
0
+ db = ActiveRecord::Base.connection.database_name
0
+ ActiveRecord::Base.connection.recreate_database(db)
0
+ namespace :structure do
0
+ redefine_task :dump => :environment do
0
+ abcs = ActiveRecord::Base.configurations
0
+ ActiveRecord::Base.establish_connection(abcs[RAILS_ENV])
0
+ File.open("db/#{RAILS_ENV}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump }
0
+ if ActiveRecord::Base.connection.supports_migrations?
0
+ File.open("db/#{RAILS_ENV}_structure.sql", "a") { |f| f << ActiveRecord::Base.connection.dump_schema_information }
0
+ redefine_task :clone_structure => [ "db:structure:dump", "db:test:purge" ] do
0
+ abcs = ActiveRecord::Base.configurations
0
+ ActiveRecord::Base.establish_connection(:test)
0
+ ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0') if abcs["test"]["adapter"] =~ /mysql/i
0
+ IO.readlines("db/#{RAILS_ENV}_structure.sql").join.split(";\n\n").each do |ddl|
0
+ puts "****** Executing #{ddl} *******"
0
+ ActiveRecord::Base.connection.execute(ddl)
0
+ redefine_task :purge => :environment do
0
+ abcs = ActiveRecord::Base.configurations
0
+ ActiveRecord::Base.establish_connection(:test)
0
+ db = ActiveRecord::Base.connection.database_name
0
+ ActiveRecord::Base.connection.recreate_database(db)
Comments
No one has commented yet.