403Webshell
Server IP : 192.158.238.246  /  Your IP : 18.222.25.95
Web Server : LiteSpeed
System : Linux uniform.iwebfusion.net 4.18.0-553.27.1.lve.1.el8.x86_64 #1 SMP Wed Nov 20 15:58:00 UTC 2024 x86_64
User : jenniferflocom ( 1321)
PHP Version : 8.1.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /opt/alt/python37/lib/python3.7/site-packages/alembic/runtime/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/alt/python37/lib/python3.7/site-packages/alembic/runtime/__pycache__/migration.cpython-37.pyc
B

�M!Vn�@s�ddlZddlZddlmZddlmZmZmZmZm	Z	ddl
mZddlm
ZddlmZmZddlmZmZe�e�ZGd	d
�d
e�ZGdd�de�ZGd
d�de�ZGdd�de�ZGdd�de�ZdS)�N)�contextmanager)�MetaData�Table�Column�String�literal_column)�MockEngineStrategy)�url�)�callable�	EncodedIO)�ddl�utilc@s�eZdZdZd"dd�Zed#dd��Zd$dd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
d%dd�Zdd�Zedd��Zedd��Zdd�Zd d!�ZdS)&�MigrationContexta�Represent 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	sht�n||_|�d�|_	||_
d|kr�t|�d�p�tj
|d�|_n|�dtj
�|_|�d	d�|_|�d
d�|_|�dd�|_}|�d
d�|_}t|t�tdtd�dd�|d�|_|�d�|_tj�|�||j|j
||j|�|_t�d|jjj �|j
�rdt�d�t�d|jj!�rxdnd�dS)N�script�as_sqlF�transactional_ddlZtransaction_per_migration�fnZoutput_encoding�
output_buffer�compare_type�compare_server_default�
version_tableZalembic_version�version_table_schema�version_num� )Znullable)ZschemaZstarting_revzContext impl %s.zGenerating static SQLzWill assume %s DDL.Z
transactionalznon-transactional)"�environment_context�opts�dialect�getr�_transaction_per_migration�_stdout_connection�
connection�AssertionError�_migrations_fnrr�sys�stdoutr�_user_compare_type�_user_compare_server_defaultrrrrrr�_version�_start_from_revr
ZDefaultImplZget_by_dialect�impl�log�info�	__class__�__name__r)	�selfrr!rrrrrr�r0�J/opt/alt/python37/lib/python3.7/site-packages/alembic/runtime/migration.py�__init__>sT





zMigrationContext.__init__cCsj|dkri}|r|j}nD|r2t�|�}|���}n*|rPt�d|�}|���}n|s\td��t||||�S)a�Create 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.)r�sqla_urlZmake_urlZget_dialect�	Exceptionr)�clsr!r	Zdialect_namerrrr0r0r1�	configurets
zMigrationContext.configureFcsd|�jk}|s tdd��}|�S�jjs:tdd��}|�S�jrVt�fdd��}|�S�j��SdS)Ncss
dVdS)Nr0r0r0r0r1�
do_nothing�sz6MigrationContext.begin_transaction.<locals>.do_nothingcss
dVdS)Nr0r0r0r0r1r7�sc3s�j��dV�j��dS)N)r*Z
emit_beginZemit_commitr0)r/r0r1�begin_commit�s
z8MigrationContext.begin_transaction.<locals>.begin_commit)rrr*rr�bind�begin)r/�_per_migrationZtransaction_nowr7r8r0)r/r1�begin_transaction�s
z"MigrationContext.begin_transactioncCsB|��}t|�dkrdSt|�dkr6t�d|j��n|dSdS)a�Return 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.

        rN�zQVersion table '%s' has more than one head present; please use get_current_heads())�get_current_heads�lenr�CommandErrorr)r/�headsr0r0r1�get_current_revision�sz%MigrationContext.get_current_revisioncCsr|jr6|j}|dk	r(|jr(|j�|�j}tj|dd�S|jrFt�d��|��sRdSt	dd�|j
�|j�
��D��S)a�Return 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)�.0�rowr0r0r1�	<genexpr>�sz5MigrationContext.get_current_heads.<locals>.<genexpr>)rr)r�get_revision�revisionr�to_tupler@�_has_version_table�tupler!�executer(�select)r/Zstart_from_revr0r0r1r>�sz"MigrationContext.get_current_headscCs|jj|jdd�dS)NT)Z
checkfirst)r(�creater!)r/r0r0r1�_ensure_version_table�sz&MigrationContext._ensure_version_tablecCs|jj�|j|j|j�S)N)r!rZ	has_tablerr)r/r0r0r1rJ�sz#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>rrO�HeadMaintainerZ_stamp_revs�update_to_step)r/Zscript_directoryrHrA�head_maintainer�stepr0r0r1�stamps

zMigrationContext.stampc
Ks�|j��|��}|js$|s$|��t||�}x�|�||�D]r}|jdd��\|jrh|jsh|j	�
|j�t�
d|�|jr�|j�d|jf�|jf|�|�|�WdQRXq<W|jr�|js�|j	�|j�dS)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>rrOrPr#r<rAr(rNr!r+r,Z
static_output�	short_log�migration_fnrQZdrop)r/�kwrArRrSr0r0r1�run_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_optionsr0r0r1rLDs	zMigrationContext.executecs�fdd�}t��j|�S)Ncs�j�|�dS)N)r*rY)Z	constructZmultiparams�params)r/r0r1�dumpPsz1MigrationContext._stdout_connection.<locals>.dump)rZMockConnectionr)r/r!r[r0)r/r1r Osz#MigrationContext._stdout_connectioncCs|jS)a�Return 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)r�config)r/r0r0r1r\jszMigrationContext.configcCsH|jdkrdSt|j�r:|�||||j|j�}|dk	r:|S|j�||�S)NF)r&r�typer*r)r/�inspector_column�metadata_column�
user_valuer0r0r1�
_compare_typevs

zMigrationContext._compare_typecCsL|jdkrdSt|j�r:|�|||||j|�}|dk	r:|S|j�||||�S)NF)r'rZserver_defaultr*r)r/r^r_Zrendered_metadata_defaultZrendered_column_defaultr`r0r0r1�_compare_server_default�s"

z(MigrationContext._compare_server_default)N)NNNNNN)F)N)r.�
__module__�__qualname__�__doc__r2�classmethodr6r<rBr>rOrJrTrXrLr �propertyr9r\rarbr0r0r0r1rs,-
6&
&2
rc@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)rPcCs||_t|�|_dS)N)�context�setrA)r/rhrAr0r0r1r2�szHeadMaintainer.__init__cCsD||jkst�|j�|�|jj�|jj��jt	d|�d��dS)Nz'%s')r)
rAr"�addrhr*rYr(�insert�valuesr)r/�versionr0r0r1�_insert_version�s
zHeadMaintainer._insert_versioncCsl|j�|�|jj�|jj���|jjjj	t
d|�k��}|jjsh|jdkrht
�d||jj|jf��dS)Nz'%s'r=zOOnline migration expected to match one row when deleting '%s' in '%s'; %d found)rA�removerhr*rYr(�delete�where�crrr�rowcountrr@r)r/rm�retr0r0r1�_delete_version�s
zHeadMaintainer._delete_versioncCs�||jkst�|j�|�|j�|�|jj�|jj��j	t
d|�d��|jjjj
t
d|�k��}|jjs�|jdkr�t�d|||jj|jf��dS)Nz'%s')rr=zWOnline migration expected to match one row when updating '%s' to '%s' in '%s'; %d found)rAr"rorjrhr*rYr(�updaterlrrqrrrrrsrr@r)r/�from_�to_rtr0r0r1�_update_version�s
zHeadMaintainer._update_versioncCs*|�|j�r*|j}t�d|�|�|�n�|�|j�rT|j}t�d|�|�|�n�|�	|j�r�|�
|j�\}}}t�d|||�x|D]}|�|�q�W|�||�n~|�|j�r�|�
|j�\}}}t�d|||�x|D]}|�|�q�W|�||�n*|�|j�\}	}
t�d|	|
�|�|	|
�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_branchrA�delete_version_numr+�debugru�should_create_branch�insert_version_numrn�should_merge_branches�merge_branch_identsry�should_unmerge_branches�unmerge_branch_idents�update_version_num)r/rS�versZdelete_revsZupdate_from_revZ
update_to_revZdelrevZinsert_revsZinsrevrwrxr0r0r1rQ�s6



zHeadMaintainer.update_to_stepN)r.rcrdr2rnruryrQr0r0r0r1rP�s
rPc@sPeZdZedd��Zedd��Zedd��Zedd��Zed	d
��Z	dd�Z
d
S)�
MigrationStepcCs|jjS)N)rVr.)r/r0r0r1�name�szMigrationStep.namecCst||d�S)NT)�RevisionStep)r5�revision_maprr0r0r1�upgrade_from_script�sz!MigrationStep.upgrade_from_scriptcCst||d�S)NF)r�)r5r�rr0r0r1�downgrade_from_scriptsz#MigrationStep.downgrade_from_scriptcCs|jS)N)�
is_upgrade)r/r0r0r1�is_downgradeszMigrationStep.is_downgradecCs d|jt�|j�t�|j�fS)Nz%s %s -> %s)r�r�format_as_comma�from_revisions�to_revisions)r/r0r0r1rUs
zMigrationStep.short_logcCs4|jr*d|jt�|j�t�|j�|jfS|jSdS)Nz%s %s -> %s, %s)�docr�rr�r�r�rU)r/r0r0r1�__str__s


zMigrationStep.__str__N)r.rcrdrgr�rfr�r�r�rUr�r0r0r0r1r��sr�c@s�eZdZdd�Zdd�Zedd��Zedd��Zed	d
��Zedd��Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zedd��Zedd��ZdS) r�cCs0||_||_||_|r"|jj|_n
|jj|_dS)N)r�rHr��moduleZupgraderVZ	downgrade)r/r�rHr�r0r0r1r2szRevisionStep.__init__cCs"t|t�o |j|jko |j|jkS)N)�
isinstancer�rHr�)r/�otherr0r0r1�__eq__&s
zRevisionStep.__eq__cCs|jjS)N)rHr�)r/r0r0r1r�+szRevisionStep.doccCs|jr|jjS|jjfSdS)N)r�rH�_all_down_revisions)r/r0r0r1r�/szRevisionStep.from_revisionscCs|jr|jjfS|jjSdS)N)r�rHr�)r/r0r0r1r�6s
zRevisionStep.to_revisionscCst|jj�dkS)Nr=)r?rHr�)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
�dd�D��}t|�|��|jjg��r�dSdSndSdS)NFTr=rcss|]}|jVqdS)N)rH)rD�rr0r0r1rFSsz4RevisionStep.should_delete_branch.<locals>.<genexpr>)�check)
r�rHr�r?r�rGZ_is_real_branch_pointriZ_get_descendant_nodes�
get_revisionsZ_all_nextrev�intersection�
difference)r/rA�downrevs�downrevZdescendantsr0r0r1rzAs(
z!RevisionStep.should_delete_branchcCszt|��|j�}|rPtdd�|jj|j�|�dd�D��}tt|j��|��}n
t|j�}t|dd��|d|jdfS)Ncss|]}|jVqdS)N)rH)rDr�r0r0r1rFvsz3RevisionStep.merge_branch_idents.<locals>.<genexpr>F)r�r���)rir�r�r��_get_ancestor_nodesr��listr�)r/rA�other_heads�	ancestorsr�r0r0r1r�qs

z RevisionStep.merge_branch_identscCsvt|��|jjg�}|rTtdd�|jj|j�|�dd�D��}tt|j��|��}n|j}|jd|d|dd�fS)Ncss|]}|jVqdS)N)rH)rDr�r0r0r1rF�sz5RevisionStep.unmerge_branch_idents.<locals>.<genexpr>F)r�rr�)	rir�rHr�r�r�r�r�r�)r/rAr�r�r�r0r0r1r��s
z"RevisionStep.unmerge_branch_identscCs0|js
dS|jj}|sdS|�|�s(dSdSdS)NFT)r�rHr�r�)r/rAr�r0r0r1r}�s
z!RevisionStep.should_create_branchcCs8|js
dS|jj}t|�dkr4t|�|��dkr4dSdS)NFr=T)r�rHr�r?r�)r/rAr�r0r0r1r�sz"RevisionStep.should_merge_branchescCs2|js
dS|jj}|jj|kr.t|�dkr.dSdS)NFr=T)r�rHr�r?)r/rAr�r0r0r1r��sz$RevisionStep.should_unmerge_branchescCsd|js6|�|jj�}t|�dks(td��t|�d}n|jjd}|jrT||jjfS|jj|fSdS)Nr=z4Can't do an UPDATE because downrevision is ambiguousr)r�r�rHr�r?r"r�r�)r/rAr�Z
down_revisionr0r0r1r��szRevisionStep.update_version_numcCs|jjS)N)rH)r/r0r0r1r{�szRevisionStep.delete_version_numcCs|jjS)N)rH)r/r0r0r1r~�szRevisionStep.insert_version_numN)r.rcrdr2r�rgr�r�r�r�rzr�r�r}rr�r�r{r~r0r0r0r1r�s	0r�c@s�eZdZdd�ZdZdd�Zdd�Zedd	��Zed
d��Z	edd
��Z
edd��Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�ZdS)�	StampStepcCs8tj|dd�|_tj|dd�|_||_||_|j|_dS)Nr0)rC)rrIrwrxr��branch_move�stamp_revisionrV)r/rwrxr�r�r0r0r1r2�s
zStampStep.__init__NcKsdS)Nr0)r/rWr0r0r1r��szStampStep.stamp_revisioncCs:t|t�o8|j|jko8|j|jko8|j|jko8|j|jkS)N)r�r�r�Z	revisionsr�r�r�)r/r�r0r0r1r��s

zStampStep.__eq__cCs|jS)N)rw)r/r0r0r1r��szStampStep.from_revisionscCs|jS)N)rx)r/r0r0r1r��szStampStep.to_revisionscCst|j�dkst�|jdS)Nr=r)r?rwr")r/r0r0r1r{�szStampStep.delete_version_numcCst|j�dkst�|jdS)Nr=r)r?rxr")r/r0r0r1r~�szStampStep.insert_version_numcCs8t|j�dkst�t|j�dks$t�|jd|jdfS)Nr=r)r?rwr"rx)r/rAr0r0r1r�szStampStep.update_version_numcCs$t|jdd��|jd|jdfS)Nrr�)r�rwrx)r/rAr0r0r1r�szStampStep.merge_branch_identscCs$|jd|jdt|jdd��fS)Nrr�)rwrxr�)r/rAr0r0r1r�szStampStep.unmerge_branch_identscCs|jo
|jS)N)r�r�)r/rAr0r0r1rzszStampStep.should_delete_branchcCs|jo
|jS)N)r�r�)r/rAr0r0r1r}szStampStep.should_create_branchcCst|j�dkS)Nr=)r?rw)r/rAr0r0r1rszStampStep.should_merge_branchescCst|j�dkS)Nr=)r?rx)r/rAr0r0r1r�sz!StampStep.should_unmerge_branches)r.rcrdr2r�r�r�rgr�r�r{r~r�r�r�rzr}rr�r0r0r0r1r��sr�)�loggingr$�
contextlibrZ
sqlalchemyrrrrrZsqlalchemy.engine.strategiesrZsqlalchemy.enginer	r3Zutil.compatrr�r
r�	getLoggerr.r+�objectrrPr�r�r�r0r0r0r1�<module>s"
S%A

Youez - 2016 - github.com/yon3zu
LinuXploit