AlkantarClanX12

Your IP : 18.225.195.153


Current Path : /opt/cloudlinux/venv/lib64/python3.11/site-packages/sqlalchemy/sql/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib64/python3.11/site-packages/sqlalchemy/sql/__pycache__/ddl.cpython-311.pyc

�

�܋fӢ���dZddlmZddlmZddlmZddlmZddlmZddlm	Z	dd	lm
Z
dd
lmZddlmZGd�d
e��Z
Gd�dee
��ZGd�de��ZGd�de��ZGd�de��ZGd�de��ZGd�de��ZGd�de��ZGd�de
��ZGd�de��ZGd �d!e��ZGd"�d#e��ZGd$�d%e��ZGd&�d'e��ZGd(�d)e��ZGd*�d+e��ZGd,�d-e��ZGd.�d/e��ZGd0�d1e��ZGd2�d3e��Z Gd4�d5e��Z!Gd6�d7e!��Z"Gd8�d9e!��Z#		d>d;�Z$	d?d=�Z%d:S)@zq
Provides the hierarchy of DDL-defining schema items as well as routines
to invoke them for a create/drop call.

�)�_bind_or_error)�_generative)�
Executable)�
SchemaVisitor)�
ClauseElement�)�event)�exc)�util)�topologicalc��eZdZd�ZdS)�_DDLCompilesc� �|j||fi|��S)zNReturn a compiler appropriate for this ClauseElement, given a
        Dialect.)�ddl_compiler)�self�dialect�kws   �I/opt/cloudlinux/venv/lib64/python3.11/site-packages/sqlalchemy/sql/ddl.py�	_compilerz_DDLCompiles._compilers!��$�w�#�G�T�8�8�R�8�8�8�N)�__name__�
__module__�__qualname__r�rrrrs#������9�9�9�9�9rrc��eZdZdZej�ddi��ZdZdZdZ	dZ
d�Zdd�Ze
jdd��d	���Zed
���Zedd���Zd�Zd
�Zd�Zd�Zd�Zd�Zeee��Zd�ZdS)�
DDLElementa�Base class for 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.

    :class:`.DDLElement` 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`

    �
autocommitTNc�0�|�|||��S�N)�_execute_ddl)r�
connection�multiparams�paramss    r�_execute_on_connectionz!DDLElement._execute_on_connectionGs���&�&�t�[�&�A�A�Arc���|�t|��}|�||��r(|�|�|����S|jj�d��dS)a1Execute this DDL immediately.

        Executes the DDL statement in isolation using the supplied
        :class:`.Connectable` or
        :class:`.Connectable` assigned to the ``.bind``
        property, if not supplied. If the DDL has a conditional ``on``
        criteria, it will be invoked with None as the event.

        :param bind:
          Optional, an ``Engine`` or ``Connection``. If not supplied, a valid
          :class:`.Connectable` must be present in the
          ``.bind`` property.

        :param target:
          Optional, defaults to None.  The target :class:`_schema.SchemaItem`
          for the execute call.  Will be passed to the ``on`` callable if any,
          and may also provide string expansion data for the statement.
          See ``execute_at`` for more information.

        Nz(DDL execution skipped, criteria not met.)r�_should_execute�execute�against�engine�logger�info)r�bind�targets   rr'zDDLElement.executeJsm��,�<�!�$�'�'�D������-�-�	P��<�<����V� 4� 4�5�5�5��K��#�#�$N�O�O�O�O�Or�0.7z�The :meth:`.DDLElement.execute_at` method is deprecated and will be removed in a future release.  Please use the :class:`.DDLEvents` listener interface in conjunction with the :meth:`.DDLElement.execute_if` method.c�p�����fd�}tj|d��dd��z|��dS)a_Link execution of this DDL to the DDL lifecycle of a SchemaItem.

        Links this ``DDLElement`` to a ``Table`` or ``MetaData`` instance,
        executing it when that schema item is created or dropped. The DDL
        statement will be executed using the same Connection and transactional
        context as the Table create/drop itself. The ``.bind`` property of
        this statement is ignored.

        :param event:
          One of the events defined in the schema item's ``.ddl_events``;
          e.g. 'before-create', 'after-create', 'before-drop' or 'after-drop'

        :param target:
          The Table or MetaData instance for which this DDLElement will
          be associated with.

        A DDLElement instance can be linked to any number of schema items.

        ``execute_at`` builds on the ``append_ddl_listener`` interface of
        :class:`_schema.MetaData` and :class:`_schema.Table` objects.

        Caveat: Creating or dropping a Table in isolation will also trigger
        any DDL set to ``execute_at`` that Table's MetaData.  This may change
        in a future release.

        c�x���j�||fi|��r(|���|����SdSr)�_should_execute_deprecatedr'r()r-r!r�
event_namers   ��r�
call_eventz)DDLElement.execute_at.<locals>.call_event�s]���.�t�.��F�J���24���
@�"�)�)�$�,�,�v�*>�*>�?�?�?�
@�
@r��-�_N)r	�listen�replace)rr2r-r3s``  r�
execute_atzDDLElement.execute_athsZ����F	@�	@�	@�	@�	@�	@�	��V�R�*�"4�"4�S�#�">�">�>�
�K�K�K�K�Krc��||_dS)z9Return a copy of this DDL against a specific schema item.N)r-)rr-s  rr(zDDLElement.against�s������rc�0�||_||_||_dS)aReturn a callable that will execute this
        DDLElement conditionally.

        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, tuple or a callable
          predicate.  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
          four 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

            :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.

            :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::

            :class:`.DDLEvents`

            :ref:`event_toplevel`

        N)r�	callable_�state)rrr<r=s    r�
execute_ifzDDLElement.execute_if�s��D���"�����
�
�
rc�^�|j�|jd||fi|��sdSt|jtj��r|j|jjkrdSn<t|jtttf��r|jj|jvrdS|j�|j|||fd|ji|��sdSdS)NFr=T)
�onr1�
isinstancerr�string_typesr)�name�tuple�list�setr<r=�rr-r,rs    rr&zDDLElement._should_execute�s����7��'F�t�'F��&�$�(
�(
�"$�(
�(
���5��d�l�D�$5�6�6�	��|�t�{�/�/�/��u�0�
���u�d�C�&8�
9�
9�	��{��t�|�3�3��u��>�%�n�d�n��&�$�/
�/
�&*�j�/
�46�/
�/
�%��5��trc��|j�dSt|jtj��r|j|jjkSt|jtttf��r|jj|jvS|j||||fi|��S�NT)	r@rArrBr)rCrDrErF)rr	r-r,rs     rr1z%DDLElement._should_execute_deprecated�s����7�?��4�
����!2�
3�
3�	<��7�d�k�.�.�.�
���%��s�!3�
4�
4�	<��;�#�t�w�.�.��4�7�4����;�;��;�;�;rc�t�|j||fi|��r(|�|�|����SdS)z"Execute the DDL as a ddl_listener.N)r&r'r(rGs    r�__call__zDDLElement.__call__�sK�� �4����3�3��3�3�	6��<�<����V� 4� 4�5�5�5�	6�	6rc���|�lt|tjttt
fz��s?tj|��s-tjdt|��j
z���dSdSdS)NzjExpected the name of a database dialect, a tuple of names, or a callable for 'on' criteria, got type '%s'.)rArrBrDrErF�callabler
�
ArgumentError�typer)rr@s  r�
_check_ddl_onzDDLElement._check_ddl_onsw��
�>��2�t�0�E�4��3E�E�F�F���M�"�%�%���#�0�26�r�(�(�2C�D���
�	�>�>�>�>�>rc�"�|jr|jSdSr��_bind�rs rr,zDDLElement.bind
s���:�	��:��	�	rc��||_dSrrR)rr,s  r�	_set_bindzDDLElement._set_binds
����
�
�
rc��|j�|j��}|j���|_|Sr)�	__class__�__new__�__dict__�copy)r�ss  r�	_generatezDDLElement._generates3���N�"�"�4�>�2�2���]�'�'�)�)��
��r�NN�NNN)rrr�__doc__r�_execution_options�unionr-r@rr<r$r'r�
deprecatedr9rr(r>r&r1rKrPr,rV�propertyr]rrrrr su��������:$�6�<�<�	�t������F�	
�B��G��I�B�B�B�P�P�P�P�<�T�_�
�	1���"L�"L���"L�H����[��
�C�C�C��[�C�J���&<�<�<�6�6�6�	�	�	��������8�D�)�$�$�D�����rrc�R�eZdZdZdZejd���dd���Zd�ZdS)	�DDLaAA 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::

      %(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.

    �ddl)r.z�The :paramref:`.DDL.on` parameter is deprecated and will be removed in a future release.  Please refer to :meth:`.DDLElement.execute_if`.)r@Nc���t|tj��stjd|z���||_|pi|_|�|��||_||_	dS)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.  See the
          ``context`` argument and the ``execute_at`` method.

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

          SQL bind parameters are not available in DDL statements.

        :param on:

          Optional filtering criteria.  May be a string, tuple or a callable
          predicate.  If a string, it will be compared to the name of the
          executing database dialect::

            DDL('something', on='postgresql')

          If a tuple, specifies multiple dialect names::

            DDL('something', on=('postgresql', 'mysql'))

          If a callable, it will be invoked with four positional arguments
          as well as optional keyword arguments:

            :ddl:
              This DDL element.

            :event:
              The name of the event that has triggered this DDL, such as
              'after-create' Will be None if the DDL is executed explicitly.

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

            :connection:
              The ``Connection`` being used for DDL execution

            :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.


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

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

        :param bind:
          Optional. A :class:`.Connectable`, used by
          default when ``execute()`` is invoked without a bind argument.


        .. seealso::

            :class:`.DDLEvents`

            :ref:`event_toplevel`

        z4Expected a string or unicode SQL statement, got '%r'N)
rArrBr
rN�	statement�contextrPr@rS)rrir@rjr,s     r�__init__zDDL.__init__Bst��V�)�T�%6�7�7�	��#�F�����
�
#����}�"������2���������
�
�
rc
����dt���j�dt����dd�t	�j��g�fd�dD��z���d�S)N�<�@z; �, c�Z��g|]'}t�|���|�dt�|������(S)�=)�getattr)�.0�keyrs  �r�
<listcomp>z DDL.__repr__.<locals>.<listcomp>�sO��������t�S�)�)��"�s�s�G�D�#�$6�$6�$6�7���r)r@rj�>)rOr�id�join�reprrirTs`r�__repr__zDDL.__repr__�s�������J�J�����t�H�H�H�H��I�I��d�n�%�%�&�����0�����
�
�
�
�
�	
rr_)	rrrr`�__visit_name__r�deprecated_paramsrkrzrrrrfrfst������!�!�F�N��T��
����N�N�N���N�`
�
�
�
�
rrfc� �eZdZdZdd�Zd�ZdS)�_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.

    Nc�Z�||_|�|��||_||_dSr)�elementrPr@r,)rr�r@r,s    rrkz_CreateDropBase.__init__�s/��������2���������	�	�	rc��dS)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�compilers  r�_create_rule_disablez$_CreateDropBase._create_rule_disable�s	���urr^)rrrr`rkr�rrrr~r~�sA����������������rr~c�(��eZdZdZdZd�fd�	Z�xZS)�CreateSchemazcRepresent a CREATE SCHEMA statement.

    The argument here is the string name of the schema.

    �
create_schemaNc�X��||_tt|��j|fi|��dS)z.Create a new :class:`.CreateSchema` construct.N)�quote�superr�rk)rrCr�rrXs    �rrkzCreateSchema.__init__�s7�����
�*��l�D�!�!�*�4�6�6�2�6�6�6�6�6rr�rrrr`r{rk�
__classcell__�rXs@rr�r��sN���������%�N�7�7�7�7�7�7�7�7�7�7rr�c�(��eZdZdZdZd�fd�	Z�xZS)�
DropSchemazaRepresent a DROP SCHEMA statement.

    The argument here is the string name of the schema.

    �drop_schemaNFc�f��||_||_tt|��j|fi|��dS)z,Create a new :class:`.DropSchema` construct.N)r��cascader�r�rk)rrCr�r�rrXs     �rrkzDropSchema.__init__�s>�����
����(��j�$���(��4�4��4�4�4�4�4r�NFr�r�s@rr�r��sN���������#�N�5�5�5�5�5�5�5�5�5�5rr�c�*��eZdZdZdZ	d�fd�	Z�xZS)�CreateTablez#Represent a CREATE TABLE statement.�create_tableNc���tt|���|||���d�|jD��|_||_dS)aZCreate 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 bind: See the description for 'bind' 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.

         .. versionadded:: 1.0.0

        )r@r,c�,�g|]}t|����Sr)�CreateColumn)rs�columns  rruz(CreateTable.__init__.<locals>.<listcomp>�s ��K�K�K���V�,�,�K�K�KrN)r�r�rk�columns�include_foreign_key_constraints)rr�r@r,r�rXs     �rrkzCreateTable.__init__�sO���"	�k�4� � �)�)�'�b�t�)�D�D�D�K�K�7�?�K�K�K���/N��,�,�,rr_r�r�s@rr�r��sY�������-�-�#�N�LP�O�O�O�O�O�O�O�O�O�Orr�c��eZdZdZdZdS)�	_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�rrrr`r{rrrr�r�s��������!�N�N�Nrr�c��eZdZdZdZd�ZdS)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::

        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��||_dSr)r�)rr�s  rrkzCreateColumn.__init__ts
������rN)rrrr`r{rkrrrr�r�s7������d�d�L%�N�����rr�c��eZdZdZdZdS)�	DropTablez!Represent a DROP TABLE statement.�
drop_tableNr�rrrr�r�x�������+�+�!�N�N�Nrr�c��eZdZdZdZdS)�CreateSequencez&Represent a CREATE SEQUENCE statement.�create_sequenceNr�rrrr�r�~s������0�0�&�N�N�Nrr�c��eZdZdZdZdS)�DropSequencez$Represent a DROP SEQUENCE statement.�
drop_sequenceNr�rrrr�r��s������.�.�$�N�N�Nrr�c��eZdZdZdZdS)�CreateIndexz#Represent a CREATE INDEX statement.�create_indexNr�rrrr�r��s������-�-�#�N�N�Nrr�c��eZdZdZdZdS)�	DropIndexz!Represent a DROP INDEX statement.�
drop_indexNr�rrrr�r��r�rr�c�&��eZdZdZdZ�fd�Z�xZS)�
AddConstraintz2Represent an ALTER TABLE ADD CONSTRAINT statement.�add_constraintc���tt|��j|g|�Ri|��tj|j��|_dSr)r�r�rkr�portable_instancemethodr��_create_rule)rr��argsrrXs    �rrkzAddConstraint.__init__�sQ���+��m�T�"�"�+�G�A�d�A�A�A�b�A�A�A�#�;��%� 
� 
����rr�r�s@rr�r��sC�������<�<�%�N�
�
�
�
�
�
�
�
�
rr�c�(��eZdZdZdZd�fd�	Z�xZS)�DropConstraintz3Represent an ALTER TABLE DROP CONSTRAINT statement.�drop_constraintFc���||_tt|��j|fi|��t	j|j��|_dSr)r�r�r�rkrr�r�r�)rr�r�rrXs    �rrkzDropConstraint.__init__�sP������,��n�d�#�#�,�W�;�;��;�;�;�#�;��%� 
� 
����r�Fr�r�s@rr�r��sH�������=�=�&�N�
�
�
�
�
�
�
�
�
�
rr�c��eZdZdZdZdS)�SetTableCommentz*Represent a COMMENT ON TABLE IS statement.�set_table_commentNr�rrrr�r��s������4�4�(�N�N�Nrr�c��eZdZdZdZdS)�DropTableCommentzfRepresent a COMMENT ON TABLE '' statement.

    Note this varies a lot across database backends.

    �drop_table_commentNr�rrrr�r��s��������*�N�N�Nrr�c��eZdZdZdZdS)�SetColumnCommentz+Represent a COMMENT ON COLUMN IS statement.�set_column_commentNr�rrrr�r��s������5�5�)�N�N�Nrr�c��eZdZdZdZdS)�DropColumnCommentz0Represent a COMMENT ON COLUMN IS NULL statement.�drop_column_commentNr�rrrr�r��s������:�:�*�N�N�Nrr�c��eZdZd�ZdS)�DDLBasec��||_dSr)r!)rr!s  rrkzDDLBase.__init__�s
��$����rN)rrrrkrrrr�r��s#������%�%�%�%�%rr�c�V��eZdZ	d�fd�	Zd�Zd�Zd�Z			dd�Zd�Zd
d	�Z	d
�Z
�xZS)�SchemaGeneratorFNc���tt|��j|fi|��||_||_|j|_||_i|_dSr)	r�r�rk�
checkfirst�tables�identifier_preparer�preparerr�memo�rrr!r�r��kwargsrXs      �rrkzSchemaGenerator.__init__�sT���	.��o�t�$�$�-�j�C�C�F�C�C�C�$�������3��
������	�	�	rc��|j�|j��|j�|��}|r|j�|��|jp'|j�|j|j|���S�N)�schema�r�validate_identifierrCr!�schema_for_objectr��	has_table�r�table�effective_schemas   r�_can_create_tablez!SchemaGenerator._can_create_table�s�����(�(���4�4�4��?�<�<�U�C�C���	?��L�,�,�-=�>�>�>��?�"�
�$�,�*@�*@��O�U�Z�0@�+A�+
�+
�'
�	
rc���|j�|��}|jjoD|jjs|jo/|jp'|j�|j|j|���Sr��	r!r�r�supports_sequences�sequences_optional�optionalr��has_sequencerC�r�sequencer�s   r�_can_create_sequencez$SchemaGenerator._can_create_sequence�s}���?�<�<�X�F�F���|�.�
���0�
0�
I��8I�4I�
��O�#���|�0�0��O�X�]�;K�1����		
rc�b���j��j}n&t|j�����}t�fd�|D����}�fd�|j���D��}d�|D��}|j�|�j|�j����|D]}��	|d����|D];\}}|���	|d|d����!|D]}	��	|	����<|j�
|�j|�j����dS)Nc�>��g|]}��|���|��Sr)r��rs�trs  �rruz2SchemaGenerator.visit_metadata.<locals>.<listcomp>�s,���<�<�<�1�$�"8�"8��";�";�<�Q�<�<�<rc�L��g|] }|j�	��|���|��!Sr)r�r��rsr\rs  �rruz2SchemaGenerator.visit_metadata.<locals>.<listcomp>�s>���
�
�
���x��D�$=�$=�a�$@�$@��
���rc��g|]	\}}|�|��
Srr�rsr��fkss   rruz2SchemaGenerator.visit_metadata.<locals>.<listcomp>���J�J�J�(�1�c�A�M�A�M�M�Mr�r�r��_ddl_runnerT)�	create_ok)r�r��_is_metadata_operation)r�rE�values�sort_tables_and_constraints�
_sequences�dispatch�
before_creater!r��traverse_single�after_create)
r�metadatar��
collection�seq_coll�event_collection�seqr��fkcs�fkcs
`         r�visit_metadatazSchemaGenerator.visit_metadata�s�����;�"��[�F�F��(�/�0�0�2�2�3�3�F�0�<�<�<�<��<�<�<�
�
�
�
�
�
�
��(�/�/�1�1�
�
�
��K�J�j�J�J�J����'�'���O�#����	(�	
�	
�	
��	6�	6�C�� � ��� �5�5�5�5�%�
	.�
	.�K�E�4�� ��$�$��"�48�+/�	%����� �.�.�C��(�(��-�-�-�-�.�	��&�&���O�#����	'�	
�	
�	
�	
�	
rc��|s|�|��sdS|j�||j|j||���|jD]#}|j�|�|j���$|jj	sd}|j�
t||�����t|d��r|j
D]}|�|���|jjrr|jjsf|j�'|j�
t#|����|jD]0}|j�'|j�
t%|�����1|j�||j|j||���dS)N�r�r�r�)r��indexes)r�r�r�r!r�r��defaultr�r�supports_alterr'r��hasattrr�supports_comments�inline_comments�commentr�r�r)rr�r�r�r�r��indexs       r�visit_tablezSchemaGenerator.visit_table!s����	��!7�!7��!>�!>�	��F�
��$�$���O����#9�	%�	
�	
�	
��m�	5�	5�F��~�)��$�$�V�^�4�4�4���|�*�	3�.2�+�������3�
�
�
�	
�	
�	
��5�)�$�$�	,���
,�
,���$�$�U�+�+�+�+��<�)�	F�$�,�2N�	F��}�(���'�'���(>�(>�?�?�?��-�
F�
F���>�-��O�+�+�,<�V�,D�,D�E�E�E��
��#�#���O����#9�	$�	
�	
�	
�	
�	
rc�p�|jjsdS|j�t	|����dSr)rr
r!r'r��r�
constraints  r�visit_foreign_key_constraintz,SchemaGenerator.visit_foreign_key_constraintYs8���|�*�	��F�����
�j� 9� 9�:�:�:�:�:rc��|s|�|��sdS|j�t|����dSr)r�r!r'r�)rr�r�s   r�visit_sequencezSchemaGenerator.visit_sequence^sH���	��!:�!:�8�!D�!D�	��F������x� 8� 8�9�9�9�9�9rc�T�|j�t|����dSr)r!r'r��rrs  r�visit_indexzSchemaGenerator.visit_indexcs&�������E� 2� 2�3�3�3�3�3r�FN)FNFr�)rrrrkr�r�rrrrrr�r�s@rr�r��s��������<@�������
�
�
�
�
�
�.
�.
�.
�f�(,�$�6
�6
�6
�6
�p;�;�;�
:�:�:�:�
4�4�4�4�4�4�4rr�c�V��eZdZ	d�fd�	Zd�Zd�Zd�Zd�Zddgfd�Zd	�Z	dd
�Z
�xZS)
�
SchemaDropperFNc���tt|��j|fi|��||_||_|j|_||_i|_dSr)	r�rrkr�r�r�r�rr�r�s      �rrkzSchemaDropper.__init__hsT���	,��m�T�"�"�+�J�A�A�&�A�A�A�$�������3��
������	�	�	rc����j��j}n&t|j�����}	�fd�|D��}ttt	|�fd��������}n�#t
j$r�}�jjsStj
dd�td�|j
D������z��d�|D��}nstjtj|jd|j
|jd	d�td
�|j
D������z���|���Yd}~nd}~wwxYw�fd
�|j���D��}d�|D��}|j�|�j|�j����|D];\}}	|���|dd|����!|	D]}
��|
����<|D] }��||jdu����!|j�|�j|�j����dS)Nc�>��g|]}��|���|��Sr)�_can_drop_tabler�s  �rruz0SchemaDropper.visit_metadata.<locals>.<listcomp>ys,���L�L�L�Q�D�4H�4H��4K�4K�L�q�L�L�Lrc�2���jjr|j�dndSr�)rr
rC)rrs �r�<lambda>z.SchemaDropper.visit_metadata.<locals>.<lambda>~s)���#�|�:�6"�%�?�2�6;�U�"�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.roc��g|]	}|j��
Sr��fullname�rsr�s  rruz0SchemaDropper.visit_metadata.<locals>.<listcomp>�s��(I�(I�(I����(I�(I�(Irc��g|]}|df��S)rrr*s  rruz0SchemaDropper.visit_metadata.<locals>.<listcomp>�s��?�?�?�!�q�"�g�?�?�?r�z�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.c��g|]	}|j��
Srr(r*s  rruz0SchemaDropper.visit_metadata.<locals>.<listcomp>�s��'H�'H�'H�q��
�'H�'H�'Hr)�msg)�from_c�>��g|]}��|���|��Sr)�_can_drop_sequencer�s  �rruz0SchemaDropper.visit_metadata.<locals>.<listcomp>�s=���
�
�
���&�&�q�)�)�
�
�
�
�
rc��g|]	\}}|�|��
Srrr�s   rruz0SchemaDropper.visit_metadata.<locals>.<listcomp>�r�rr�T)�drop_okr��_ignore_sequences)r3)r�rEr��reversedr�r
�CircularDependencyErrorrr
r�warnrx�sorted�cycles�raise_r��edgesr�r��before_dropr!r�r�r��
after_drop)rrr��unsorted_tablesr�err2rrr�rrrs`           rrzSchemaDropper.visit_metadatars����;�"��[�F�F��(�/�0�0�2�2�3�3�F�/	�L�L�L�L�&�L�L�L�O���/�'�#"�#"�#"�#"������
�
�J�J���*�"	�"	�"	��<�.�!
��	�3��y�y��(I�(I�T�[�(I�(I�(I�!J�!J�K�K�M�
�
�
�@�?��?�?�?�
�
����/��	�!�����
�+�!�I�I� &�'H�'H�D�K�'H�'H�'H� I� I����	���"�%�������������"	����H
�
�
�
��(�/�/�1�1�
�
�
��K�J�j�J�J�J����%�%���O�#����	&�	
�	
�	
�&�
	.�
	.�K�E�4�� ��$�$�� �+/�&.�	%����� �.�.�C��(�(��-�-�-�-�.��	B�	B�C�� � ��c�j�D�.@� �A�A�A�A���$�$���O�#����	%�	
�	
�	
�	
�	
s�<A5�5E �CE�E c�
�|j�|j��|j�|��}|r|j�|��|jp&|j�|j|j|���Sr�r�r�s   rr#zSchemaDropper._can_drop_table�s�����(�(���4�4�4��?�<�<�U�C�C���	?��L�,�,�-=�>�>�>��?�"�
�d�l�&<�&<��O�U�Z�0@�'=�'
�'
�	
rc���|j�|��}|jjoC|jjs|jo.|jp&|j�|j|j|���Sr�r�r�s   rr1z SchemaDropper._can_drop_sequence�sx���?�<�<�X�F�F���|�.�
���0�
0�
I��8I�4I�
��O�#���<�,�,��O�X�]�;K�-���		
rc�T�|j�t|����dSr)r!r'r�rs  rrzSchemaDropper.visit_index�s&������	�%� 0� 0�1�1�1�1�1rc��|s|�|��sdS|j�||j|j||���|j�t
|����|jD],}|j�#|j|vr|�	|j���-|j�
||j|j||���dS)Nr
)r#r�r<r!r�r'r�r�rr�r=)rr�r3r�r4r�s      rrzSchemaDropper.visit_table�s����	�t�3�3�E�:�:�	��F�
��"�"���O����#9�	#�	
�	
�	
�	
����	�%� 0� 0�1�1�1��m�	5�	5�F���*��N�*;�;�;��$�$�V�^�4�4�4��
��!�!���O����#9�	"�	
�	
�	
�	
�	
rc�p�|jjsdS|j�t	|����dSr)rr
r!r'r�rs  rrz*SchemaDropper.visit_foreign_key_constraints8���|�*�	��F������z� :� :�;�;�;�;�;rc��|s|�|��sdS|j�t|����dSr)r1r!r'r�)rr�r3s   rrzSchemaDropper.visit_sequencesH���	�t�6�6�x�@�@�	��F������X� 6� 6�7�7�7�7�7rrr�)rrrrkrr#r1rrrrr�r�s@rrrgs��������<@�������\
�\
�\
�|
�
�
�

�

�

�2�2�2��$��&
�&
�&
�&
�P<�<�<�
8�8�8�8�8�8�8�8rrNc�R�����fd�}nd}d�t|||d���D��S)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.ForeignKey` 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�8��|jD]}�|��rdS�dSrI)�elements)r�fk�skip_fns  �r�_skip_fnzsort_tables.<locals>._skip_fn]s7����l�
�
���7�2�;�;� ��4�4� ��trc��g|]	\}}|�|��
Srr)rsr�rs   rruzsort_tables.<locals>.<listcomp>gs-��	�	�	��Q��
�=�	
��=�=rT)r&�extra_dependencies�_warn_for_cycles)r�)r�rJrMrKs `  r�sort_tablesrOsm���~��	�	�	�	�	�	���	�	�4���1�!�	
�
�
�	�	�	�	rFc
���
��t��}t��}|�|�|��t���
|D]���jD]j}|jdur�
�|���!�r%�|��}|dur�
�|���H|j}|�ur|�|�f���k|��fd��jD������	ttj	|�
|��|d�����}	�n#tj$r�}
|rGtjdd�t!d�|
jD�������d���|
jD]g}||vra|d	��|
jvr��fd
��jD��}�
�|��|D]$}|j}|�ur|�|�f���%�httj	|�
|��|d�����}	Yd}
~
nd}
~
wwxYw�
fd�|	D��dt�
��fgzS)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.

    .. versionadded:: 1.0.0

    .. seealso::

        :func:`.sort_tables`


    NTc3� �K�|]}|�fV��	dSrr)rs�parentr�s  �r�	<genexpr>z.sort_tables_and_constraints.<locals>.<genexpr>�s8�����"
�"
� &�V�U�O�"
�"
�"
�"
�"
�"
r)�deterministic_orderzLCannot correctly sort tables; there are unresolvable cycles between tables "roc3�$K�|]}|jV��dSrr(r*s  rrSz.sort_tables_and_constraints.<locals>.<genexpr>�s$����#C�#C�1�A�J�#C�#C�#C�#C�#C�#Crz�", 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.rc�2��g|]}��
�|��du�|��Sr�r)rsrr&s  �rruz/sort_tables_and_constraints.<locals>.<listcomp>�s;������� �(�I�I�c�N�N�%�,G�,G��,G�,G�,Grc�H��g|]}||j����f��Sr)�foreign_key_constraints�
difference)rsr��remaining_fkcss  �rruz/sort_tables_and_constraints.<locals>.<listcomp>�s?�������
��-�8�8��H�H�I���r)rF�updaterX�	use_alter�add�referred_table�_extra_dependenciesrEr�sortrbr
r6rr7rxr8r9r;�discard)r�r&rMrN�fixed_dependencies�mutable_dependenciesr�filtered�dependent_on�candidate_sort�err�edge�
can_removerZr�s `           @@rr�r�ss2�����`�����5�5���%��!�!�"4�5�5�5��U�U�N��
�
���0�	@�	@�C��}��$�$��"�"�3�'�'�'���
�$�9�S�>�>���t�#�#�"�&�&�s�+�+�+���-�L��5�(�(�$�(�(�,��)>�?�?�?���!�!�"
�"
�"
�"
�*/�*C�"
�"
�"
�	
�	
�	
�	
�'
����"�(�(�)=�>�>��$(�
�
�
�
�
�����&�
�
�
��	��I�I��9�9�V�#C�#C��
�#C�#C�#C�C�C�D�D�D�D�G�
�
�
��I�	L�	L�D��+�+�+��Q�����
�*�*������$�<����
�
�%�%�j�1�1�1�%�L�L�C�#&�#5�L�#�5�0�0�,�4�4�l�E�5J�K�K�K������"�(�(�)=�>�>��$(�
�
�
�
�
�����������3
����B����#������^�$�$�	%�&�'�'s�#7D�H$�+C/H�H$r^)NNF)&r`�baserrrrrHrr4r	r
rrrrrfr~r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrOr�rrr�<module>rks�����!� � � � � �������������������#�#�#�#�#�#�������������������������9�9�9�9�9�=�9�9�9�y�y�y�y�y��\�y�y�y�xJ
�J
�J
�J
�J
�*�J
�J
�J
�Z�����j����6
7�
7�
7�
7�
7�?�
7�
7�
7� 5�5�5�5�5��5�5�5�"O�O�O�O�O�/�O�O�O�6!�!�!�!�!��!�!�!�j�j�j�j�j�<�j�j�j�Z"�"�"�"�"��"�"�"�'�'�'�'�'�_�'�'�'�%�%�%�%�%�?�%�%�%�$�$�$�$�$�/�$�$�$�"�"�"�"�"��"�"�"�	
�	
�	
�	
�	
�O�	
�	
�	
�

�

�

�

�

�_�

�

�

�)�)�)�)�)�o�)�)�)�*�*�*�*�*��*�*�*�*�*�*�*�*��*�*�*�+�+�+�+�+��+�+�+�%�%�%�%�%�m�%�%�%�
T4�T4�T4�T4�T4�g�T4�T4�T4�nr8�r8�r8�r8�r8�G�r8�r8�r8�n
��T�T�T�T�pGL�x'�x'�x'�x'�x'�x'r