Sha256: 54ba078c0d16954aefdc7eaae4a0d56c23b40fa36b64c415f91302e2885f6095
Contents?: true
Size: 1.7 KB
Versions: 3
Compression:
Stored size: 1.7 KB
Contents
namespace :datashift do namespace :db do SYSTEM_TABLE_EXCLUSION_LIST = ['schema_migrations'].freeze 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".tr('\\', '-') `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
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
datashift-0.40.3 | lib/tasks/to_convert_to_thor/db_tasks.rake |
datashift-0.40.1 | lib/tasks/to_convert_to_thor/db_tasks.rake |
datashift-0.40.0 | lib/tasks/to_convert_to_thor/db_tasks.rake |