• File: migration.cpython-37.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/opt/alt/python37/lib/python3.7/site-packages/alembic/runtime/__pycache__/migration.cpython-37.pyc
  • Date Modified: 06/27/2022 11:08 PM
  • File size: 23.46 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit
B

M!Vn@sddlZddlZddlmZddlmZmZmZmZm	Z	ddl
mZddlm
ZddlmZmZddlmZmZeeZGd	d
d
eZGdddeZGd
ddeZGdddeZGdddeZdS)N)contextmanager)MetaDataTableColumnStringliteral_column)MockEngineStrategy)url)callable	EncodedIO)ddlutilc@seZdZdZd"ddZed#ddZd$dd	Zd
dZdd
Z	ddZ
ddZddZddZ
d%ddZddZeddZeddZddZd d!ZdS)&MigrationContextaRepresent the database state made available to a migration
    script.

    :class:`.MigrationContext` is the front end to an actual
    database connection, or alternatively a string output
    stream given a particular database dialect,
    from an Alembic perspective.

    When inside the ``env.py`` script, the :class:`.MigrationContext`
    is available via the
    :meth:`.EnvironmentContext.get_context` method,
    which is available at ``alembic.context``::

        # from within env.py script
        from alembic import context
        migration_context = context.get_context()

    For usage outside of an ``env.py`` script, such as for
    utility routines that want to check the current version
    in the database, the :meth:`.MigrationContext.configure`
    method to create new :class:`.MigrationContext` objects.
    For example, to get at the current revision in the
    database using :meth:`.MigrationContext.get_current_revision`::

        # in any application, outside of an env.py script
        from alembic.migration import MigrationContext
        from sqlalchemy import create_engine

        engine = create_engine("postgresql://mydatabase")
        conn = engine.connect()

        context = MigrationContext.configure(conn)
        current_rev = context.get_current_revision()

    The above context can also be used to produce
    Alembic migration operations with an :class:`.Operations`
    instance::

        # in any application, outside of the normal Alembic environment
        from alembic.operations import Operations
        op = Operations(context)
        op.alter_column("mytable", "somecolumn", nullable=True)

    Nc	Cs||_||_||_|d|_|dd}|d}|dd|_|rb|||_|jdk	shtn||_|d|_	||_
d|krt|dptj
|d|_n|dtj
|_|d	d|_|d
d|_|dd|_}|d
d|_}t|ttdtddd|d|_|d|_tj|||j|j
||j||_td|jjj |j
rdtdtd|jj!rxdnddS)Nscriptas_sqlFtransactional_ddlZtransaction_per_migrationfnZoutput_encoding
output_buffercompare_typecompare_server_default
version_tableZalembic_versionversion_table_schemaversion_num )Znullable)ZschemaZstarting_revzContext impl %s.zGenerating static SQLzWill assume %s DDL.Z
transactionalznon-transactional)"environment_contextoptsdialectgetr_transaction_per_migration_stdout_connection
connectionAssertionError_migrations_fnrrsysstdoutr_user_compare_type_user_compare_server_defaultrrrrrr_version_start_from_revr
ZDefaultImplZget_by_dialectimplloginfo	__class____name__r)	selfrr!rrrrrrr0J/opt/alt/python37/lib/python3.7/site-packages/alembic/runtime/migration.py__init__>sT





zMigrationContext.__init__cCsj|dkri}|r|j}nD|r2t|}|}n*|rPtd|}|}n|s\tdt||||S)aCreate a new :class:`.MigrationContext`.

        This is a factory method usually called
        by :meth:`.EnvironmentContext.configure`.

        :param connection: a :class:`~sqlalchemy.engine.Connection`
         to use for SQL execution in "online" mode.  When present,
         is also used to determine the type of dialect in use.
        :param url: a string database url, or a
         :class:`sqlalchemy.engine.url.URL` object.
         The type of dialect to be used will be derived from this if
         ``connection`` is not passed.
        :param dialect_name: string name of a dialect, such as
         "postgresql", "mssql", etc.  The type of dialect to be used will be
         derived from this if ``connection`` and ``url`` are not passed.
        :param opts: dictionary of options.  Most other options
         accepted by :meth:`.EnvironmentContext.configure` are passed via
         this dictionary.

        Nz%s://z-Connection, url, or dialect_name is required.)rsqla_urlZmake_urlZget_dialect	Exceptionr)clsr!r	Zdialect_namerrrr0r0r1	configurets
zMigrationContext.configureFcsd|jk}|s tdd}|Sjjs:tdd}|SjrVtfdd}|SjSdS)Ncss
dVdS)Nr0r0r0r0r1
do_nothingsz6MigrationContext.begin_transaction.<locals>.do_nothingcss
dVdS)Nr0r0r0r0r1r7sc3sjdVjdS)N)r*Z
emit_beginZemit_commitr0)r/r0r1begin_commits
z8MigrationContext.begin_transaction.<locals>.begin_commit)rrr*rrbindZbegin)r/_per_migrationZtransaction_nowr7r8r0)r/r1begin_transactions
z"MigrationContext.begin_transactioncCsB|}t|dkrdSt|dkr6td|jn|dSdS)aReturn the current revision, usually that which is present
        in the ``alembic_version`` table in the database.

        This method intends to be used only for a migration stream that
        does not contain unmerged branches in the target database;
        if there are multiple branches present, an exception is raised.
        The :meth:`.MigrationContext.get_current_heads` should be preferred
        over this method going forward in order to be compatible with
        branch migration support.

        If this :class:`.MigrationContext` was configured in "offline"
        mode, that is with ``as_sql=True``, the ``starting_rev``
        parameter is returned instead, if any.

        rNzQVersion table '%s' has more than one head present; please use get_current_heads())get_current_headslenrCommandErrorr)r/headsr0r0r1get_current_revisionsz%MigrationContext.get_current_revisioncCsr|jr6|j}|dk	r(|jr(|j|j}tj|ddS|jrFtd|sRdSt	dd|j
|j
DS)aReturn a tuple of the current 'head versions' that are represented
        in the target database.

        For a migration stream without branches, this will be a single
        value, synonymous with that of
        :meth:`.MigrationContext.get_current_revision`.   However when multiple
        unmerged branches exist within the target database, the returned tuple
        will contain a value for each head.

        If this :class:`.MigrationContext` was configured in "offline"
        mode, that is with ``as_sql=True``, the ``starting_rev``
        parameter is returned in a one-length tuple.

        If no version table is present, or if there are no revisions
        present, an empty tuple is returned.

        .. versionadded:: 0.7.0

        Nr0)defaultzECan't specify current_rev to context when using a database connectioncss|]}|dVqdS)rNr0).0rowr0r0r1	<genexpr>sz5MigrationContext.get_current_heads.<locals>.<genexpr>)rr)rget_revisionrevisionrto_tupler?_has_version_tabletupler!executer(Zselect)r/Zstart_from_revr0r0r1r=sz"MigrationContext.get_current_headscCs|jj|jdddS)NT)Z
checkfirst)r(creater!)r/r0r0r1_ensure_version_tablesz&MigrationContext._ensure_version_tablecCs|jj|j|j|jS)N)r!rZ	has_tablerr)r/r0r0r1rIsz#MigrationContext._has_version_tablecCsH|}|js|s|t||}x|||D]}||q2WdS)a}Stamp the version table with a specific revision.

        This method calculates those branches to which the given revision
        can apply, and updates those branches as though they were migrated
        towards that revision (either up or down).  If no current branches
        include the revision, it is added as a new branch head.

        .. versionadded:: 0.7.0

        N)r=rrMHeadMaintainerZ_stamp_revsupdate_to_step)r/Zscript_directoryrGr@head_maintainerstepr0r0r1stamps

zMigrationContext.stampc
Ks|j|}|js$|s$|t||}x|||D]r}|jdd\|jrh|jsh|j	
|jt
d||jr|jd|jf|jf|||WdQRXq<W|jr|js|j	|jdS)a-Run the migration scripts established for this
        :class:`.MigrationContext`, if any.

        The commands in :mod:`alembic.command` will set up a function
        that is ultimately passed to the :class:`.MigrationContext`
        as the ``fn`` argument.  This function represents the "work"
        that will be done when :meth:`.MigrationContext.run_migrations`
        is called, typically from within the ``env.py`` script of the
        migration environment.  The "work function" then provides an iterable
        of version callables and other version information which
        in the case of the ``upgrade`` or ``downgrade`` commands are the
        list of version scripts to invoke.  Other commands yield nothing,
        in the case that a command wants to run some other operation
        against the database such as the ``current`` or ``stamp`` commands.

        :param \**kw: keyword arguments here will be passed to each
         migration callable, that is the ``upgrade()`` or ``downgrade()``
         method within revision scripts.

        T)r:z
Running %sz
-- Running %sN)r*Zstart_migrationsr=rrMrNr#r;r@r(rLr!r+r,Z
static_output	short_logmigration_fnrOZdrop)r/kwr@rPrQr0r0r1run_migrationss 


zMigrationContext.run_migrationscCs|j||dS)aExecute a SQL construct or string statement.

        The underlying execution mechanics are used, that is
        if this is "offline mode" the SQL is written to the
        output buffer, otherwise the SQL is emitted on
        the current SQLAlchemy connection.

        N)r*_exec)r/ZsqlZexecution_optionsr0r0r1rKDs	zMigrationContext.executecsfdd}tj|S)Ncsj|dS)N)r*rW)Z	constructZmultiparamsZparams)r/r0r1dumpPsz1MigrationContext._stdout_connection.<locals>.dump)rZMockConnectionr)r/r!rXr0)r/r1r Osz#MigrationContext._stdout_connectioncCs|jS)aReturn the current "bind".

        In online mode, this is an instance of
        :class:`sqlalchemy.engine.Connection`, and is suitable
        for ad-hoc execution of any kind of usage described
        in :ref:`sqlexpression_toplevel` as well as
        for usage with the :meth:`sqlalchemy.schema.Table.create`
        and :meth:`sqlalchemy.schema.MetaData.create_all` methods
        of :class:`~sqlalchemy.schema.Table`,
        :class:`~sqlalchemy.schema.MetaData`.

        Note that when "standard output" mode is enabled,
        this bind will be a "mock" connection handler that cannot
        return results and is only appropriate for a very limited
        subset of commands.

        )r!)r/r0r0r1r9UszMigrationContext.bindcCs|jr|jjSdSdS)zoReturn the :class:`.Config` used by the current environment, if any.

        .. versionadded:: 0.6.6

        N)rconfig)r/r0r0r1rYjszMigrationContext.configcCsH|jdkrdSt|jr:|||||j|j}|dk	r:|S|j||S)NF)r&rtyper*r)r/inspector_columnmetadata_column
user_valuer0r0r1
_compare_typevs

zMigrationContext._compare_typecCsL|jdkrdSt|jr:||||||j|}|dk	r:|S|j||||S)NF)r'rZserver_defaultr*r)r/r[r\Zrendered_metadata_defaultZrendered_column_defaultr]r0r0r1_compare_server_defaults"

z(MigrationContext._compare_server_default)N)NNNNNN)F)N)r.
__module____qualname____doc__r2classmethodr6r;rAr=rMrIrRrVrKr propertyr9rYr^r_r0r0r0r1rs,-
6&
&2
rc@s4eZdZddZddZddZddZd	d
ZdS)rNcCs||_t||_dS)N)contextsetr@)r/rer@r0r0r1r2szHeadMaintainer.__init__cCsD||jkst|j||jj|jjjt	d|ddS)Nz'%s')r)
r@r"addrer*rWr(insertvaluesr)r/versionr0r0r1_insert_versions
zHeadMaintainer._insert_versioncCsl|j||jj|jj|jjjj	t
d|k}|jjsh|jdkrht
d||jj|jfdS)Nz'%s'r<zOOnline migration expected to match one row when deleting '%s' in '%s'; %d found)r@removerer*rWr(deletewherecrrrrowcountrr?r)r/rjretr0r0r1_delete_versions
zHeadMaintainer._delete_versioncCs||jkst|j||j||jj|jjj	t
d|d|jjjj
t
d|k}|jjs|jdkrtd|||jj|jfdS)Nz'%s')rr<zWOnline migration expected to match one row when updating '%s' to '%s' in '%s'; %d found)r@r"rlrgrer*rWr(updaterirrnrorrrprr?r)r/from_to_rqr0r0r1_update_versions
zHeadMaintainer._update_versioncCs*||jr*|j}td|||n||jrT|j}td|||n|	|jr|
|j\}}}td|||x|D]}||qW|||n~||jr|
|j\}}}td|||x|D]}||qW|||n*||j\}	}
td|	|
||	|
dS)Nzbranch delete %sznew branch insert %sz!merge, delete %s, update %s to %sz#unmerge, insert %s, update %s to %szupdate %s to %s)should_delete_branchr@delete_version_numr+debugrrshould_create_branchinsert_version_numrkshould_merge_branchesmerge_branch_identsrvshould_unmerge_branchesunmerge_branch_identsupdate_version_num)r/rQZversZdelete_revsZupdate_from_revZ
update_to_revZdelrevZinsert_revsZinsrevrtrur0r0r1rOs6



zHeadMaintainer.update_to_stepN)r.r`rar2rkrrrvrOr0r0r0r1rNs
rNc@sPeZdZeddZeddZeddZeddZed	d
Z	ddZ
d
S)
MigrationStepcCs|jjS)N)rTr.)r/r0r0r1nameszMigrationStep.namecCst||dS)NT)RevisionStep)r5revision_maprr0r0r1upgrade_from_scriptsz!MigrationStep.upgrade_from_scriptcCst||dS)NF)r)r5rrr0r0r1downgrade_from_scriptsz#MigrationStep.downgrade_from_scriptcCs|jS)N)
is_upgrade)r/r0r0r1is_downgradeszMigrationStep.is_downgradecCs d|jt|jt|jfS)Nz%s %s -> %s)rrformat_as_commafrom_revisionsto_revisions)r/r0r0r1rSs
zMigrationStep.short_logcCs4|jr*d|jt|jt|j|jfS|jSdS)Nz%s %s -> %s, %s)docrrrrrrS)r/r0r0r1__str__s


zMigrationStep.__str__N)r.r`rardrrcrrrrSrr0r0r0r1rsrc@seZdZddZddZeddZeddZed	d
ZeddZ	d
dZ
ddZddZddZ
ddZddZddZeddZeddZdS) rcCs0||_||_||_|r"|jj|_n
|jj|_dS)N)rrGrmoduleZupgraderTZ	downgrade)r/rrGrr0r0r1r2szRevisionStep.__init__cCs"t|to |j|jko |j|jkS)N)
isinstancerrGr)r/otherr0r0r1__eq__&s
zRevisionStep.__eq__cCs|jjS)N)rGr)r/r0r0r1r+szRevisionStep.doccCs|jr|jjS|jjfSdS)N)rrG_all_down_revisions)r/r0r0r1r/szRevisionStep.from_revisionscCs|jr|jjfS|jjSdS)N)rrGr)r/r0r0r1r6s
zRevisionStep.to_revisionscCst|jjdkS)Nr<)r>rGr)r/r0r0r1_has_scalar_down_revision=sz&RevisionStep._has_scalar_down_revisioncCs|js
dS|jj|krdS|jj}|s*dSt|dkr|j|d}|jsPdStdd|jj|j	|j
ddD}t|||jjgrdSdSndSdS)NFTr<rcss|]}|jVqdS)N)rG)rCrr0r0r1rESsz4RevisionStep.should_delete_branch.<locals>.<genexpr>)check)
rrGrr>rrFZ_is_real_branch_pointrfZ_get_descendant_nodes
get_revisionsZ_all_nextrevintersection
difference)r/r@downrevsdownrevZdescendantsr0r0r1rwAs(
z!RevisionStep.should_delete_branchcCszt||j}|rPtdd|jj|j|ddD}tt|j|}n
t|j}t|dd|d|jdfS)Ncss|]}|jVqdS)N)rG)rCrr0r0r1rEvsz3RevisionStep.merge_branch_idents.<locals>.<genexpr>F)rr)rfrrr_get_ancestor_nodesrlistr)r/r@other_heads	ancestorsrr0r0r1r}qs

z RevisionStep.merge_branch_identscCsvt||jjg}|rTtdd|jj|j|ddD}tt|j|}n|j}|jd|d|ddfS)Ncss|]}|jVqdS)N)rG)rCrr0r0r1rEsz5RevisionStep.unmerge_branch_idents.<locals>.<genexpr>F)rrr)	rfrrGrrrrrr)r/r@rrrr0r0r1rs
z"RevisionStep.unmerge_branch_identscCs0|js
dS|jj}|sdS||s(dSdSdS)NFT)rrGrr)r/r@rr0r0r1rzs
z!RevisionStep.should_create_branchcCs8|js
dS|jj}t|dkr4t||dkr4dSdS)NFr<T)rrGrr>r)r/r@rr0r0r1r|sz"RevisionStep.should_merge_branchescCs2|js
dS|jj}|jj|kr.t|dkr.dSdS)NFr<T)rrGrr>)r/r@rr0r0r1r~sz$RevisionStep.should_unmerge_branchescCsd|js6||jj}t|dks(tdt|d}n|jjd}|jrT||jjfS|jj|fSdS)Nr<z4Can't do an UPDATE because downrevision is ambiguousr)rrrGrr>r"rr)r/r@rZ
down_revisionr0r0r1rszRevisionStep.update_version_numcCs|jjS)N)rG)r/r0r0r1rxszRevisionStep.delete_version_numcCs|jjS)N)rG)r/r0r0r1r{szRevisionStep.insert_version_numN)r.r`rar2rrdrrrrrwr}rrzr|r~rrxr{r0r0r0r1rs	0rc@seZdZddZdZddZddZedd	Zed
dZ	edd
Z
eddZddZddZ
ddZddZddZddZddZdS)	StampStepcCs8tj|dd|_tj|dd|_||_||_|j|_dS)Nr0)rB)rrHrtrurbranch_movestamp_revisionrT)r/rtrurrr0r0r1r2s
zStampStep.__init__NcKsdS)Nr0)r/rUr0r0r1rszStampStep.stamp_revisioncCs:t|to8|j|jko8|j|jko8|j|jko8|j|jkS)N)rrrZ	revisionsrrr)r/rr0r0r1rs

zStampStep.__eq__cCs|jS)N)rt)r/r0r0r1rszStampStep.from_revisionscCs|jS)N)ru)r/r0r0r1rszStampStep.to_revisionscCst|jdkst|jdS)Nr<r)r>rtr")r/r0r0r1rxszStampStep.delete_version_numcCst|jdkst|jdS)Nr<r)r>rur")r/r0r0r1r{szStampStep.insert_version_numcCs8t|jdkstt|jdks$t|jd|jdfS)Nr<r)r>rtr"ru)r/r@r0r0r1rszStampStep.update_version_numcCs$t|jdd|jd|jdfS)Nrr)rrtru)r/r@r0r0r1r}szStampStep.merge_branch_identscCs$|jd|jdt|jddfS)Nrr)rtrur)r/r@r0r0r1rszStampStep.unmerge_branch_identscCs|jo
|jS)N)rr)r/r@r0r0r1rwszStampStep.should_delete_branchcCs|jo
|jS)N)rr)r/r@r0r0r1rzszStampStep.should_create_branchcCst|jdkS)Nr<)r>rt)r/r@r0r0r1r|szStampStep.should_merge_branchescCst|jdkS)Nr<)r>ru)r/r@r0r0r1r~sz!StampStep.should_unmerge_branches)r.r`rar2rrrrdrrrxr{rr}rrwrzr|r~r0r0r0r1rsr)Zloggingr$
contextlibrZ
sqlalchemyrrrrrZsqlalchemy.engine.strategiesrZsqlalchemy.enginer	r3Zutil.compatrrr
rZ	getLoggerr.r+objectrrNrrrr0r0r0r1<module>s"
S%A