%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /opt/alt/python27/lib/python2.7/site-packages/alembic/autogenerate/
Upload File :
Create Path :
Current File : //opt/alt/python27/lib/python2.7/site-packages/alembic/autogenerate/api.pyo

�
�M!Vc@s�dZddlmZddlmZddlmZddlmZddlmZdd	l	Z	d
�Z
d�Zdd
edd	d�Zd�Zdefd��YZdefd��YZd	S(sXProvide the 'autogenerate' feature which can produce migration operations
automatically.i(topsi(trender(tcompare(tutili����(t	InspectorNcCst||�}|jj�S(s�
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.

    (tproduce_migrationstupgrade_opstas_diffs(tcontexttmetadatatmigration_script((sI/opt/alt/python27/lib/python2.7/site-packages/alembic/autogenerate/api.pytcompare_metadatasZcCsVt|d|�}tjdddtjg�dtjg��}tj||�|S(s�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	trev_idRt
downgrade_opsN(tAutogenContextRtMigrationScripttNonet
UpgradeOpstDowngradeOpsRt_populate_migration_script(RR	tautogen_contextR
((sI/opt/alt/python27/lib/python2.7/site-packages/alembic/autogenerate/api.pyRjs	ssa.sop.cCs\i|d6|d6|d6|d6}tdd|�}t|�|_tjtj||��S(s�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.

    tsqlalchemy_module_prefixtalembic_module_prefixtrender_itemtrender_as_batchtoptsN(RRtsettimportsRt_indentt_render_cmd_body(t
up_or_down_opRRRRRRR((sI/opt/alt/python27/lib/python2.7/site-packages/alembic/autogenerate/api.pytrender_python_code�s
cCsft|�}tjg�}tj||�tjddd|d|j��}tj	|||�dS(s6legacy, used by test_autogen_composition at the momentRRR
N(
RRRRt_produce_net_changesRRtreverseRt _render_python_into_templatevars(Rt
template_argsRRR
((sI/opt/alt/python27/lib/python2.7/site-packages/alembic/autogenerate/api.pyt_render_migration_diffs�s	RcBskeZdZdZdZdZdZdZdde	d�Z
ejd��Z
ejd��Zd�ZRS(sSMaintains configuration and state that's specific to an
    autogenerate operation.cs||r-|dk	r-|jr-tjd��n|dkrE|j}n|dkrc|jdd�n||_}|dkr�|dk	r�|jdk	r�tjd|jj��n|jdd��|jdd�}g}�r�fd�}|j	|�n|r|j	|�n||_
||_|jdk	rZ|jj|_
|jj|_nt�|_||_t|_dS(Ns^autogenerate can't use as_sql=True as it prevents querying the database for schema informationttarget_metadatasrCan't proceed with --autogenerate option; environment script %s does not provide a MetaData object to the context.tinclude_symboltinclude_objectcs$|dkr�||j�StSdS(Nttable(tschematTrue(tobjecttnamettype_t	reflectedt
compare_to(R&(sI/opt/alt/python27/lib/python2.7/site-packages/alembic/autogenerate/api.pytinclude_symbol_filters(Rtas_sqlRtCommandErrorRtgetR	tscripttenv_py_locationtappendt_object_filterstmigration_contexttbindt
connectiontdialectRRtFalset
_has_batch(tselfR8R	RtautogenerateR'tobject_filtersR0((R&sI/opt/alt/python27/lib/python2.7/site-packages/alembic/autogenerate/api.pyt__init__�s:+			cCstj|j�S(N(Rtfrom_engineR:(R>((sI/opt/alt/python27/lib/python2.7/site-packages/alembic/autogenerate/api.pyt	inspector&sccst|_dVt|_dS(N(R*R=R<(R>((sI/opt/alt/python27/lib/python2.7/site-packages/alembic/autogenerate/api.pyt
_within_batch*s	cCs8x1|jD]"}||||||�s
tSq
WtSdS(s4Run 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.

        N(R7R<R*(R>tobject_R,R-R.R/tfn((sI/opt/alt/python27/lib/python2.7/site-packages/alembic/autogenerate/api.pytrun_filters0s
N(t__name__t
__module__t__doc__RR	R:R;RR8R*RARtmemoized_propertyRCt
contextlibtcontextmanagerRDRG(((sI/opt/alt/python27/lib/python2.7/site-packages/alembic/autogenerate/api.pyR�s	2tRevisionContextcBsMeZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	RS(s^Maintains configuration and state that's specific to a revision
    file generation operation.cCsA||_||_||_i|d6|_|j�g|_dS(Ntconfig(ROtscript_directorytcommand_argsR#t_default_revisiontgenerated_revisions(R>RORPRQ((sI/opt/alt/python27/lib/python2.7/site-packages/alembic/autogenerate/api.pyRAHs			
cCs�i}x-|jj�D]\}}|j||�qWt|dt�r�|j}t�|_|jr||jj|j�nt	j
|||�n|jj|j
|jdtd|jd|jd|jd|jd|j|�S(Nt
_needs_rendertrefreshtheadtsplicet
branch_labelstversion_patht
depends_on(R#titemst
setdefaulttgetattrR<t_last_autogen_contextRRtunion_updateRR"RPtgenerate_revisionRtmessageR*RVRWtbranch_labelRYRZ(R>R
R#tktvR((sI/opt/alt/python27/lib/python2.7/site-packages/alembic/autogenerate/api.pyt
_to_scriptTs(								cCs|j||t�dS(N(t_run_environmentR*(R>trevR8((sI/opt/alt/python27/lib/python2.7/site-packages/alembic/autogenerate/api.pytrun_autogeneratepscCs|j||t�dS(N(RfR<(R>RgR8((sI/opt/alt/python27/lib/python2.7/site-packages/alembic/autogenerate/api.pytrun_no_autogeneratessc	Cs�|rj|jdr%tjd��nt|jj|��t|jjd��krjtjd��qjn|jd}|jd}|jd}t|dt	�s�||j
d_||jd_
t|_n>|jjtjgd|��|jjtjgd|��t|d	|�|_}|r?tj||�n|jd
}|rh||||j�nx|jD]}t|_qrWdS(Ntsqls7Using --sql with --autogenerate does not make any sensetheadss"Target database is not up to date.t
upgrade_tokentdowngrade_tokeni����RTR?tprocess_revision_directives(RQRR2RRPt
get_revisionsRRSR]R<tupgrade_ops_listRltdowngrade_ops_listRmR*RTt_upgrade_opsR6RRt_downgrade_opsRRR^RR(	R>RgR8R?RlRmR
Rthook((sI/opt/alt/python27/lib/python2.7/site-packages/alembic/autogenerate/api.pyRfvs6



		

cCs�tjd|jdptj�d|jddtjg�dtjg�d|jdd|jdd|jdd|jdd	|jd	�	}|S(
NRRaRR
RVRWRbRYRZ(RRRQRRRR(R>top((sI/opt/alt/python27/lib/python2.7/site-packages/alembic/autogenerate/api.pyRR�s	




ccs&x|jD]}|j|�Vq
WdS(N(RSRe(R>tgenerated_revision((sI/opt/alt/python27/lib/python2.7/site-packages/alembic/autogenerate/api.pytgenerate_scripts�s(
RHRIRJRAReRhRiRfRRRw(((sI/opt/alt/python27/lib/python2.7/site-packages/alembic/autogenerate/api.pyRNDs					(	((RJt
operationsRtRRRtsqlalchemy.engine.reflectionRRLRRR<RRR$R+RRN(((sI/opt/alt/python27/lib/python2.7/site-packages/alembic/autogenerate/api.pyt<module>s 	^	!	�

Zerion Mini Shell 1.0