Hacked By AnonymousFox

Current Path : /opt/cloudlinux/venv/lib64/python3.11/site-packages/alembic/autogenerate/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib64/python3.11/site-packages/alembic/autogenerate/__pycache__/api.cpython-311.pyc

�

�܋f�T����ddlmZddlZddlmZddlmZddlmZddlmZddlmZddlm	Z	dd	lm
Z
dd
lmZddlmZddl
mZd
dlmZd
dlmZddlmZddlmZ	erZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddl"m#Z#ddl"m$Z$ddl"m%Z%ddl&m'Z'dd l(m)Z)dd!l(m*Z*dGd(�Z+dHd*�Z,							dIdJd>�Z-dKdB�Z.GdC�dD��Z/GdE�dF��Z0dS)L�)�annotationsN)�Any)�Callable)�Dict)�Iterator)�Optional)�Sequence)�Set)�
TYPE_CHECKING)�Union)�inspect�)�compare)�render�)�util)�ops)�
Connection)�Dialect)�	Inspector)�MetaData)�
SchemaItem)�Config)�DowngradeOps)�MigrationScript)�
UpgradeOps)�NameFilterParentNames)�NameFilterType)�RenderItemFn��MigrationContext)�Script)�ScriptDirectory�contextr!�metadatar�returnrc�T�t||��}|j���S)aB
Compare a database schema to that given in a
    :class:`~sqlalchemy.schema.MetaData` instance.

    The database connection is presented in the context
    of a :class:`.MigrationContext` object, which
    provides database connectivity as well as optional
    comparison functions to use for datatypes and
    server defaults - see the "autogenerate" arguments
    at :meth:`.EnvironmentContext.configure`
    for details on these.

    The return format is a list of "diff" directives,
    each representing individual differences::

        from alembic.migration import MigrationContext
        from alembic.autogenerate import compare_metadata
        from sqlalchemy import (
            create_engine,
            MetaData,
            Column,
            Integer,
            String,
            Table,
            text,
        )
        import pprint

        engine = create_engine("sqlite://")

        with engine.begin() as conn:
            conn.execute(
                text(
                    '''
                        create table foo (
                            id integer not null primary key,
                            old_data varchar,
                            x integer
                        )
                    '''
                )
            )
            conn.execute(text("create table bar (data varchar)"))

        metadata = MetaData()
        Table(
            "foo",
            metadata,
            Column("id", Integer, primary_key=True),
            Column("data", Integer),
            Column("x", Integer, nullable=False),
        )
        Table("bat", metadata, Column("info", String))

        mc = MigrationContext.configure(engine.connect())

        diff = compare_metadata(mc, metadata)
        pprint.pprint(diff, indent=2, width=20)

    Output::

        [
            (
                "add_table",
                Table(
                    "bat",
                    MetaData(),
                    Column("info", String(), table=<bat>),
                    schema=None,
                ),
            ),
            (
                "remove_table",
                Table(
                    "bar",
                    MetaData(),
                    Column("data", VARCHAR(), table=<bar>),
                    schema=None,
                ),
            ),
            (
                "add_column",
                None,
                "foo",
                Column("data", Integer(), table=<foo>),
            ),
            [
                (
                    "modify_nullable",
                    None,
                    "foo",
                    "x",
                    {
                        "existing_comment": None,
                        "existing_server_default": False,
                        "existing_type": INTEGER(),
                    },
                    True,
                    False,
                )
            ],
            (
                "remove_column",
                None,
                "foo",
                Column("old_data", VARCHAR(), table=<foo>),
            ),
        ]

    :param context: a :class:`.MigrationContext`
     instance.
    :param metadata: a :class:`~sqlalchemy.schema.MetaData`
     instance.

    .. seealso::

        :func:`.produce_migrations` - produces a :class:`.MigrationScript`
        structure based on metadata comparison.

    )�produce_migrations�upgrade_ops�as_diffs)r$r%�migration_scripts   �O/opt/cloudlinux/venv/lib64/python3.11/site-packages/alembic/autogenerate/api.py�compare_metadatar-+s*��r*�'�8�<�<���'�0�0�2�2�2�rc���t||���}tjdtjg��tjg�����}tj||��|S)a�Produce a :class:`.MigrationScript` structure based on schema
    comparison.

    This function does essentially what :func:`.compare_metadata` does,
    but then runs the resulting list of diffs to produce the full
    :class:`.MigrationScript` object.   For an example of what this looks like,
    see the example in :ref:`customizing_revision`.

    .. seealso::

        :func:`.compare_metadata` - returns more fundamental "diff"
        data from comparing a schema.

    )r%N��rev_idr)�
downgrade_ops)�AutogenContextrrrrr�_populate_migration_script)r$r%�autogen_contextr+s    r,r(r(�sh��$%�W�x�@�@�@�O��*���N�2�&�&��&�r�*�*������&��8H�I�I�I��r.�sa.�op.F��
up_or_down_op�Union[UpgradeOps, DowngradeOps]�sqlalchemy_module_prefix�str�alembic_module_prefix�render_as_batch�bool�imports�
Sequence[str]�render_item�Optional[RenderItemFn]�migration_context�Optional[MigrationContext]�user_module_prefix�
Optional[str]c��|||||d�}|�%ddlm}	ddlm}
|	j|
�����}t||���}t
|��|_tj	tj
||����S)	a*Render Python code given an :class:`.UpgradeOps` or
    :class:`.DowngradeOps` object.

    This is a convenience function that can be used to test the
    autogenerate output of a user-defined :class:`.MigrationScript` structure.

    :param up_or_down_op: :class:`.UpgradeOps` or :class:`.DowngradeOps` object
    :param sqlalchemy_module_prefix: module prefix for SQLAlchemy objects
    :param alembic_module_prefix: module prefix for Alembic constructs
    :param render_as_batch: use "batch operations" style for rendering
    :param imports: sequence of import symbols to add
    :param render_item: callable to render items
    :param migration_context: optional :class:`.MigrationContext`
    :param user_module_prefix: optional string prefix for user-defined types

     .. versionadded:: 1.11.0

    )r;r=rBr>rFNrr r)�DefaultDialect)�dialect)�opts)�runtime.migrationr!�sqlalchemy.engine.defaultrI�	configurer3�setr@r�_indent�_render_cmd_body)r9r;r=r>r@rBrDrFrKr!rIr5s            r,�render_python_coderR�s���:%=�!6�"�*�0���D�� �8�8�8�8�8�8�<�<�<�<�<�<�6�,�6�"�N�$�$�
�
�
��%�%6�T�B�B�B�O�!�'�l�l�O���>���
��?�?���r.�
template_args�Dict[Any, Any]�Nonec���t|��}tjg��}tj||��tjd||������}tj|||��dS)z6legacy, used by test_autogen_composition at the momentNr0)	r3rrr�_produce_net_changesr�reverser� _render_python_into_templatevars)r$rSr5r)r+s     r,�_render_migration_diffsrZ�s���
%�W�-�-�O��.��$�$�K�� ��+�>�>�>��*���!�)�)�+�+������+��)�=�����r.c��eZdZUdZdZded<	dZded<	dZded<	dZd	ed
<	dZ	ded<				d(d)d�Z
ejd*d���Z
ejd+d���Zd,d�Zd-d%�ZeZejd&���Zejd'���ZdS).r3zSMaintains configuration and state that's specific to an
    autogenerate operation.N�Optional[MetaData]r%zOptional[Connection]�
connectionzOptional[Dialect]rJzSet[str]r@r!rDTrK�Optional[dict]�autogenerater?r&rUc�n�|r|�|jrtjd���|�|j}|�|�dd��n|x|_}|r,|�*|�(|j�!tjd|jjz���|�dd��}|�dd��}g}g}|r|�|��|r|�|��||_	||_
||_|j�"|jj|_
|jj|_t��|_||_d|_dS)Nz^autogenerate can't use as_sql=True as it prevents querying the database for schema information�target_metadataz�Can't proceed with --autogenerate option; environment script %s does not provide a MetaData object or sequence of objects to the context.�include_object�include_nameF)�as_sqlr�CommandErrorrK�getr%�script�env_py_location�append�_object_filters�
_name_filtersrD�bindr]rJrOr@�
_has_batch)	�selfrDr%rKr_rbrc�object_filters�name_filterss	         r,�__init__zAutogenContext.__init__Gs~��
�	�!�-�!�(�.��#�6���
�
�<�$�)�D�2:�1A�D�H�H�&��-�-�-�x�	
��
��

�	�� �!�-�!�(�4��#�K�%�+�;�=���
����"2�D�9�9���x�x���5�5�������	2��!�!�.�1�1�1��	.�����-�-�-�-���)���!2����!�-�"�4�9�D�O��1�9�D�L��u�u���$(��	� %����r.rc�V�|j�td���t|j��S)NzHcan't return inspector as this AutogenContext has no database connection)r]�	TypeErrorr
�rns r,�	inspectorzAutogenContext.inspector�s3���?�"��<���
��t��'�'�'r.�Iterator[None]c#�.K�d|_dV�d|_dS)NTF)rmrts r,�
_within_batchzAutogenContext._within_batch�s!�������
��������r.�namerG�type_r�parent_namesrc��d|vr;|dkr|}n|�dd��}|r|d}|r|�d|��|d<n||d<|jD]}||||��sdS�dS)	a�Run the context's name filters and return True if the targets
        should be part of the autogenerate operation.

        This method should be run for every kind of name encountered within the
        reflection side of an autogenerate operation, giving the environment
        the chance to filter what names should be reflected as database
        objects.  The filters here are produced directly via the
        :paramref:`.EnvironmentContext.configure.include_name` parameter.

        �schema_name�table�
table_nameN�.�schema_qualified_table_nameFT)rfrk)rnryrzr{rr}�fns       r,�run_name_filterszAutogenContext.run_name_filters�s��� �L�(�(�����!�
�
�)�-�-�l�D�A�A�
��
M�*�=�9���M�#���"�
�C�L�!>�?�?�
CM�L�!>�?��$�	�	�B��2�d�E�<�0�0�
��u�u�
��4r.�object_r�	reflected�
compare_to�Optional[SchemaItem]c�>�|jD]}||||||��sdS�dS)a�Run the context's object filters and return True if the targets
        should be part of the autogenerate operation.

        This method should be run for every kind of object encountered within
        an autogenerate operation, giving the environment the chance
        to filter what objects should be included in the comparison.
        The filters here are produced directly via the
        :paramref:`.EnvironmentContext.configure.include_object` parameter.

        FT)rj)rnr�ryrzr�r�r�s       r,�run_object_filtersz!AutogenContext.run_object_filters�sC��$�&�	�	�B��2�g�t�U�I�z�B�B�
��u�u�
��4r.c�v�g}tj|j��D]}|�|j���|S)aiReturn an aggregate of the :attr:`.MetaData.sorted_tables`
        collection(s).

        For a sequence of :class:`.MetaData` objects, this
        concatenates the :attr:`.MetaData.sorted_tables` collection
        for each individual :class:`.MetaData`  in the order of the
        sequence.  It does **not** collate the sorted tables collections.

        )r�to_listr%�extend�
sorted_tables)rn�result�ms   r,r�zAutogenContext.sorted_tables�s@������d�m�,�,�	+�	+�A��M�M�!�/�*�*�*�*��
r.c
�Z�i}tj|j��D]�}t|���t|j����}|r<t
dd�d�t|��D����z���|�	|j����|S)a�Return an aggregate  of the :attr:`.MetaData.tables` dictionaries.

        The :attr:`.MetaData.tables` collection is a dictionary of table key
        to :class:`.Table`; this method aggregates the dictionary across
        multiple :class:`.MetaData` objects into one dictionary.

        Duplicate table keys are **not** supported; if two :class:`.MetaData`
        objects contain the same table key, an exception is raised.

        z9Duplicate table keys across multiple MetaData objects: %sz, c3� K�|]	}d|zV��
dS)z"%s"Nr8)�.0�keys  r,�	<genexpr>z4AutogenContext.table_key_to_table.<locals>.<genexpr>�s&���� K� K�#��#�� K� K� K� K� K� Kr.)
rr�r%rO�intersection�tables�
ValueError�join�sorted�update)rnr�r��	intersects    r,�table_key_to_tablez!AutogenContext.table_key_to_table�s�������d�m�,�,�		$�		$�A��F���0�0��Q�X���?�?�I��
� �+��y�y� K� K��	�9J�9J� K� K� K�K�K�M����
�M�M�!�(�#�#�#�#��
r.)NNT)
rDr!r%r\rKr^r_r?r&rU)r&r)r&rv)ryrGrzrr{rr&r?)r�rryrGrzrr�r?r�r�r&r?)�__name__�
__module__�__qualname__�__doc__r%�__annotations__r]rJr@rDrqr�memoized_propertyru�
contextlib�contextmanagerrxr�r��run_filtersr�r�r8r.r,r3r3sp���������$(�H�'�'�'�'��"(,�J�+�+�+�+��"&�G�%�%�%�%���G������+/��.�.�.�.�N�
(,�#�!�:&�:&�:&�:&�:&�x
��(�(�(���(��� � � ��� �
$�$�$�$�L����0%�K�	��
�
���
�
��������r.r3c�N�eZdZdZ	ddd
�Zd d�Zd!d�Zd!d�Zd"d�Zd#d�Z	d$d�Z
dS)%�RevisionContextz^Maintains configuration and state that's specific to a revision
    file generation operation.N�configr�script_directoryr#�command_args�Dict[str, Any]�process_revision_directives�Optional[Callable]r&rUc��||_||_||_||_d|i|_|���g|_dS)Nr�)r�r�r�r�rS�_default_revision�generated_revisions)rnr�r�r�r�s     r,rqzRevisionContext.__init__sQ����� 0���(���+F��(��f�
���%)�$:�$:�$<�$<�#=�� � � r.r+r�Optional[Script]c
��|j���}t|dd��rV|j}t	��|_|jr|j�|j��tj|||��|j	�J�|j
j|j	|jfd|j
|j|j|j|jd�|��S)N�
_needs_renderFT)�refresh�head�splice�
branch_labels�version_path�
depends_on)rS�copy�getattr�_last_autogen_contextrOr@r�rrYr1r��generate_revision�messager�r��branch_labelr�r�)rnr+rSr5s    r,�
_to_scriptzRevisionContext._to_scripts���)-�(:�(?�(?�(A�(A�
��#�_�e�<�<�
	�"�8�O�'*�e�e�O�#��'�
I��'�.�.�/?�/G�H�H�H��3��!1�=�
�
�
� �&�2�2�2�6�t�$�6��#��$�

��!�&�#�*�*�7�)�6�'�2�

�

��

�

�
	
r.�rev�tuplerDr!c�4�|�||d��dS)NT��_run_environment�rnr�rDs   r,�run_autogeneratez RevisionContext.run_autogenerate/s#��	
���c�#4�d�;�;�;�;�;r.c�4�|�||d��dS)NFr�r�s   r,�run_no_autogeneratez#RevisionContext.run_no_autogenerate4s#��	
���c�#4�e�<�<�<�<�<r.r_r?c��|r�|jdrtjd���t|j�|����t|j�d����krtjd���|jd}|jd}|jd}t|dd	��s,||j	d_
||jd_d
|_
n\|j�t!jg|�����|j�t!jg|�����t)||�
��}||_|rt-j||��|jr|�|||j��|jd}|r||||j��|jD]	}d
|_
�
dS)N�sqlz7Using --sql with --autogenerate does not make any sense�headsz"Target database is not up to date.�
upgrade_token�downgrade_token���r�FT)r�)r�)r_r�)r�rrerOr��
get_revisionsrKr�r��upgrade_ops_listr��downgrade_ops_listr�r��_upgrade_opsrirr�_downgrade_opsrr3r�rr4r�)	rnr�rDr_r�r�r+r5�hooks	         r,r�z RevisionContext._run_environment9s5���	N�� ��'�
��'�M�����4�(�6�6�s�;�;�<�<���%�3�3�G�<�<�A�A����'�(L�M�M�M�)�.��?�
�+�0�1B�C���3�B�7���'��%�@�@�	�BO��-�b�1�?�!0�
�/��
��-1��*�*��)�0�0���r��?�?�?�
�
�
�
�+�2�2�� ��_�E�E�E�
�
�
�)��L�
�
�
��6E��"��	��.��!1�
�
�
��+�	��,�,�!�3��(@�
�
�
�!�%�&C�D���	C��D�"�C��)A�B�B�B� $� 8�	2�	2��-1��*�*�	2�	2r.c��|j}tj|dptj��|dtjg��tjg��|d|d|d|d|d��	�	}|S)	Nr1r�r�r�r�r�r�)	r1r�r)r2r�r�r�r�r�)r�rrrr1rr)rnr��ops   r,r�z!RevisionContext._default_revisionqs���'+�'8��
�
 ���)�:�T�[�]�]� ��+���r�*�*��*�2�.�.��f�%���)�%�n�5�%�n�5�#�L�1�

�

�

���	r.�Iterator[Optional[Script]]c#�LK�|jD]}|�|��V��dS�N)r�r�)rn�generated_revisions  r,�generate_scriptsz RevisionContext.generate_scripts�s?����"&�":�	6�	6���/�/�"4�5�5�5�5�5�5�	6�	6r.r�)
r�rr�r#r�r�r�r�r&rU)r+rr&r�)r�r�rDr!r&rU)r�r�rDr!r_r?r&rU)r&r)r&r�)r�r�r�r�rqr�r�r�r�r�r�r8r.r,r�r��s�������"�"�;?�>�>�>�>�>�"
�
�
�
�<<�<�<�<�
=�=�=�=�
62�62�62�62�p
�
�
�
�6�6�6�6�6�6r.r�)r$r!r%rr&r)r$r!r%rr&r)r6r7Fr8NNN)r9r:r;r<r=r<r>r?r@rArBrCrDrErFrGr&r<)r$r!rSrTr&rU)1�
__future__rr��typingrrrrrr	r
rr�
sqlalchemyr
�rrr�
operationsr�sqlalchemy.enginerrr�sqlalchemy.sql.schemarrr�r�operations.opsrrr�runtime.environmentrrrrLr!�script.baser"r#r-r(rRrZr3r�r8r.r,�<module>r�s��"�"�"�"�"�"����������������������������������������������� � � � � � ���������������������������������������.�,�,�,�,�,�,�)�)�)�)�)�)�+�+�+�+�+�+�.�.�.�.�.�.�0�0�0�0�0�0�������-�-�-�-�-�-�0�0�0�0�0�0�+�+�+�+�+�+�;�;�;�;�;�;�4�4�4�4�4�4�2�2�2�2�2�2�4�4�4�4�4�4�$�$�$�$�$�$�-�-�-�-�-�-�z3�z3�z3�z3�z����B%*�!&�!��*.�48�(,�0�0�0�0�0�f����*j�j�j�j�j�j�j�j�ZF6�F6�F6�F6�F6�F6�F6�F6�F6�F6r.

Hacked By AnonymousFox1.0, Coded By AnonymousFox