lib/wyrm/schema_tools.rb
# Delete given tables.
# Recurse if there are foreign keys preventing table deletion.
# This implementation will fail for tables with mutual foreign keys.
# TODO maybe this should use the schema down migration?
Delete given tables.
Recurse if there are foreign keys preventing table deletion.
This implementation will fail for tables with mutual foreign keys.
Delete given tables . Recurse if there are foreign keys preventing table deletion . This implementation will fail for tables with mutual foreign keys .
def drop_tables( tables )
      foreign_keyed_tables = []
      tables.each do |table_name|
        begin
          logger.debug "dropping #{table_name}"
          dst_db.drop_table? table_name, drop_table_options
        rescue Sequel::ForeignKeyConstraintViolation => ex
          foreign_keyed_tables << table_name
        rescue Sequel::DatabaseError => ex
          if ex.message =~ /foreign key constraint fail/i
            foreign_keyed_tables << table_name
          else
            raise
          end
        end
      end
      if tables.any? && tables.sort == foreign_keyed_tables.sort
        raise "can't remove #{tables.inspect} because they have mutual foreign keys"
      end
      drop_tables foreign_keyed_tables.shuffle unless foreign_keyed_tables.empty?
    end
def drop_tables ( tables ) foreign_keyed_tables = [ ] tables . each do | table_name | begin logger . debug "dropping #{table_name}" dst_db . drop_table? table_name , drop_table_options rescue Sequel :: ForeignKeyConstraintViolation => ex foreign_keyed_tables << table_name rescue Sequel :: DatabaseError => ex if ex . message =~ / foreign key constraint fail /i foreign_keyed_tables << table_name else raise end end end if tables . any? && tables . sort == foreign_keyed_tables . sort raise "can't remove #{tables.inspect} because they have mutual foreign keys" end drop_tables foreign_keyed_tables . shuffle unless foreign_keyed_tables . empty? end
Delete given tables.
Delete given tables .
# Mysql2::Error: Cannot delete or update a parent row: a foreign key constraint fails # SQLite3::ConstraintException: FOREIGN KEY constraint failed== # this should be temporary # recursively delete tables. Shuffle as kak workaround for dependency loops.
tables
<not_specific>