Sh3ll
OdayForums


Server : LiteSpeed
System : Linux premium84.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
User : claqxcrl ( 523)
PHP Version : 8.1.32
Disable Function : NONE
Directory :  /opt/hc_python/lib64/python3.12/site-packages/sqlalchemy/sql/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //opt/hc_python/lib64/python3.12/site-packages/sqlalchemy/sql/__pycache__/ddl.cpython-312.pyc
�

���gF�����dZddlmZddlZddlZddlmZddlmZddlmZddlmZddlm	Z	dd	lm
Zdd
lmZddl
mZdd
lmZddlmZddlmZddlmZddl
mZddl
mZddlmZddlmZddlmZej6rTddlmZddlmZddlmZddl m!Z!ddl m"Z"ddl m#Z#dd	l m
Z
ddl m$Z$ddl%m&Z&ddl'm(Z(dd l)m*Z*dd!l)m+Z+dd"l)m,Z,dd#l)m-Z-Gd$�d%e�Z.Gd&�d'e�Z/Gd(�d)ej`�Z1Gd*�d+ejdee.�Z3e3Z4	Gd,�d-e3�Z5Gd.�d/e3�Z6Gd0�d1e6�Z7Gd2�d3e6�Z8Gd4�d5e7�Z9Gd6�d7e8�Z:Gd8�d9e7�Z;Gd:�d;e8�Z<Gd<�d=e.�Z=Gd>�d?e.�Z>Gd@�dAe8�Z?GdB�dCe7�Z@GdD�dEe8�ZAGdF�dGe7�ZBGdH�dIe8�ZCGdJ�dKe7�ZDGdL�dMe8�ZEGdN�dOe6�ZFGdP�dQe6�ZGGdR�dSe6�ZHGdT�dUe6�ZIGdV�dWe6�ZJGdX�dYe6�ZKGdZ�d[e�ZLGd\�d]eL�ZMGd^�d_eL�ZNGd`�daeM�ZOGdb�dceN�ZP		df							dgdd�ZQ	dhde�ZRy)izq
Provides the hierarchy of DDL-defining schema items as well as routines
to invoke them for a create/drop call.

�)�annotationsN)�Any)�Callable)�Iterable)�List)�Optional)�Sequence)�Tuple�)�roles)�_generative)�
Executable)�
SchemaVisitor)�
ClauseElement�)�exc)�util)�topological)�Protocol)�Self)�Compiled)�DDLCompiler)�
BindParameter)�
Constraint)�ForeignKeyConstraint)�
SchemaItem)�Table)�TableClause)�
Connection)�
CacheStats)�CompiledCacheType)�Dialect)�SchemaTranslateMapTypec�F�eZdZdZdZ	d�Zddd�													dd�Zy)�BaseDDLElementz�The root of DDL constructs, including those that are sub-elements
    within the "create table" and other processes.

    .. versionadded:: 2.0

    Fc�*�|j||fi|��S)zNReturn a compiler appropriate for this ClauseElement, given a
        Dialect.)�ddl_compiler)�self�dialect�kws   �C/opt/hc_python/lib64/python3.12/site-packages/sqlalchemy/sql/ddl.py�	_compilerzBaseDDLElement._compilerAs��$�w�#�#�G�T�8�R�8�8�N)�for_executemany�schema_translate_mapc��t���N��NotImplementedError)r(r)�compiled_cache�column_keysr.r/r*s       r+�_compile_w_cachezBaseDDLElement._compile_w_cacheGs
��"�#�#r-)r)r"r4zOptional[CompiledCacheType]r5z	List[str]r.�boolr/z Optional[SchemaTranslateMapType]r*r�returnzJTuple[Compiled, Optional[typing_Sequence[BindParameter[Any]]], CacheStats])�__name__�
__module__�__qualname__�__doc__�_hierarchy_supports_cachingr,r6�r-r+r%r%6sh���#(��B�9�!&�AE�$��$�4�	$�
�$��
$�?�$��$�
�$r-r%c�B�eZdZ		ddd�																	dd�Zy)�
DDLIfCallableN.)�compilerc��yr1r>)	r(�ddl�target�bind�tables�stater)rA�
checkfirsts	         r+�__call__zDDLIfCallable.__call__Ws��r-�NN)rCr%rDrrE�Optional[Connection]rFzOptional[List[Table]]rG�
Optional[Any]r)r"rA�Optional[DDLCompiler]rHr7r8r7)r9r:r;rIr>r-r+r@r@Vsq��)-�#�
�+.��
����#�	�
&���
���(����
�r-r@c�N�eZdZUded<ded<ded<	d												d
d�Zy)�DDLIf�
Optional[str]r)�Optional[DDLIfCallable]�	callable_rLrGNc��|�
|j}n|�
|j}nJd��t|jt�r|j|jk7r?yt|jtt
tf�r|j|jvry|j�$|j|||f|j||d�|��syy)NFzcompiler or dialect is required)rGr)rAT)	r)�
isinstance�str�name�tuple�list�setrRrG)r(rCrDrErAr*r)s       r+�_should_executezDDLIf._should_executejs������l�l�G�
�
!��&�&�G�;�;�;�5��d�l�l�C�(��|�|�w�|�|�+��
����u�d�C�&8�
9��|�|�4�<�<�/���>�>�%�n�d�n�n����/
��*�*���
/
��/
��r-r1)rCr%rDrrErKrArMr*rr8r7)r9r:r;�__annotations__rZr>r-r+rOrOesX��
��&�&���+/� �
� �� �#�	 �
(� ��
 �
� r-rOc��eZdZUdZdZded<dZded<d�Zedd��Z	e			d							dd	��Z
d
�Zd�Zd�Z
d
�Zy)�ExecutableDDLElementa�Base class for standalone executable DDL expression constructs.

    This class is the base for the general purpose :class:`.DDL` class,
    as well as the various create/drop clause constructs such as
    :class:`.CreateTable`, :class:`.DropTable`, :class:`.AddConstraint`,
    etc.

    .. versionchanged:: 2.0  :class:`.ExecutableDDLElement` is renamed from
       :class:`.DDLElement`, which still exists for backwards compatibility.

    :class:`.ExecutableDDLElement` integrates closely with SQLAlchemy events,
    introduced in :ref:`event_toplevel`.  An instance of one is
    itself an event receiving callable::

        event.listen(
            users,
            "after_create",
            AddConstraint(constraint).execute_if(dialect="postgresql"),
        )

    .. seealso::

        :class:`.DDL`

        :class:`.DDLEvents`

        :ref:`event_toplevel`

        :ref:`schema_ddl_sequences`

    NzOptional[DDLIf]�_ddl_ifzOptional[SchemaItem]rDc�(�|j|||�Sr1)�_execute_ddl)r(�
connection�distilled_params�execution_optionss    r+�_execute_on_connectionz+ExecutableDDLElement._execute_on_connection�s ���&�&��"�$5�
�	
r-c��||_|S)a�Return a copy of this :class:`_schema.ExecutableDDLElement` which
        will include the given target.

        This essentially applies the given item to the ``.target`` attribute of
        the returned :class:`_schema.ExecutableDDLElement` object. This target
        is then usable by event handlers and compilation routines in order to
        provide services such as tokenization of a DDL string in terms of a
        particular :class:`_schema.Table`.

        When a :class:`_schema.ExecutableDDLElement` object is established as
        an event handler for the :meth:`_events.DDLEvents.before_create` or
        :meth:`_events.DDLEvents.after_create` events, and the event then
        occurs for a given target such as a :class:`_schema.Constraint` or
        :class:`_schema.Table`, that target is established with a copy of the
        :class:`_schema.ExecutableDDLElement` object using this method, which
        then proceeds to the :meth:`_schema.ExecutableDDLElement.execute`
        method in order to invoke the actual DDL instruction.

        :param target: a :class:`_schema.SchemaItem` that will be the subject
         of a DDL operation.

        :return: a copy of this :class:`_schema.ExecutableDDLElement` with the
         ``.target`` attribute assigned to the given
         :class:`_schema.SchemaItem`.

        .. seealso::

            :class:`_schema.DDL` - uses tokenization against the "target" when
            processing the DDL string.

        )rD)r(rDs  r+�againstzExecutableDDLElement.against�s��B����r-c�*�t|||�|_|S)aA
Return a callable that will execute this
        :class:`_ddl.ExecutableDDLElement` conditionally within an event
        handler.

        Used to provide a wrapper for event listening::

            event.listen(
                metadata,
                "before_create",
                DDL("my_ddl").execute_if(dialect="postgresql"),
            )

        :param dialect: May be a string or tuple of strings.
          If a string, it will be compared to the name of the
          executing database dialect::

            DDL("something").execute_if(dialect="postgresql")

          If a tuple, specifies multiple dialect names::

            DDL("something").execute_if(dialect=("postgresql", "mysql"))

        :param callable\_: A callable, which will be invoked with
          three positional arguments as well as optional keyword
          arguments:

            :ddl:
              This DDL element.

            :target:
              The :class:`_schema.Table` or :class:`_schema.MetaData`
              object which is the
              target of this event. May be None if the DDL is executed
              explicitly.

            :bind:
              The :class:`_engine.Connection` being used for DDL execution.
              May be None if this construct is being created inline within
              a table, in which case ``compiler`` will be present.

            :tables:
              Optional keyword argument - a list of Table objects which are to
              be created/ dropped within a MetaData.create_all() or drop_all()
              method call.

            :dialect: keyword argument, but always present - the
              :class:`.Dialect` involved in the operation.

            :compiler: keyword argument.  Will be ``None`` for an engine
              level DDL invocation, but will refer to a :class:`.DDLCompiler`
              if this DDL element is being created inline within a table.

            :state:
              Optional keyword argument - will be the ``state`` argument
              passed to this function.

            :checkfirst:
             Keyword argument, will be True if the 'checkfirst' flag was
             set during the call to ``create()``, ``create_all()``,
             ``drop()``, ``drop_all()``.

          If the callable returns a True value, the DDL statement will be
          executed.

        :param state: any value which will be passed to the callable\_
          as the ``state`` keyword argument.

        .. seealso::

            :meth:`.SchemaItem.ddl_if`

            :class:`.DDLEvents`

            :ref:`event_toplevel`

        )rOr^)r(r)rRrGs    r+�
execute_ifzExecutableDDLElement.execute_if�s��f�W�i��7����r-c�Z�|j�y|jj|||fi|��S�NT)r^rZ�r(rDrEr*s    r+rZz$ExecutableDDLElement._should_execute2s/���<�<���/�4�<�<�/�/��f�d�I�b�I�Ir-c�^�|j|j|�r|j|�Syr1)rZrD�execute)r(rEs  r+�_invoke_withz!ExecutableDDLElement._invoke_with8s*��������T�2��<�<��%�%�3r-c�D�|j|�j|�y)z"Execute the DDL as a ddl_listener.N)rfrnrks    r+rIzExecutableDDLElement.__call__<s��	
���V��)�)�$�/r-c��|jj|j�}|jj�|_|Sr1)�	__class__�__new__�__dict__�copy)r(�ss  r+�	_generatezExecutableDDLElement._generateAs3���N�N�"�"�4�>�>�2���]�]�'�'�)��
��r-)rDrr8r)NNN)r)rPrRrQrGrLr8r)r9r:r;r<r^r[rDrdr
rfrhrZrnrIrvr>r-r+r]r]�s����@ $�G�_�#�#'�F� �'�
��!��!�F�"&�-1�#�	S��S�+�S��	S�

�S��S�jJ�&�0�
r-r]c�"�eZdZdZdZdd�Zd�Zy)�DDLaZA literal DDL statement.

    Specifies literal SQL DDL to be executed by the database.  DDL objects
    function as DDL event listeners, and can be subscribed to those events
    listed in :class:`.DDLEvents`, using either :class:`_schema.Table` or
    :class:`_schema.MetaData` objects as targets.
    Basic templating support allows
    a single DDL instance to handle repetitive tasks for multiple tables.

    Examples::

      from sqlalchemy import event, DDL

      tbl = Table("users", metadata, Column("uid", Integer))
      event.listen(tbl, "before_create", DDL("DROP TRIGGER users_trigger"))

      spow = DDL("ALTER TABLE %(table)s SET secretpowers TRUE")
      event.listen(tbl, "after_create", spow.execute_if(dialect="somedb"))

      drop_spow = DDL("ALTER TABLE users SET secretpowers FALSE")
      connection.execute(drop_spow)

    When operating on Table events, the following ``statement``
    string substitutions are available:

    .. sourcecode:: text

      %(table)s  - the Table name, with any required quoting applied
      %(schema)s - the schema name, with any required quoting applied
      %(fullname)s - the Table name including schema, quoted if needed

    The DDL's "context", if any, will be combined with the standard
    substitutions noted above.  Keys present in the context will override
    the standard substitutions.

    rCNc�x�t|t�stjd|z��||_|xsi|_y)a�Create a DDL statement.

        :param statement:
          A string or unicode string to be executed.  Statements will be
          processed with Python's string formatting operator using
          a fixed set of string substitutions, as well as additional
          substitutions provided by the optional :paramref:`.DDL.context`
          parameter.

          A literal '%' in a statement must be escaped as '%%'.

          SQL bind parameters are not available in DDL statements.

        :param context:
          Optional dictionary, defaults to None.  These values will be
          available for use in string substitutions on the DDL statement.

        .. seealso::

            :class:`.DDLEvents`

            :ref:`event_toplevel`

        z4Expected a string or unicode SQL statement, got '%r'N)rTrUr�
ArgumentError�	statement�context)r(r{r|s   r+�__init__zDDL.__init__ss@��4�)�S�)��#�#�F����
�
#����}�"��r-c���t|j�g}|jr|jd|j���dt	|�j
�dt
|��ddj|��d�S)Nzcontext=�<�@z; �, �>)�reprr{r|�append�typer9�id�join)r(�partss  r+�__repr__zDDL.__repr__�s^���d�n�n�%�&���<�<��L�L�8�D�L�L�>�2�3��
��J����t�H��I�I�e��
�	
r-r1)r9r:r;r<�__visit_name__r}r�r>r-r+rxrxKs��#�J�N�!%�F	
r-rxc�,�eZdZdZd�Zed��Zd�Zy)�_CreateDropBasez�Base class for DDL constructs that represent CREATE and DROP or
    equivalents.

    The common theme of _CreateDropBase is a single
    ``element`` attribute which refers to the element
    to be created or dropped.

    c�D�|x|_|_t|dd�|_y)Nr^)�elementrD�getattrr^�r(r�s  r+r}z_CreateDropBase.__init__�s"��&-�,���t�{��w�	�4�8��r-c�.�|jjSr1)r��create_drop_stringify_dialect)r(s r+�stringify_dialectz!_CreateDropBase.stringify_dialect�s���|�|�9�9�9r-c��y)z�Allow disable of _create_rule using a callable.

        Pass to _create_rule using
        util.portable_instancemethod(self._create_rule_disable)
        to retain serializability.

        Fr>)r(rAs  r+�_create_rule_disablez$_CreateDropBase._create_rule_disable�s��r-N)r9r:r;r<r}�propertyr�r�r>r-r+r�r��s%���9��:��:�r-r�c� ��eZdZd�fd�	Z�xZS)�_CreateBasec�2��t�|�|�||_yr1)�superr}�
if_not_exists�r(r�r�rqs   �r+r}z_CreateBase.__init__�s���
����!�*��r-�F�r9r:r;r}�
__classcell__�rqs@r+r�r��s
���+�+r-r�c� ��eZdZd�fd�	Z�xZS)�	_DropBasec�2��t�|�|�||_yr1)r�r}�	if_exists�r(r�r�rqs   �r+r}z_DropBase.__init__�s���
����!�"��r-r�r�r�s@r+r�r��s
���#�#r-r�c�6��eZdZdZdZdZ	d			d�fd�
Z�xZS)�CreateSchemazcRepresent a CREATE SCHEMA statement.

    The argument here is the string name of the schema.

    �
create_schema�defaultc�(��t�|�||��y)z.Create a new :class:`.CreateSchema` construct.)r�r�N�r�r})r(rVr�rqs   �r+r}zCreateSchema.__init__�s���	����]��Cr-r�)rVrUr�r7�r9r:r;r<r�r�r}r�r�s@r+r�r��s:����%�N�!��
$�D��D��D�Dr-r�c�<��eZdZdZdZdZ		d					d�fd�
Z�xZS)�
DropSchemazaRepresent a DROP SCHEMA statement.

    The argument here is the string name of the schema.

    �drop_schemar�c�6��t�|�||��||_y)z,Create a new :class:`.DropSchema` construct.)r�r�N)r�r}�cascade)r(rVr�r�rqs    �r+r}zDropSchema.__init__�s���	������;���r-)FF)rVrUr�r7r�r7r�r�s@r+r�r��sC����#�N�!��
��		��	��	��		�	r-r�c�8��eZdZdZdZ		d					d�fd�
Z�xZS)�CreateTablez#Represent a CREATE TABLE statement.�create_tablec���t�|�||��|jD�cgc]
}t|���c}|_||_ycc}w)a�Create a :class:`.CreateTable` construct.

        :param element: a :class:`_schema.Table` that's the subject
         of the CREATE
        :param on: See the description for 'on' in :class:`.DDL`.
        :param include_foreign_key_constraints: optional sequence of
         :class:`_schema.ForeignKeyConstraint` objects that will be included
         inline within the CREATE construct; if omitted, all foreign key
         constraints that do not specify use_alter=True are included.

        :param if_not_exists: if True, an IF NOT EXISTS operator will be
         applied to the construct.

         .. versionadded:: 1.4.0b2

        �r�N)r�r}�columns�CreateColumn�include_foreign_key_constraints)r(r�r�r��columnrqs     �r+r}zCreateTable.__init__�sD���0	����
��>�;B�?�?�K�?���V�,�?�K���/N��,��Ls�A�NF)r�rr�z/Optional[typing_Sequence[ForeignKeyConstraint]]r�r7�r9r:r;r<r�r}r�r�s@r+r�r��s>���-�#�N�
�#�
O��O�*
�O��
O�Or-r�c��eZdZdZdZy)�	_DropViewz�Semi-public 'DROP VIEW' construct.

    Used by the test suite for dialect-agnostic drops of views.
    This object will eventually be part of a public "view" API.

    �	drop_viewN�r9r:r;r<r�r>r-r+r�r�s���!�Nr-r�c��eZdZdd�Zy)�CreateConstraintc��||_yr1�r�r�s  r+r}zCreateConstraint.__init__(�	����r-N)r�r)r9r:r;r}r>r-r+r�r�'s��r-r�c��eZdZdZdZd�Zy)r�a�Represent a :class:`_schema.Column`
    as rendered in a CREATE TABLE statement,
    via the :class:`.CreateTable` construct.

    This is provided to support custom column DDL within the generation
    of CREATE TABLE statements, by using the
    compiler extension documented in :ref:`sqlalchemy.ext.compiler_toplevel`
    to extend :class:`.CreateColumn`.

    Typical integration is to examine the incoming :class:`_schema.Column`
    object, and to redirect compilation if a particular flag or condition
    is found::

        from sqlalchemy import schema
        from sqlalchemy.ext.compiler import compiles


        @compiles(schema.CreateColumn)
        def compile(element, compiler, **kw):
            column = element.element

            if "special" not in column.info:
                return compiler.visit_create_column(element, **kw)

            text = "%s SPECIAL DIRECTIVE %s" % (
                column.name,
                compiler.type_compiler.process(column.type),
            )
            default = compiler.get_column_default_string(column)
            if default is not None:
                text += " DEFAULT " + default

            if not column.nullable:
                text += " NOT NULL"

            if column.constraints:
                text += " ".join(
                    compiler.process(const) for const in column.constraints
                )
            return text

    The above construct can be applied to a :class:`_schema.Table`
    as follows::

        from sqlalchemy import Table, Metadata, Column, Integer, String
        from sqlalchemy import schema

        metadata = MetaData()

        table = Table(
            "mytable",
            MetaData(),
            Column("x", Integer, info={"special": True}, primary_key=True),
            Column("y", String(50)),
            Column("z", String(20), info={"special": True}),
        )

        metadata.create_all(conn)

    Above, the directives we've added to the :attr:`_schema.Column.info`
    collection
    will be detected by our custom compilation scheme:

    .. sourcecode:: sql

        CREATE TABLE mytable (
                x SPECIAL DIRECTIVE INTEGER NOT NULL,
                y VARCHAR(50),
                z SPECIAL DIRECTIVE VARCHAR(20),
            PRIMARY KEY (x)
        )

    The :class:`.CreateColumn` construct can also be used to skip certain
    columns when producing a ``CREATE TABLE``.  This is accomplished by
    creating a compilation rule that conditionally returns ``None``.
    This is essentially how to produce the same effect as using the
    ``system=True`` argument on :class:`_schema.Column`, which marks a column
    as an implicitly-present "system" column.

    For example, suppose we wish to produce a :class:`_schema.Table`
    which skips
    rendering of the PostgreSQL ``xmin`` column against the PostgreSQL
    backend, but on other backends does render it, in anticipation of a
    triggered rule.  A conditional compilation rule could skip this name only
    on PostgreSQL::

        from sqlalchemy.schema import CreateColumn


        @compiles(CreateColumn, "postgresql")
        def skip_xmin(element, compiler, **kw):
            if element.element.name == "xmin":
                return None
            else:
                return compiler.visit_create_column(element, **kw)


        my_table = Table(
            "mytable",
            metadata,
            Column("id", Integer, primary_key=True),
            Column("xmin", Integer),
        )

    Above, a :class:`.CreateTable` construct will generate a ``CREATE TABLE``
    which only includes the ``id`` column in the string; the ``xmin`` column
    will be omitted, but only against the PostgreSQL backend.

    �
create_columnc��||_yr1r�r�s  r+r}zCreateColumn.__init__�r�r-N)r9r:r;r<r�r}r>r-r+r�r�,s��l�\%�N�r-r�c�*��eZdZdZdZdd�fd�
Z�xZS)�	DropTablez!Represent a DROP TABLE statement.�
drop_tablec�(��t�|�||��y)aVCreate a :class:`.DropTable` construct.

        :param element: a :class:`_schema.Table` that's the subject
         of the DROP.
        :param on: See the description for 'on' in :class:`.DDL`.
        :param if_exists: if True, an IF EXISTS operator will be applied to the
         construct.

         .. versionadded:: 1.4.0b2

        �r�Nr�r�s   �r+r}zDropTable.__init__�s���	����I��6r-r�)r�rr�r7r�r�s@r+r�r��s���+�!�N�7�7r-r�c�*��eZdZdZdZdd�fd�
Z�xZS)�CreateSequencez&Represent a CREATE SEQUENCE statement.�create_sequencec�(��t�|�||��y)Nr�r�r�s   �r+r}zCreateSequence.__init__�s���
����
��>r-r�)r�r	r�r7r�r�s@r+r�r��s���0�&�N�?�?r-r�c�*��eZdZdZdZdd�fd�
Z�xZS)�DropSequencez$Represent a DROP SEQUENCE statement.�
drop_sequencec�(��t�|�||��y)Nr�r�r�s   �r+r}zDropSequence.__init__�s���
����I��6r-r�)r�r	r�r7r�r�s@r+r�r��s���.�$�N�7�7r-r�c�(��eZdZdZdZd�fd�	Z�xZS)�CreateIndexz#Represent a CREATE INDEX statement.�create_indexc�(��t�|�||��y)a Create a :class:`.Createindex` construct.

        :param element: a :class:`_schema.Index` that's the subject
         of the CREATE.
        :param if_not_exists: if True, an IF NOT EXISTS operator will be
         applied to the construct.

         .. versionadded:: 1.4.0b2

        r�Nr�r�s   �r+r}zCreateIndex.__init__�s���	����
��>r-r�r�r�s@r+r�r��s���-�#�N�?�?r-r�c�(��eZdZdZdZd�fd�	Z�xZS)�	DropIndexz!Represent a DROP INDEX statement.�
drop_indexc�(��t�|�||��y)aCreate a :class:`.DropIndex` construct.

        :param element: a :class:`_schema.Index` that's the subject
         of the DROP.
        :param if_exists: if True, an IF EXISTS operator will be applied to the
         construct.

         .. versionadded:: 1.4.0b2

        r�Nr�r�s   �r+r}zDropIndex.__init__�s���	����I��6r-r�r�r�s@r+r�r��s���+�!�N�7�7r-r�c�4��eZdZdZdZdd�			d�fd�Z�xZS)�
AddConstraintz2Represent an ALTER TABLE ADD CONSTRAINT statement.�add_constraintT)�isolate_from_tablec�r��t�|�|�|r%tj|j�|_yy)aLConstruct a new :class:`.AddConstraint` construct.

        :param element: a :class:`.Constraint` object

        :param isolate_from_table: optional boolean, defaults to True.  Has
         the effect of the incoming constraint being isolated from being
         included in a CREATE TABLE sequence when associated with a
         :class:`.Table`.

         .. versionadded:: 2.0.39 - added
            :paramref:`.AddConstraint.isolate_from_table`, defaulting
            to True.  Previously, the behavior of this parameter was implicitly
            turned on in all cases.

        N)r�r}r�portable_instancemethodr��_create_rule)r(r�r�rqs   �r+r}zAddConstraint.__init__�s6���*	����!��#'�#?�#?��)�)�$�G� �r-)r�rr�r7r�r�s@r+r�r��s,���<�%�N�$(�	���!�	�r-r�c�D��eZdZdZdZdddd�									d�fd�Z�xZS)�DropConstraintz3Represent an ALTER TABLE DROP CONSTRAINT statement.�drop_constraintFT)r�r�r�c���||_t�|�|fd|i|��|r%tj|j
�|_yy)a`Construct a new :class:`.DropConstraint` construct.

        :param element: a :class:`.Constraint` object
        :param cascade: optional boolean, indicates backend-specific
         "CASCADE CONSTRAINT" directive should be rendered if available
        :param if_exists: optional boolean, indicates backend-specific
         "IF EXISTS" directive should be rendered if available
        :param isolate_from_table: optional boolean, defaults to True.  Has
         the effect of the incoming constraint being isolated from being
         included in a CREATE TABLE sequence when associated with a
         :class:`.Table`.

         .. versionadded:: 2.0.39 - added
            :paramref:`.DropConstraint.isolate_from_table`, defaulting
            to True.  Previously, the behavior of this parameter was implicitly
            turned on in all cases.

        r�N)r�r�r}rr�r�r�)r(r�r�r�r�r*rqs      �r+r}zDropConstraint.__init__sG���6���
����<�I�<��<��#'�#?�#?��)�)�$�G� �r-)
r�rr�r7r�r7r�r7r*rr�r�s@r+r�r�sP���=�&�N���#'�
!��!��	!�
�!�!�
!��!�!r-r�c��eZdZdZdZy)�SetTableCommentz*Represent a COMMENT ON TABLE IS statement.�set_table_commentNr�r>r-r+r�r�8s
��4�(�Nr-r�c��eZdZdZdZy)�DropTableCommentzfRepresent a COMMENT ON TABLE '' statement.

    Note this varies a lot across database backends.

    �drop_table_commentNr�r>r-r+r�r�>s���*�Nr-r�c��eZdZdZdZy)�SetColumnCommentz+Represent a COMMENT ON COLUMN IS statement.�set_column_commentNr�r>r-r+r�r�Hs
��5�)�Nr-r�c��eZdZdZdZy)�DropColumnCommentz0Represent a COMMENT ON COLUMN IS NULL statement.�drop_column_commentNr�r>r-r+r�r�Ns
��:�*�Nr-r�c��eZdZdZdZy)�SetConstraintCommentz/Represent a COMMENT ON CONSTRAINT IS statement.�set_constraint_commentNr�r>r-r+r�r�Ts
��9�-�Nr-r�c��eZdZdZdZy)�DropConstraintCommentz4Represent a COMMENT ON CONSTRAINT IS NULL statement.�drop_constraint_commentNr�r>r-r+r�r�Zs
��>�.�Nr-r�c�6�eZdZd�Zej
d��Zy)�
InvokeDDLBasec��||_yr1)ra)r(ras  r+r}zInvokeDDLBase.__init__as	��$��r-c��t��)�dhelper context manager that will apply appropriate DDL events
        to a CREATE or DROP operation.r2�r(rDr*s   r+�with_ddl_eventszInvokeDDLBase.with_ddl_eventsds
��
"�#�#r-N)r9r:r;r}�
contextlib�contextmanagerrr>r-r+r�r�`s!��%����$��$r-r�c�0�eZdZejd��Zy)�InvokeCreateDDLBasec+�K�|jj||jfd|i|��d��|jj||jfd|i|��y�w�r��_ddl_runnerN)�dispatch�
before_createra�after_creaters   r+rz#InvokeCreateDDLBase.with_ddl_eventsmsg����
	&����%�%��D�O�O�	
�15�	
�9;�	
�	�$����$�$��D�O�O�	
�15�	
�9;�	
���AAN�r9r:r;rrrr>r-r+rrl������

��

r-rc�0�eZdZejd��Zy)�InvokeDropDDLBasec+�K�|jj||jfd|i|��d��|jj||jfd|i|��y�wr)r	�before_dropra�
after_droprs   r+rz!InvokeDropDDLBase.with_ddl_events|sg����
	$����#�#��D�O�O�	
�15�	
�9;�	
�	�"����"�"��D�O�O�	
�15�	
�9;�	
�rNr
r>r-r+rr{rr-rc�^��eZdZ	d
�fd�	Zd�Zd�Zd�Zd�Z			dd�Zd�Z	dd�Z
dd	�Z�xZS)
�SchemaGeneratorc���t�|�|fi|��||_||_|j|_||_i|_yr1�r�r}rHrF�identifier_preparer�preparerr)�memo�r(r)rarHrF�kwargsrqs      �r+r}zSchemaGenerator.__init__��@���	����.�v�.�$�������3�3��
������	r-c�@�|jj|j�|jj	|�}|r|jj|�|j
xs3|jj
|j|j|��S�N)�schema�r)�validate_identifierrVra�schema_for_objectrH�	has_table�r(�table�effective_schemas   r+�_can_create_tablez!SchemaGenerator._can_create_table�s������(�(����4��?�?�<�<�U�C����L�L�,�,�-=�>��?�?�"�
�$�,�,�*@�*@��O�O�U�Z�Z�0@�+A�+
�'
�	
r-c�4�|jj|j�}|r|jj	|�|j
xsH|jj
|j|jj|j|��Sr�rar#r&r)r"rH�	has_indexrV�r(�indexr's   r+�_can_create_indexz!SchemaGenerator._can_create_index�s���?�?�<�<�U�[�[�I����L�L�,�,�-=�>��?�?�"�
�$�,�,�*@�*@��O�O��K�K����J�J�#�	+A�+
�'
�	
r-c�<�|jj|�}|jjxrj|jjxs
|j
xrB|jxs3|jj|j|j|��Sr�	rar#r)�supports_sequences�sequences_optional�optionalrH�has_sequencerV�r(�sequencer's   r+�_can_create_sequencez$SchemaGenerator._can_create_sequence�s����?�?�<�<�X�F���|�|�.�.�
����0�0�
0�
I��8I�8I�4I�
��O�O�#���|�|�0�0��O�O�X�]�]�;K�1���		
r-c��|j�
|j}n#t|jj��}t|D�cgc]}|j	|�s�|��c}�}|j
j�D�cgc]!}|j�|j|�r|��#}}|D��cgc]
\}}|��	|��}}}|j|||j��5|D]}	|j|	d���|D]5\}
}|
�|j|
d|d���|D]}|j|���7	ddd�ycc}wcc}wcc}}w#1swYyxYw)N�rFrHT��	create_ok)r;r��_is_metadata_operation)rFrX�values�sort_tables_and_constraintsr(�
_sequencesr�r7rrH�traverse_single)
r(�metadatarF�t�
collectionru�seq_coll�fks�event_collection�seqr&�fkcs�fkcs
             r+�visit_metadatazSchemaGenerator.visit_metadata�so���;�;�"��[�[�F��(�/�/�0�0�2�3�F�0��<��1�$�"8�"8��";�Q��<�
�
��(�(�/�/�1�
�1���x�x��D�$=�$=�a�$@�
�1�	�
�/9�J�j�(�1�c�A�M�A�j��J�
�
!�
!��#����"�
�
 ���$�$�S�D�$�9� � *���t��$��(�(��"&�8<�/3�	)�� $���,�,�S�1� $� *�
�
��
=��
��K�
�
�s+�E�E�&E�1
E
�<E
�!AE�Ec���|s|j|�sy|j||j|��5|jD]*}|j��|j|j��,|jjsd}t||��j|j�t|d�r$|jD]}|j|d���|jjr�|jjs�|j�$t!|�j|j�|jD]3}|j��t#|�j|j��5|jj$rB|j&D]3}|j��|jj)t+|���5ddd�y#1swYyxYw)N�rHr<)r��indexesTr:)r(rrHr�r�r@r)�supports_alterr�rnra�hasattrrM�supports_comments�inline_comments�commentr�r��supports_constraint_comments�constraintsrmr�)r(r&r;r�r<r�r-�
constraints        r+�visit_tablezSchemaGenerator.visit_table�s�����!7�!7��!>��
�
!�
!�����#9�"�
�
 �-�-���>�>�-��(�(����8�(��<�<�.�.�26�/���3�
�
�l�4�?�?�+��u�i�(�"�]�]�E��(�(��$�(�?�+����.�.����4�4��=�=�,�#�E�*�7�7����H�#�m�m�F��~�~�1�(��0�=�=�d�o�o�N�,��<�<�<�<�&+�&7�&7�
�%�-�-�9� �O�O�3�3� 4�Z� @��'8�I
�
�
�s�G�DG�AG�+&G�G#c���|jjsy|j|�5t|�j	|j
�ddd�y#1swYyxYwr1)r)rNrr�rnra�r(rUs  r+�visit_foreign_key_constraintz,SchemaGenerator.visit_foreign_key_constraintsC���|�|�*�*��
�
!�
!�*�
-��*�%�2�2�4�?�?�C�.�
-�
-���%A�A c��|s|j|�sy|j|�5t|�j|j�ddd�y#1swYyxYwr1)r7rr�rnra)r(r6r;s   r+�visit_sequencezSchemaGenerator.visit_sequencesF����!:�!:�8�!D��
�
!�
!�(�
+��8�$�1�1�$�/�/�B�,�
+�
+���%A�Ac��|s|j|�sy|j|�5t|�j|j�ddd�y#1swYyxYwr1)r.rr�rnra)r(r-r;s   r+�visit_indexzSchemaGenerator.visit_indexsF����!7�!7��!>��
�
!�
!�%�
(����+�+�D�O�O�<�)�
(�
(�r]�FN)FNFr�)
r9r:r;r}r(r.r7rJrVrYr\r_r�r�s@r+rr�sB���<@��
�	
�
�$2�R�(,�$�2�hD�C�=r-rc�^��eZdZ	d
�fd�	Zd�Zd�Zd�Zd�Zdd�Z			dd�Z	d�Z
dd	�Z�xZS)
�
SchemaDropperc���t�|�|fi|��||_||_|j|_||_i|_yr1rrs      �r+r}zSchemaDropper.__init__%rr-c�8���j�
�j}n#t|jj��}	|D�cgc]}�j|�s�|��}}tt	t|�fd�����}|j$j�D�cgc]}�j'|�r|��}}|D��	cgc]
\}}	|��	|��}
}}	�j)||
�j*�	�5|D]5\}}|��j-|d
d
|���|D]}
�j-|
���7|D]!}�j-||j.du���#	ddd�ycc}w#tj$�r}�jjsptjddjt|jD�cgc]}|j��ncc}wc}��z�D�cgc]}|df��ncc}w}}n~t
j|j d|j|j"ddjt|jD�cgc]}|j��ncc}wc}��z��|�Yd}~���d}~wwxYwcc}wcc}	}w#1swYyxYw)
Nc�P���jjr|j�dSdSr�)r)rNrV)rUr(s �r+�<lambda>z.SchemaDropper.visit_metadata.<locals>.<lambda>;s.���#'�<�<�#>�#>�)���6�"�&�"&�&r-)�	filter_fna4Can't sort tables for DROP; an unresolvable foreign key dependency exists between tables: %s; and backend does not support ALTER.  To restore at least a partial sort, apply use_alter=True to ForeignKey and ForeignKeyConstraint objects involved in the cycle to mark these as known cycles that will be ignored.r�r>rz�Can't sort tables for DROP; an unresolvable foreign key dependency exists between tables: %s.  Please ensure that the ForeignKey and ForeignKeyConstraint objects involved in the cycle have names so that they can be dropped using DROP CONSTRAINT.)�msgr9T)�drop_okr<�_ignore_sequences)ri)rFrXr=�_can_drop_table�reversedr>r�CircularDependencyErrorr)rNr�warnr��sorted�cycles�fullname�args�edgesr?�_can_drop_sequencerrHr@r�)r(rArFrB�unsorted_tablesrC�err2rurDrErFr&rHrIrGs`              r+rJzSchemaDropper.visit_metadata/s�����;�;�"��[�[�F��(�/�/�0�0�2�3�F�*	�*0�L�&�Q�D�4H�4H��4K�q�&�O�L���/�'�#��
��J�X�(�(�/�/�1�
�1���&�&�q�)�
�1�	�
�/9�J�j�(�1�c�A�M�A�j��J�
�
!�
!��#����"�
�
 *���t��$��(�(�� $�/3�*2�	)�� $���,�,�S�1� $� *� ���$�$�S�#�*�*��2D�$�E� �#
�
��gM���*�*�	��<�<�.�.��	�	�3��y�y��T�[�[�(I�[�����[��(I�!J�K�M�
�0?�?��!�q�"�g���?�
�?��1�1��I�I�a�L��K�K��J�J�'��y�y��T�[�[�(I�[�����[��(I�!J�K�M�	���@��	��:
��K�
�
�st�E�E�E�$E�J�?
J
�
J
�/A!J�E�J�3AI=�7G�
I=�%G1�0AI=�I�I=�=J�Jc�>�|jj|j�|jj	|�}|r|jj|�|j
xs2|jj
|j|j|��Srr!r%s   r+rkzSchemaDropper._can_drop_table}s}�����(�(����4��?�?�<�<�U�C����L�L�,�,�-=�>��?�?�"�
�d�l�l�&<�&<��O�O�U�Z�Z�0@�'=�'
�	
r-c�2�|jj|j�}|r|jj	|�|j
xsG|jj
|j|jj|j|��Srr*r,s   r+�_can_drop_indexzSchemaDropper._can_drop_index�sy���?�?�<�<�U�[�[�I����L�L�,�,�-=�>��?�?�"�
�d�l�l�&<�&<��O�O��K�K����J�J�#�	'=�'
�	
r-c�:�|jj|�}|jjxri|jjxs
|j
xrA|jxs2|jj|j|j|��Srr0r5s   r+rtz SchemaDropper._can_drop_sequence�s����?�?�<�<�X�F���|�|�.�.�
����0�0�
0�
I��8I�8I�4I�
��O�O�#���<�<�,�,��O�O�X�]�]�;K�-��		
r-c��|s|j|�sy|j|�5t|�||j�ddd�y#1swYyxYwr1)ryrr�ra)r(r-ris   r+r_zSchemaDropper.visit_index�sD���t�3�3�E�:��
�
!�
!�%�
(��I�e��U�D�O�O�4�)�
(�
(�s�A�Ac�l�|s|j|�sy|j||j|��5t|�j	|j
�|jD]9}|j��|j|vs�|j|j��;	ddd�y#1swYyxYw)NrL)	rkrrHr�rnrar�r�r@)r(r&rir<rjr�s      r+rVzSchemaDropper.visit_table�s����t�3�3�E�:��
�
!�
!�����#9�"�
�

�e��)�)�$�/�/�:� �-�-���N�N�.����.?�?��(�(����8�(�
�
�
�s�AB*�4B*�B*�*B3c���|jjsy|j|�5t|�j	|j
�ddd�y#1swYyxYwr1)r)rNrr�rnrarXs  r+rYz*SchemaDropper.visit_foreign_key_constraint�sC���|�|�*�*��
�
!�
!�*�
-��:�&�3�3�D�O�O�D�.�
-�
-�rZc��|s|j|�sy|j|�5t|�j|j�ddd�y#1swYyxYwr1)rtrr�rnra)r(r6ris   r+r\zSchemaDropper.visit_sequence�sF���t�6�6�x�@��
�
!�
!�(�
+���"�/�/����@�,�
+�
+�r]r`r�)FFr>)
r9r:r;r}rJrkryrtr_rVrYr\r�r�s@r+rbrb$sC���<@��LF�\
�	
�

�5��$��9�>E�Ar-rbc�p��|�|��fd�}nd}t|||d��D��cgc]	\}}|�|��c}}Scc}}w)a
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


    Nc�<��|jD]}�|�s�yyrj)�elements)rI�fk�
fixed_skip_fns  �r+�_skip_fnzsort_tables.<locals>._skip_fns!����l�l�� ��$��#�r-T)rg�extra_dependencies�_warn_for_cycles)r>)rF�skip_fnr�r�rBrHr�s      @r+�sort_tablesr��sd���B���
�	���5���1�!�	
�	�
�I�Q��
�=�	
�
�	�	��	s�2c
����t�}t�}|�|j|�t�}|D]���jD]f}|jdur|j	|��#|r||�}|dur|j	|��C|j
}	|	�us�T|j	|	�f��h|j�fd��jD����	ttj|j|�|��}
|
D�cgc]}||jj)|�f��!c}dt|�fgzS#tj$�r}|rBtjddjt!d�|j"D����d��|j$D]�}||vs�|d��|j"vr��jD�cgc]}|�
||�d	ur|��ncc}w}
}|j|
�|
D]&}|j
}	|	�us�|j'|	�f��(��ttj|j|�|��}
Yd}~��Wd}~wwxYwcc}w)
a�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.

    .. seealso::

        :func:`.sort_tables`


    NTc3�&�K�|]}|�f���
y�wr1r>)�.0�parentr&s  �r+�	<genexpr>z.sort_tables_and_constraints.<locals>.<genexpr>ps�����"
�*C��V�U�O�*C�s�zLCannot correctly sort tables; there are unresolvable cycles between tables "r�c3�4K�|]}|j���y�wr1)rq)r�rBs  r+r�z.sort_tables_and_constraints.<locals>.<genexpr>�s����#C�
�1�A�J�J�
�s�z�", which is usually caused by mutually dependent foreign key constraints.  Foreign key constraints involving these tables will not be considered; this warning may raise an error in a future release.rF)rY�update�foreign_key_constraints�	use_alter�add�referred_table�_extra_dependenciesrXr�sort�unionrrmrrnr�rorprs�discard�
difference)rFrgr�r��fixed_dependencies�mutable_dependencies�remaining_fkcsrI�filtered�dependent_on�candidate_sort�err�edge�
can_remover&s              `r+r>r>*s~���\����5���%��!�!�"4�5��U�N����0�0�C��}�}��$��"�"�3�'���$�S�>���t�#�"�&�&�s�+���-�-�L��5�(�$�(�(�,��)>�?�1� 	�!�!�"
�*/�*C�*C�"
�	
�#�*%
�����"�(�(�)=�>��
�
��P$��#�E�
��-�-�8�8��H�I�#����^�$�	%�&�'�'��A�&�&�
���I�I��9�9�V�#C��
�
�#C�C�D�G�
��I�I�D��+�+��Q�����
�
�*�� %�<�<��<�� �(�I�c�N�%�,G��<���
��
�%�%�j�1�%�C�#&�#5�#5�L�#�5�0�,�4�4�l�E�5J�K�&������"�(�(�)=�>��
�
���3
��@s8�.D<�$I!�<I�AI�("I�
G �.I�AI�IrJ)rFzIterable[TableClause]r�z0Optional[Callable[[ForeignKeyConstraint], bool]]r�z:Optional[typing_Sequence[Tuple[TableClause, TableClause]]]r8zList[Table])NNF)Sr<�
__future__rr�typingrrrrrr	�typing_Sequencer
�r�baser
rrr�rrrr�util.typingrr�
TYPE_CHECKINGrArrrr rrrr�
selectabler�engine.baser�engine.interfacesr r!r"r#r%r@�
NamedTuplerO�DDLRoler]�
DDLElementrxr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrbr�r>r>r-r+�<module>r�sz���
#��
������.������#����"��	���"�%�'�"�,�"� ��'�(�.�5�+�:�$�]�$�@�H��%�F���%�Pw�5�=�=�*�n�w�t"�
�H�T
�
�T
�n�*��@+�/�+�#��#�D�;�D�*���.O�+�O�D!�	�!��~��
r�>�r�j7�	�7�(?�[�?�7�9�7�?�+�?�&7�	�7�&�K��D&�Y�&�R)�o�)�*��*�*��*�+��+�.�?�.�/�O�/�	$�M�	$�
�-�
�
�
�
�W=�)�W=�tiA�%�iA�\AE�	
�W�!�W�
=�W��W��
W�vGL�t'r-

ZeroDay Forums Mini