MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / SchemaDropper

Class SchemaDropper

lib/sqlalchemy/sql/ddl.py:1523–1708  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1521
1522
1523class SchemaDropper(InvokeDropDDLBase):
1524 def __init__(
1525 self,
1526 dialect,
1527 connection,
1528 checkfirst=CheckFirst.NONE,
1529 tables=None,
1530 **kwargs,
1531 ):
1532 super().__init__(connection, **kwargs)
1533 self.checkfirst = CheckFirst(checkfirst)
1534 self.tables = tables
1535 self.preparer = dialect.identifier_preparer
1536 self.dialect = dialect
1537 self.memo = {}
1538
1539 def visit_metadata(self, metadata):
1540 if self.tables is not None:
1541 tables = self.tables
1542 else:
1543 tables = list(metadata.tables.values())
1544
1545 try:
1546 unsorted_tables = [t for t in tables if self._can_drop_table(t)]
1547 collection = list(
1548 reversed(
1549 sort_tables_and_constraints(
1550 unsorted_tables,
1551 filter_fn=lambda constraint: (
1552 False
1553 if not self.dialect.supports_alter
1554 or constraint.name is None
1555 else None
1556 ),
1557 )
1558 )
1559 )
1560 except exc.CircularDependencyError as err2:
1561 if not self.dialect.supports_alter:
1562 util.warn(
1563 "Can't sort tables for DROP; an "
1564 "unresolvable foreign key "
1565 "dependency exists between tables: %s; and backend does "
1566 "not support ALTER. To restore at least a partial sort, "
1567 "apply use_alter=True to ForeignKey and "
1568 "ForeignKeyConstraint "
1569 "objects involved in the cycle to mark these as known "
1570 "cycles that will be ignored."
1571 % (", ".join(sorted([t.fullname for t in err2.cycles])))
1572 )
1573 collection = [(t, ()) for t in unsorted_tables]
1574 else:
1575 raise exc.CircularDependencyError(
1576 err2.args[0],
1577 err2.cycles,
1578 err2.edges,
1579 msg="Can't sort tables for DROP; an "
1580 "unresolvable foreign key "

Callers 1

_mock_drop_fixtureMethod · 0.90

Calls

no outgoing calls

Tested by 1

_mock_drop_fixtureMethod · 0.72