%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /opt/alt/python37/lib/python3.7/site-packages/alembic/autogenerate/__pycache__/
Upload File :
Create Path :
Current File : //opt/alt/python37/lib/python3.7/site-packages/alembic/autogenerate/__pycache__/api.cpython-37.pyc

B

�M!Vz9�@s�dZddlmZddlmZddlmZddlmZddlmZdd	l	Z	d
d�Z
dd
�Zddd�Zdd�Z
Gdd�de�ZGdd�de�Zd	S)zXProvide the 'autogenerate' feature which can produce migration operations
automatically.�)�ops�)�render)�compare)�util�)�	InspectorNcCst||�}|j��S)a�
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.schema import SchemaItem
        from sqlalchemy.types import TypeEngine
        from sqlalchemy import (create_engine, MetaData, Column,
                Integer, String, Table)
        import pprint

        engine = create_engine("sqlite://")

        engine.execute('''
            create table foo (
                id integer not null primary key,
                old_data varchar,
                x integer
            )''')

        engine.execute('''
            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(bind=None),
                Column('info', String(), table=<bat>), schema=None)),
          ( 'remove_table',
            Table(u'bar', MetaData(bind=None),
                Column(u'data', VARCHAR(), table=<bar>), schema=None)),
          ( 'add_column',
            None,
            'foo',
            Column('data', Integer(), table=<foo>)),
          ( 'remove_column',
            None,
            'foo',
            Column(u'old_data', VARCHAR(), table=None)),
          [ ( 'modify_nullable',
              None,
              'foo',
              u'x',
              { 'existing_server_default': None,
                'existing_type': INTEGER()},
              True,
              False)]]


    :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_opsZas_diffs)�context�metadata�migration_script�r�/api.py�compare_metadatasZ
rcCs8t||d�}tjdt�g�t�g�d�}t�||�|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`.

    .. versionadded:: 0.8.0

    .. seealso::

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

    )rN)�rev_idr
�
downgrade_ops)�AutogenContextr�MigrationScript�
UpgradeOps�DowngradeOpsr�_populate_migration_script)rr�autogen_contextr
rrrr	jsr	�sa.�op.FrcCs6||||d�}td|d�}t|�|_t�t�||��S)z�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.

    )�sqlalchemy_module_prefix�alembic_module_prefix�render_item�render_as_batchN)�opts)r�set�importsrZ_indentZ_render_cmd_body)Z
up_or_down_oprrrr!rrrrrr�render_python_code�s
r"cCsDt|�}t�g�}t�||�tjd||��d�}t�|||�dS)z6legacy, used by test_autogen_composition at the momentN)rr
r)	rrrrZ_produce_net_changesr�reverser� _render_python_into_templatevars)r�
template_argsrr
r
rrr�_render_migration_diffs�s
r&c@sReZdZdZdZdZdZdZdZddd�Z	e
jdd��Ze
jdd	��Zd
d�ZdS)
rzSMaintains configuration and state that's specific to an
    autogenerate operation.NTcs�|r|dk	r|jrt�d��|dkr*|j}|dkr>|�dd�n||_}|dkrt|dk	rt|jdk	rtt�d|jj��|�dd��|�dd�}g}�r��fdd�}|�|�|r�|�|�||_	||_
|j
dk	r�|j
j|_|j
j
|_
t�|_||_d|_dS)	Nz^autogenerate can't use as_sql=True as it prevents querying the database for schema informationZtarget_metadatazrCan't proceed with --autogenerate option; environment script %s does not provide a MetaData object to the context.�include_symbol�include_objectcs|dkr�||j�SdSdS)N�tableT)Zschema)�object�name�type_�	reflected�
compare_to)r'rr�include_symbol_filtersz6AutogenContext.__init__.<locals>.include_symbol_filterF)Zas_sqlr�CommandErrorr�getrZscriptZenv_py_location�append�_object_filters�migration_contextZbind�
connection�dialectr r!�
_has_batch)�selfr4rr�autogenerater(Zobject_filtersr/r)r'r�__init__�s:





zAutogenContext.__init__cCst�|j�S)N)rZfrom_enginer5)r8rrr�	inspector&szAutogenContext.inspectorccsd|_dVd|_dS)NTF)r7)r8rrr�
_within_batch*szAutogenContext._within_batchcCs,x&|jD]}||||||�sdSqWdSdS)a4Run 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`
        and :paramref:`.EnvironmentContext.configure.include_symbol`
        functions, if present.

        FTN)r3)r8Zobject_r+r,r-r.�fnrrr�run_filters0s
zAutogenContext.run_filters)NNT)�__name__�
__module__�__qualname__�__doc__rr5r6r!r4r:rZmemoized_propertyr;�
contextlib�contextmanagerr<r>rrrrr�s	
2rc@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�RevisionContextz^Maintains configuration and state that's specific to a revision
    file generation operation.cCs,||_||_||_d|i|_|��g|_dS)N�config)rF�script_directory�command_argsr%�_default_revision�generated_revisions)r8rFrGrHrrrr:Hs

zRevisionContext.__init__c	Cs�i}x"|j��D]\}}|�||�qWt|dd�rd|j}t�|_|jrV|j�|j�t�	|||�|j
j|j|j
fd|j|j|j|j|jd�|��S)N�
_needs_renderFT)Zrefresh�head�spliceZ
branch_labels�version_path�
depends_on)r%�items�
setdefault�getattr�_last_autogen_contextr r!Zunion_updaterr$rGZgenerate_revisionr�messagerLrM�branch_labelrNrO)r8r
r%�k�vrrrr�
_to_scriptTs(
zRevisionContext._to_scriptcCs|�||d�dS)NT)�_run_environment)r8�revr4rrr�run_autogeneratepsz RevisionContext.run_autogeneratecCs|�||d�dS)NF)rY)r8rZr4rrr�run_no_autogeneratessz#RevisionContext.run_no_autogeneratec	Cs|rB|jdrt�d��t|j�|��t|j�d��krBt�d��|jd}|jd}|jd}t|dd	�s�||j	d_
||jd_d
|_
n,|j�tjg|d��|j�tjg|d��t||d
�|_}|r�t�||�|jd}|r�||||j�x|jD]
}d
|_
q�WdS)NZsqlz7Using --sql with --autogenerate does not make any senseZheadsz"Target database is not up to date.�
upgrade_token�downgrade_token���rKFT)r])r^)r9Zprocess_revision_directives)rHrr0r rGZ
get_revisionsrrJrRZupgrade_ops_listr]Zdowngrade_ops_listr^rKZ_upgrade_opsr2rrZ_downgrade_opsrrrSrr)	r8rZr4r9r]r^r
r�hookrrrrYvs6





z RevisionContext._run_environmentcCs^tj|jdpt��|jdt�g�t�g�|jd|jd|jd|jd|jdd�	}|S)	NrrTrLrMrUrNrO)	rrTr
rrLrMrUrNrO)rrrHrrrr)r8�oprrrrI�sz!RevisionContext._default_revisionccs x|jD]}|�|�VqWdS)N)rJrX)r8Zgenerated_revisionrrr�generate_scripts�sz RevisionContext.generate_scriptsN)r?r@rArBr:rXr[r\rYrIrbrrrrrEDs(rE)rrFrN)rBZ
operationsr�rrrZsqlalchemy.engine.reflectionrrCrr	r"r&r*rrErrrr�<module>s"^!


Zerion Mini Shell 1.0