Sha256: a9440db6b7eb30e536b5e6a45f92e9e77be0b5d2efc2cfa665a49b74ce3f2cc5

Contents?: true

Size: 1.7 KB

Versions: 13

Compression:

Stored size: 1.7 KB

Contents

namespace :datashift  do
  
  namespace :db  do

    SYSTEM_TABLE_EXCLUSION_LIST = ['schema_migrations']

    desc "Purge the current database"
    task :purge, [:exclude_system_tables] => [:environment] do |t, args|
      require 'highline/import'

      if(Rails.env.production?)
        agree("WARNING: In Production database, REALLY PURGE ? [y]:")
      end

      config = ActiveRecord::Base.configurations[Rails.env || 'development']
      case config['adapter']
      when "mysql", "mysql2", "jdbcmysql"
        ActiveRecord::Base.establish_connection(config)
        ActiveRecord::Base.connection.tables.each do |table|
          next if(args[:exclude_system_tables] && SYSTEM_TABLE_EXCLUSION_LIST.include?(table) )
          puts "purging table: #{table}"
          ActiveRecord::Base.connection.execute("TRUNCATE #{table}")
        end
      when "sqlite","sqlite3"
        dbfile = config["database"] || config["dbfile"]
        File.delete(dbfile) if File.exist?(dbfile)
      when "sqlserver"
        dropfkscript = "#{config["host"]}.#{config["database"]}.DP1".gsub(/\\/,'-')
        `osql -E -S #{config["host"]} -d #{config["database"]} -i db\\#{dropfkscript}`
        `osql -E -S #{config["host"]} -d #{config["database"]} -i db\\#{Rails.env}_structure.sql`
      when "oci", "oracle"
        ActiveRecord::Base.establish_connection(config)
        ActiveRecord::Base.connection.structure_drop.split(";\n\n").each do |ddl|
          ActiveRecord::Base.connection.execute(ddl)
        end
      when "firebird"
        ActiveRecord::Base.establish_connection(config)
        ActiveRecord::Base.connection.recreate_database!
      else
        raise "Task not supported by '#{config["adapter"]}'"
      end
    end

  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
datashift-0.16.0 tasks/db_tasks.rake
datashift-0.15.0 tasks/db_tasks.rake
datashift-0.14.0 tasks/db_tasks.rake
datashift-0.13.0 tasks/db_tasks.rake
datashift-0.12.1 tasks/db_tasks.rake
datashift-0.12.0 tasks/db_tasks.rake
datashift-0.11.1 tasks/db_tasks.rake
datashift-0.11.0 tasks/db_tasks.rake
datashift-0.10.2 tasks/db_tasks.rake
datashift-0.10.1 tasks/db_tasks.rake
datashift-0.10.0 tasks/db_tasks.rake
datashift-0.9.0 tasks/db_tasks.rake
datashift-0.8.0 tasks/db_tasks.rake