Sha256: f9a9ed9bdaa3f217df776923e2b0193c93b2a2a186592cfdbc49363adaac628c

Contents?: true

Size: 1.59 KB

Versions: 20

Compression:

Stored size: 1.59 KB

Contents

# RSI: implementation idea taken from JDBC adapter
def redefine_task(*args, &block)
  task_name = Hash === args.first ? args.first.keys[0] : args.first
  existing_task = Rake.application.lookup task_name
  if existing_task
    class << existing_task; public :instance_variable_set; end
    existing_task.instance_variable_set "@prerequisites", FileList[]
    existing_task.instance_variable_set "@actions", []
  end
  task(*args, &block)
end

namespace :db do

  namespace :structure do
    redefine_task :dump => :environment do
      abcs = ActiveRecord::Base.configurations
      ActiveRecord::Base.establish_connection(abcs[RAILS_ENV])
      File.open("db/#{RAILS_ENV}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump }
      if ActiveRecord::Base.connection.supports_migrations?
        File.open("db/#{RAILS_ENV}_structure.sql", "a") { |f| f << ActiveRecord::Base.connection.dump_schema_information }
      end
    end
  end

  namespace :test do
    redefine_task :clone_structure => [ "db:structure:dump", "db:test:purge" ] do
      abcs = ActiveRecord::Base.configurations
      ActiveRecord::Base.establish_connection(:test)
      IO.readlines("db/#{RAILS_ENV}_structure.sql").join.split("\n\n").each do |ddl|
        ActiveRecord::Base.connection.execute(ddl.chop)
      end
    end

    redefine_task :purge => :environment do
      abcs = ActiveRecord::Base.configurations
      ActiveRecord::Base.establish_connection(:test)
      ActiveRecord::Base.connection.structure_drop.split("\n\n").each do |ddl|
        ActiveRecord::Base.connection.execute(ddl.chop)
      end
    end

  end
end

Version data entries

20 entries across 20 versions & 6 rubygems

Version Path
rsim-activerecord-oracle_enhanced-adapter-1.1.9.90 lib/active_record/connection_adapters/oracle_enhanced.rake
rsim-activerecord-oracle_enhanced-adapter-1.1.9.91 lib/active_record/connection_adapters/oracle_enhanced.rake
rsim-activerecord-oracle_enhanced-adapter-1.1.9.92 lib/active_record/connection_adapters/oracle_enhanced.rake
rsim-activerecord-oracle_enhanced-adapter-1.1.9.93 lib/active_record/connection_adapters/oracle_enhanced.rake
rsim-activerecord-oracle_enhanced-adapter-1.2.0.1 lib/active_record/connection_adapters/oracle_enhanced.rake
rsim-activerecord-oracle_enhanced-adapter-1.2.0.2 lib/active_record/connection_adapters/oracle_enhanced.rake
rsim-activerecord-oracle_enhanced-adapter-1.2.0 lib/active_record/connection_adapters/oracle_enhanced.rake
rwc9u-activerecord-oracle_enhanced-adapter-1.1.9.3 lib/active_record/connection_adapters/oracle_enhanced.rake
rwc9u-activerecord-oracle_enhanced-adapter-1.1.9.4 lib/active_record/connection_adapters/oracle_enhanced.rake
rwc9u-activerecord-oracle_enhanced-adapter-1.1.9.5 lib/active_record/connection_adapters/oracle_enhanced.rake
rwc9u-activerecord-oracle_enhanced-adapter-1.2.0 lib/active_record/connection_adapters/oracle_enhanced.rake
rwc9u-oracle-enhanced-1.1.9.4 lib/active_record/connection_adapters/oracle_enhanced.rake
saberma-activerecord-oracle_enhanced-adapter-nvarchar2-1.2.1.1 lib/active_record/connection_adapters/oracle_enhanced.rake
saberma-activerecord-oracle_enhanced-adapter-nvarchar2-1.2.1.2 lib/active_record/connection_adapters/oracle_enhanced.rake
saberma-activerecord-oracle_enhanced-adapter-nvarchar2-1.2.1 lib/active_record/connection_adapters/oracle_enhanced.rake
saberma-saberma-activerecord-oracle_enhanced-adapter-nvarchar2-1.2.1 lib/active_record/connection_adapters/oracle_enhanced.rake
activerecord-oracle_enhanced-adapter-1.1.9 lib/active_record/connection_adapters/oracle_enhanced.rake
activerecord-oracle_enhanced-adapter-1.1.8 lib/active_record/connection_adapters/oracle_enhanced.rake
activerecord-oracle_enhanced-adapter-1.2.0 lib/active_record/connection_adapters/oracle_enhanced.rake
activerecord-oracle_enhanced-adapter-1.2.1 lib/active_record/connection_adapters/oracle_enhanced.rake