module documentation

Provides the hierarchy of DDL-defining schema items as well as routines to invoke them for a create/drop call.

Class AddConstraint Represent an ALTER TABLE ADD CONSTRAINT statement.
Class BaseDDLElement The root of DDL constructs, including those that are sub-elements within the "create table" and other processes.
Class CreateColumn Represent a :class:`_schema.Column` as rendered in a CREATE TABLE statement, via the :class:`.CreateTable` construct.
Class CreateConstraint Undocumented
Class CreateIndex Represent a CREATE INDEX statement.
Class CreateSchema Represent a CREATE SCHEMA statement.
Class CreateSequence Represent a CREATE SEQUENCE statement.
Class CreateTable Represent a CREATE TABLE statement.
Class DDL A literal DDL statement.
Class DDLIf Undocumented
Class DDLIfCallable Undocumented
Class DropColumnComment Represent a COMMENT ON COLUMN IS NULL statement.
Class DropConstraint Represent an ALTER TABLE DROP CONSTRAINT statement.
Class DropConstraintComment Represent a COMMENT ON CONSTRAINT IS NULL statement.
Class DropIndex Represent a DROP INDEX statement.
Class DropSchema Represent a DROP SCHEMA statement.
Class DropSequence Represent a DROP SEQUENCE statement.
Class DropTable Represent a DROP TABLE statement.
Class DropTableComment Represent a COMMENT ON TABLE '' statement.
Class ExecutableDDLElement Base class for standalone executable DDL expression constructs.
Class InvokeCreateDDLBase No class docstring; 1/1 method documented
Class InvokeDDLBase No class docstring; 0/1 instance variable, 1/2 method documented
Class InvokeDropDDLBase No class docstring; 1/1 method documented
Class SchemaDropper Undocumented
Class SchemaGenerator Undocumented
Class SetColumnComment Represent a COMMENT ON COLUMN IS statement.
Class SetConstraintComment Represent a COMMENT ON CONSTRAINT IS statement.
Class SetTableComment Represent a COMMENT ON TABLE IS statement.
Function sort_tables Sort a collection of :class:`_schema.Table` objects based on dependency.
Function sort_tables_and_constraints Sort a collection of :class:`_schema.Table` / :class:`_schema.ForeignKeyConstraint` objects.
Class _CreateBase Undocumented
Class _CreateDropBase Base class for DDL constructs that represent CREATE and DROP or equivalents.
Class _DropBase Undocumented
Class _DropView Semi-public 'DROP VIEW' construct.

Sort a collection of :class:`_schema.Table` objects based on dependency. This is a dependency-ordered sort which will emit :class:`_schema.Table` objects such that they will follow their dependent :class:`_schema.Table` objects. Tables are dependent on another based on the presence of :class:`_schema.ForeignKeyConstraint` objects as well as explicit dependencies added by :meth:`_schema.Table.add_is_dependent_on`. .. warning:: The :func:`._schema.sort_tables` function cannot by itself accommodate automatic resolution of dependency cycles between tables, which are usually caused by mutually dependent foreign key constraints. When these cycles are detected, the foreign keys of these tables are omitted from consideration in the sort. A warning is emitted when this condition occurs, which will be an exception raise in a future release. Tables which are not part of the cycle will still be returned in dependency order. To resolve these cycles, the :paramref:`_schema.ForeignKeyConstraint.use_alter` parameter may be applied to those constraints which create a cycle. Alternatively, the :func:`_schema.sort_tables_and_constraints` function will automatically return foreign key constraints in a separate collection when cycles are detected so that they may be applied to a schema separately. .. versionchanged:: 1.3.17 - a warning is emitted when :func:`_schema.sort_tables` cannot perform a proper sort due to cyclical dependencies. This will be an exception in a future release. Additionally, the sort will continue to return other tables not involved in the cycle in dependency order which was not the case previously. :param tables: a sequence of :class:`_schema.Table` objects. :param skip_fn: optional callable which will be passed a :class:`_schema.ForeignKeyConstraint` object; if it returns True, this constraint will not be considered as a dependency. Note this is **different** from the same parameter in :func:`.sort_tables_and_constraints`, which is instead passed the owning :class:`_schema.ForeignKeyConstraint` object. :param extra_dependencies: a sequence of 2-tuples of tables which will also be considered as dependent on each other. .. seealso:: :func:`.sort_tables_and_constraints` :attr:`_schema.MetaData.sorted_tables` - uses this function to sort

def sort_tables_and_constraints(tables, filter_fn=None, extra_dependencies=None, _warn_for_cycles=False): (source)

Sort a collection of :class:`_schema.Table` / :class:`_schema.ForeignKeyConstraint` objects. This is a dependency-ordered sort which will emit tuples of ``(Table, [ForeignKeyConstraint, ...])`` such that each :class:`_schema.Table` follows its dependent :class:`_schema.Table` objects. Remaining :class:`_schema.ForeignKeyConstraint` objects that are separate due to dependency rules not satisfied by the sort are emitted afterwards as ``(None, [ForeignKeyConstraint ...])``. Tables are dependent on another based on the presence of :class:`_schema.ForeignKeyConstraint` objects, explicit dependencies added by :meth:`_schema.Table.add_is_dependent_on`, as well as dependencies stated here using the :paramref:`~.sort_tables_and_constraints.skip_fn` and/or :paramref:`~.sort_tables_and_constraints.extra_dependencies` parameters. :param tables: a sequence of :class:`_schema.Table` objects. :param filter_fn: optional callable which will be passed a :class:`_schema.ForeignKeyConstraint` object, and returns a value based on whether this constraint should definitely be included or excluded as an inline constraint, or neither. If it returns False, the constraint will definitely be included as a dependency that cannot be subject to ALTER; if True, it will **only** be included as an ALTER result at the end. Returning None means the constraint is included in the table-based result unless it is detected as part of a dependency cycle. :param extra_dependencies: a sequence of 2-tuples of tables which will also be considered as dependent on each other. .. versionadded:: 1.0.0 .. seealso:: :func:`.sort_tables`