Sha256: 6e799ac25607bf81277104d8226d71a702d5a24ecc2f42c4acfacbc7cc1c1127

Contents?: true

Size: 1.59 KB

Versions: 8

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)
      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)
      end
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
activerecord-oracle_enhanced-adapter-1.1.0 lib/active_record/connection_adapters/oracle_enhanced.rake
activerecord-oracle_enhanced-adapter-1.1.1 lib/active_record/connection_adapters/oracle_enhanced.rake
activerecord-oracle_enhanced-adapter-1.1.2 lib/active_record/connection_adapters/oracle_enhanced.rake
activerecord-oracle_enhanced-adapter-1.1.3 lib/active_record/connection_adapters/oracle_enhanced.rake
activerecord-oracle_enhanced-adapter-1.1.4 lib/active_record/connection_adapters/oracle_enhanced.rake
activerecord-oracle_enhanced-adapter-1.1.5 lib/active_record/connection_adapters/oracle_enhanced.rake
activerecord-oracle_enhanced-adapter-1.1.6 lib/active_record/connection_adapters/oracle_enhanced.rake
activerecord-oracle_enhanced-adapter-1.1.7 lib/active_record/connection_adapters/oracle_enhanced.rake