Sha256: 3708fb7f17ee2597498e6af9d146c852c6419fabbff7bcb66d31f3c017e9bdea
Contents?: true
Size: 1.2 KB
Versions: 4
Compression:
Stored size: 1.2 KB
Contents
require 'database_cleaner/sequel/truncation' module DatabaseCleaner module Sequel class Deletion < Truncation def disable_referential_integrity(tables) case db.database_type when :postgres db.run('SET CONSTRAINTS ALL DEFERRED') tables_to_truncate(db).each do |table| db.run("ALTER TABLE \"#{table}\" DISABLE TRIGGER ALL") end when :mysql old = db.fetch('SELECT @@FOREIGN_KEY_CHECKS').first[:@@FOREIGN_KEY_CHECKS] db.run('SET FOREIGN_KEY_CHECKS = 0') end yield ensure case db.database_type when :postgres tables.each do |table| db.run("ALTER TABLE \"#{table}\" ENABLE TRIGGER ALL") end when :mysql db.run("SET FOREIGN_KEY_CHECKS = #{old}") end end def delete_tables(db, tables) tables.each do |table| db[table.to_sym].delete end end def clean return unless dirty? tables = tables_to_truncate(db) db.transaction do disable_referential_integrity(tables) do delete_tables(db, tables) end end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems