%PDF- %PDF-
Mini Shell

Mini Shell

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

B

�M!V��@s�ddlmZddlmZddlmZddlmZddlmZmZddl	Z	Gd	d
�d
e
�ZGdd�de�Ze�
d
�e�
d
d�Gdd�de���Ze�
d�e�
dd�Gdd�de���Ze�
d�e�
dd�Gdd�de���Ze�
d�e�
dd�Gdd�de���Ze�
d�e�
dd�Gdd �d e���Ze�
d!�e�
d!d"�Gd#d$�d$e���Ze�
d%�e�
d%d&�Gd'd(�d(e���Ze�
d)�Gd*d+�d+e��Ze�
d,�Gd-d.�d.e��ZGd/d0�d0e�Ze�
d1�Gd2d3�d3e��Ze�
d4�e�
d4d5�Gd6d7�d7e���Ze�
d8�e�
d8d9�Gd:d;�d;e���Ze�
d<�e�
d<d=�Gd>d?�d?e���Ze�
d@�GdAdB�dBe��Ze�
dC�GdDdE�dEe��ZGdFdG�dGe�ZGdHdI�dIe�ZGdJdK�dKe�Z GdLdM�dMe�Z!GdNdO�dOe�Z"dS)P�)�util)�sqla_compat�)�	schemaobj�)�NULLTYPE)�
Operations�BatchOperationsNc@seZdZdZejdd��ZdS)�MigrateOperationabase class for migration command and organization objects.

    This system is part of the operation extensibility API.

    .. versionadded:: 0.8.0

    .. seealso::

        :ref:`operation_objects`

        :ref:`operation_plugins`

        :ref:`customizing_revision`

    cCsiS)z�A dictionary that may be used to store arbitrary information
        along with this :class:`.MigrateOperation` object.

        �)�selfrr�/ops.py�infoszMigrateOperation.infoN)�__name__�
__module__�__qualname__�__doc__rZmemoized_propertyrrrrr
r
	sr
c@s8eZdZdZedd��Zedd��Zdd�Zdd	�Z	d
S)�AddConstraintOpz&Represent an add constraint operation.cCs
t��dS)N)�NotImplementedError)rrrr
�constraint_type&szAddConstraintOp.constraint_typecCs(tjtjtjtjtjd�}||j|�S)N)�unique_constraint�foreign_key_constraint�primary_key_constraint�check_constraint�column_check_constraint)�CreateUniqueConstraintOp�from_constraint�CreateForeignKeyOp�CreatePrimaryKeyOp�CreateCheckConstraintOp�__visit_name__)�cls�
constraintZfuncsrrr
r*s
zAddConstraintOp.from_constraintcCst�|���S)N)�DropConstraintOpr�
to_constraint)rrrr
�reverse5szAddConstraintOp.reversecCsd|��fS)NZadd_constraint)r$)rrrr
�
to_diff_tuple8szAddConstraintOp.to_diff_tupleN)
rrrr�propertyr�classmethodrr%r&rrrr
r#s
r�drop_constraint�batch_drop_constraintc@sheZdZdZddd�Zdd�Zdd�Zed	d
��Zdd�Z	ee
�d
dg�ddd���Zeddd��Z
dS)r#z&Represent a drop constraint operation.NcCs"||_||_||_||_||_dS)N)�constraint_name�
table_namer�schema�_orig_constraint)rr+r,�type_r-r.rrr
�__init__As
zDropConstraintOp.__init__cCs|jdkrtd��t�|j�S)Nz?operation is not reversible; original constraint is not present)r.�
ValueErrorrr)rrrr
r%Ks
zDropConstraintOp.reversecCs&|jdkrd|��fSd|��fSdS)N�
foreignkeyZ	remove_fkZremove_constraint)rr$)rrrr
r&Rs
zDropConstraintOp.to_diff_tuplecCs8dddddd�}t�|�}||j|j|j||j|d�S)N�uniquer2Zprimary�check)rrrrr)r-r/r.)r�_table_for_constraint�namer-r )r!r"�types�constraint_tablerrr
rXs
z DropConstraintOp.from_constraintcCs|jdk	r|jStd��dS)NzAconstraint cannot be produced; original constraint is not present)r.r1)rrrr
r$ks
zDropConstraintOp.to_constraint)�typer/)r6r+cCs|||||d�}|�|�S)aDrop a constraint of the given name, typically via DROP CONSTRAINT.

        :param constraint_name: name of the constraint.
        :param table_name: table name.
        :param ``type_``: optional, required on MySQL.  can be
         'foreignkey', 'primary', 'unique', or 'check'.
        :param schema: Optional schema name to operate within.  To control
         quoting of the schema outside of the default behavior, use
         the SQLAlchemy construct
         :class:`~sqlalchemy.sql.elements.quoted_name`.

         .. versionadded:: 0.7.0 'schema' can now accept a
            :class:`~sqlalchemy.sql.elements.quoted_name` construct.

        .. versionchanged:: 0.8.0 The following positional argument names
           have been changed:

           * name -> constraint_name

        )r/r-)�invoke)r!�
operationsr+r,r/r-�oprrr
r)ssz DropConstraintOp.drop_constraintcCs"|||jj||jjd�}|�|�S)a�Issue a "drop constraint" instruction using the
        current batch migration context.

        The batch form of this call omits the ``table_name`` and ``schema``
        arguments from the call.

        .. seealso::

            :meth:`.Operations.drop_constraint`

        .. versionchanged:: 0.8.0 The following positional argument names
           have been changed:

           * name -> constraint_name

        )r/r-)�implr,r-r:)r!r;r+r/r<rrr
r*�sz&DropConstraintOp.batch_drop_constraint)NNN)NN)N)rrrrr0r%r&r(rr$r�_with_legacy_namesr)r*rrrr
r#<s
r#�create_primary_key�batch_create_primary_keyc@s\eZdZdZdZddd�Zedd��Zddd	�Zee	�
d
dg�ddd
���Zedd��ZdS)rz)Represent a create primary key operation.Z
primarykeyNcKs(||_||_||_||_||_||_dS)N)r+r,�columnsr-r.�kw)rr+r,rAr-r.rBrrr
r0�szCreatePrimaryKeyOp.__init__cCs$t�|�}||j|j|j|j|d�S)N)r-r.)rr5r6rAr-)r!r"r8rrr
r�s
z"CreatePrimaryKeyOp.from_constraintcCs4|jdk	r|jSt�|�}|j|j|j|j|jd�S)N)r-)r.r�
SchemaObjectsrr+r,rAr-)r�migration_context�
schema_objrrr
r$�s

z CreatePrimaryKeyOp.to_constraint)r6r+)ZcolsrAcCs|||||�}|�|�S)a�Issue a "create primary key" instruction using the current
        migration context.

        e.g.::

            from alembic import op
            op.create_primary_key(
                        "pk_my_table", "my_table",
                        ["id", "version"]
                    )

        This internally generates a :class:`~sqlalchemy.schema.Table` object
        containing the necessary columns, then generates a new
        :class:`~sqlalchemy.schema.PrimaryKeyConstraint`
        object which it then associates with the
        :class:`~sqlalchemy.schema.Table`.
        Any event listeners associated with this action will be fired
        off normally.   The :class:`~sqlalchemy.schema.AddConstraint`
        construct is ultimately used to generate the ALTER statement.

        :param name: Name of the primary key constraint.  The name is necessary
         so that an ALTER statement can be emitted.  For setups that
         use an automated naming scheme such as that described at
         :ref:`sqla:constraint_naming_conventions`
         ``name`` here can be ``None``, as the event listener will
         apply the name to the constraint object when it is associated
         with the table.
        :param table_name: String name of the target table.
        :param columns: a list of string column names to be applied to the
         primary key constraint.
        :param schema: Optional schema name to operate within.  To control
         quoting of the schema outside of the default behavior, use
         the SQLAlchemy construct
         :class:`~sqlalchemy.sql.elements.quoted_name`.

         .. versionadded:: 0.7.0 'schema' can now accept a
            :class:`~sqlalchemy.sql.elements.quoted_name` construct.

        .. versionchanged:: 0.8.0 The following positional argument names
           have been changed:

           * name -> constraint_name
           * cols -> columns

        )r:)r!r;r+r,rAr-r<rrr
r?�s5z%CreatePrimaryKeyOp.create_primary_keycCs"|||jj||jjd�}|�|�S)aIssue a "create primary key" instruction using the
        current batch migration context.

        The batch form of this call omits the ``table_name`` and ``schema``
        arguments from the call.

        .. seealso::

            :meth:`.Operations.create_primary_key`

        )r-)r=r,r-r:)r!r;r+rAr<rrr
r@s

z+CreatePrimaryKeyOp.batch_create_primary_key)NN)N)N)
rrrrrr0r(rr$rr>r?r@rrrr
r�s

	1r�create_unique_constraint�batch_create_unique_constraintc@sjeZdZdZdZddd�Zedd��Zddd	�Zee	�
d
ddg�dd
d���Zee	�
d
g�dd���ZdS)rz/Represent a create unique constraint operation.r3NcKs(||_||_||_||_||_||_dS)N)r+r,rAr-r.rB)rr+r,rAr-r.rBrrr
r0'sz!CreateUniqueConstraintOp.__init__cCsZt�|�}i}|jr|j|d<|jr.|j|d<||j|jdd�|jD�f|j|d�|��S)N�
deferrable�	initiallycSsg|]
}|j�qSr)r6)�.0�crrr
�
<listcomp>>sz<CreateUniqueConstraintOp.from_constraint.<locals>.<listcomp>)r-r.)rr5rHrIr6rAr-)r!r"r8rBrrr
r1s


z(CreateUniqueConstraintOp.from_constraintcCs>|jdk	r|jSt�|�}|j|j|j|jfd|ji|j��S)Nr-)	r.rrCrr+r,rAr-rB)rrDrErrr
r$Ds

z&CreateUniqueConstraintOp.to_constraint)r6r+)�sourcer,)�
local_colsrAcKs"||||fd|i|��}|�|�S)aGIssue a "create unique constraint" instruction using the
        current migration context.

        e.g.::

            from alembic import op
            op.create_unique_constraint("uq_user_name", "user", ["name"])

        This internally generates a :class:`~sqlalchemy.schema.Table` object
        containing the necessary columns, then generates a new
        :class:`~sqlalchemy.schema.UniqueConstraint`
        object which it then associates with the
        :class:`~sqlalchemy.schema.Table`.
        Any event listeners associated with this action will be fired
        off normally.   The :class:`~sqlalchemy.schema.AddConstraint`
        construct is ultimately used to generate the ALTER statement.

        :param name: Name of the unique constraint.  The name is necessary
         so that an ALTER statement can be emitted.  For setups that
         use an automated naming scheme such as that described at
         :ref:`sqla:constraint_naming_conventions`,
         ``name`` here can be ``None``, as the event listener will
         apply the name to the constraint object when it is associated
         with the table.
        :param table_name: String name of the source table.
        :param columns: a list of string column names in the
         source table.
        :param deferrable: optional bool. If set, emit DEFERRABLE or
         NOT DEFERRABLE when issuing DDL for this constraint.
        :param initially: optional string. If set, emit INITIALLY <value>
         when issuing DDL for this constraint.
        :param schema: Optional schema name to operate within.  To control
         quoting of the schema outside of the default behavior, use
         the SQLAlchemy construct
         :class:`~sqlalchemy.sql.elements.quoted_name`.

         .. versionadded:: 0.7.0 'schema' can now accept a
            :class:`~sqlalchemy.sql.elements.quoted_name` construct.

        .. versionchanged:: 0.8.0 The following positional argument names
           have been changed:

           * name -> constraint_name
           * source -> table_name
           * local_cols -> columns

        r-)r:)r!r;r+r,rAr-rBr<rrr
rFMs9
z1CreateUniqueConstraintOp.create_unique_constraintcKs*|jj|d<|||jj|f|�}|�|�S)a�Issue a "create unique constraint" instruction using the
        current batch migration context.

        The batch form of this call omits the ``source`` and ``schema``
        arguments from the call.

        .. seealso::

            :meth:`.Operations.create_unique_constraint`

        .. versionchanged:: 0.8.0 The following positional argument names
           have been changed:

           * name -> constraint_name

        r-)r=r-r,r:)r!r;r+rArBr<rrr
rG�s
z7CreateUniqueConstraintOp.batch_create_unique_constraint)NN)N)N)
rrrrrr0r(rr$rr>rFrGrrrr
rs

	7r�create_foreign_key�batch_create_foreign_keyc	@sveZdZdZdZddd�Zdd�Zedd	��Zdd
d�Z	ee
�dd
dg�ddd���Zee
�ddg�ddd���Z
dS)rz4Represent a create foreign key constraint operation.r2NcKs.||_||_||_||_||_||_||_dS)N)r+�source_table�referent_tablerN�remote_colsr.rB)rr+rQrRrNrSr.rBrrr
r0�szCreateForeignKeyOp.__init__cCsd|��fS)NZadd_fk)r$)rrrr
r&�sz CreateForeignKeyOp.to_diff_tuplec

Cs�i}|jr|j|d<|jr$|j|d<|jr4|j|d<|jrD|j|d<|jrT|j|d<t�|�\
}}}}}}}	}
}}||d<||d<||j||||fd|i|��S)	N�onupdate�ondeleterIrH�	use_alter�
source_schema�referent_schemar.)rTrUrIrHrVrZ_fk_specr6)
r!r"rBrWrQZsource_columnsZ
target_schemaZtarget_tableZtarget_columnsrTrUrHrIrrr
r�s,




z"CreateForeignKeyOp.from_constraintcCs<|jdk	r|jSt�|�}|j|j|j|j|j|jf|j	�S)N)
r.rrCrr+rQrRrNrSrB)rrDrErrr
r$�s


z CreateForeignKeyOp.to_constraint)r6r+)rMrQ)ZreferentrRc
Ks2||||||f|||	||
|
|d�|��}|�|�S)aW	Issue a "create foreign key" instruction using the
        current migration context.

        e.g.::

            from alembic import op
            op.create_foreign_key(
                        "fk_user_address", "address",
                        "user", ["user_id"], ["id"])

        This internally generates a :class:`~sqlalchemy.schema.Table` object
        containing the necessary columns, then generates a new
        :class:`~sqlalchemy.schema.ForeignKeyConstraint`
        object which it then associates with the
        :class:`~sqlalchemy.schema.Table`.
        Any event listeners associated with this action will be fired
        off normally.   The :class:`~sqlalchemy.schema.AddConstraint`
        construct is ultimately used to generate the ALTER statement.

        :param name: Name of the foreign key constraint.  The name is necessary
         so that an ALTER statement can be emitted.  For setups that
         use an automated naming scheme such as that described at
         :ref:`sqla:constraint_naming_conventions`,
         ``name`` here can be ``None``, as the event listener will
         apply the name to the constraint object when it is associated
         with the table.
        :param source_table: String name of the source table.
        :param referent_table: String name of the destination table.
        :param local_cols: a list of string column names in the
         source table.
        :param remote_cols: a list of string column names in the
         remote table.
        :param onupdate: Optional string. If set, emit ON UPDATE <value> when
         issuing DDL for this constraint. Typical values include CASCADE,
         DELETE and RESTRICT.
        :param ondelete: Optional string. If set, emit ON DELETE <value> when
         issuing DDL for this constraint. Typical values include CASCADE,
         DELETE and RESTRICT.
        :param deferrable: optional bool. If set, emit DEFERRABLE or NOT
         DEFERRABLE when issuing DDL for this constraint.
        :param source_schema: Optional schema name of the source table.
        :param referent_schema: Optional schema name of the destination table.

        .. versionchanged:: 0.8.0 The following positional argument names
           have been changed:

           * name -> constraint_name
           * source -> source_table
           * referent -> referent_table

        )rTrUrHrWrXrI�match)r:)r!r;r+rQrRrNrSrTrUrHrIrYrWrX�
dialect_kwr<rrr
rO�s@z%CreateForeignKeyOp.create_foreign_keyc
Ks:|||jj|||f|||	|jj||
|d�|��}
|�|
�S)a�Issue a "create foreign key" instruction using the
        current batch migration context.

        The batch form of this call omits the ``source`` and ``source_schema``
        arguments from the call.

        e.g.::

            with batch_alter_table("address") as batch_op:
                batch_op.create_foreign_key(
                            "fk_user_address",
                            "user", ["user_id"], ["id"])

        .. seealso::

            :meth:`.Operations.create_foreign_key`

        .. versionchanged:: 0.8.0 The following positional argument names
           have been changed:

           * name -> constraint_name
           * referent -> referent_table

        )rTrUrHrWrXrIrY)r=r,r-r:)r!r;r+rRrNrSrXrTrUrHrIrYrZr<rrr
rP6s$z+CreateForeignKeyOp.batch_create_foreign_key)N)N)NNNNNNN)NNNNNN)rrrrrr0r&r(rr$rr>rOrPrrrr
r�s*
	!

Cr�create_check_constraint�batch_create_check_constraintc@sheZdZdZdZddd�Zedd��Zddd	�Zee	�
d
dg�ddd
���Zee	�
d
g�dd���ZdS)rz.Represent a create check constraint operation.r4NcKs(||_||_||_||_||_||_dS)N)r+r,�	conditionr-r.rB)rr+r,r]r-r.rBrrr
r0psz CreateCheckConstraintOp.__init__cCs$t�|�}||j|j|j|j|d�S)N)r-r.)rr5r6�sqltextr-)r!r"r8rrr
rzs
z'CreateCheckConstraintOp.from_constraintcCs>|jdk	r|jSt�|�}|j|j|j|jfd|ji|j��S)Nr-)	r.rrCrr+r,r]r-rB)rrDrErrr
r$�s

z%CreateCheckConstraintOp.to_constraint)r6r+)rMr,cKs"||||fd|i|��}|�|�S)a2Issue a "create check constraint" instruction using the
        current migration context.

        e.g.::

            from alembic import op
            from sqlalchemy.sql import column, func

            op.create_check_constraint(
                "ck_user_name_len",
                "user",
                func.len(column('name')) > 5
            )

        CHECK constraints are usually against a SQL expression, so ad-hoc
        table metadata is usually needed.   The function will convert the given
        arguments into a :class:`sqlalchemy.schema.CheckConstraint` bound
        to an anonymous table in order to emit the CREATE statement.

        :param name: Name of the check constraint.  The name is necessary
         so that an ALTER statement can be emitted.  For setups that
         use an automated naming scheme such as that described at
         :ref:`sqla:constraint_naming_conventions`,
         ``name`` here can be ``None``, as the event listener will
         apply the name to the constraint object when it is associated
         with the table.
        :param table_name: String name of the source table.
        :param condition: SQL expression that's the condition of the
         constraint. Can be a string or SQLAlchemy expression language
         structure.
        :param deferrable: optional bool. If set, emit DEFERRABLE or
         NOT DEFERRABLE when issuing DDL for this constraint.
        :param initially: optional string. If set, emit INITIALLY <value>
         when issuing DDL for this constraint.
        :param schema: Optional schema name to operate within.  To control
         quoting of the schema outside of the default behavior, use
         the SQLAlchemy construct
         :class:`~sqlalchemy.sql.elements.quoted_name`.

         .. versionadded:: 0.7.0 'schema' can now accept a
            :class:`~sqlalchemy.sql.elements.quoted_name` construct.

        .. versionchanged:: 0.8.0 The following positional argument names
           have been changed:

           * name -> constraint_name
           * source -> table_name

        r-)r:)r!r;r+r,r]r-rBr<rrr
r[�s:z/CreateCheckConstraintOp.create_check_constraintcKs*|||jj|fd|jji|��}|�|�S)a�Issue a "create check constraint" instruction using the
        current batch migration context.

        The batch form of this call omits the ``source`` and ``schema``
        arguments from the call.

        .. seealso::

            :meth:`.Operations.create_check_constraint`

        .. versionchanged:: 0.8.0 The following positional argument names
           have been changed:

           * name -> constraint_name

        r-)r=r,r-r:)r!r;r+r]rBr<rrr
r\�sz5CreateCheckConstraintOp.batch_create_check_constraint)NN)N)N)
rrrrrr0r(rr$rr>r[r\rrrr
rhs

5r�create_index�batch_create_indexc@sfeZdZdZddd�Zdd�Zdd	�Zed
d��Zddd
�Z	ee
�dg�ddd���Zedd��Z
dS)�
CreateIndexOpz#Represent a create index operation.NFcKs.||_||_||_||_||_||_||_dS)N)�
index_namer,rAr-r3rB�_orig_index)rrbr,rAr-r3rcrBrrr
r0�szCreateIndexOp.__init__cCst�|���S)N)�DropIndexOp�
from_index�to_index)rrrr
r%�szCreateIndexOp.reversecCsd|��fS)NZ	add_index)rf)rrrr
r&�szCreateIndexOp.to_diff_tuplecCs0||j|jjt�|�f|jj|j|d�|j��S)N)r-r3rc)r6�tablerZ_get_index_expressionsr-r3�kwargs)r!�indexrrr
re�s
zCreateIndexOp.from_indexcCs>|jr|jSt�|�}|j|j|j|jf|j|jd�|j	��S)N)r-r3)
rcrrCrirbr,rAr-r3rB)rrDrErrr
rfs
zCreateIndexOp.to_index)r6rbc	Ks$||||f||d�|��}|�|�S)aC	Issue a "create index" instruction using the current
        migration context.

        e.g.::

            from alembic import op
            op.create_index('ik_test', 't1', ['foo', 'bar'])

        Functional indexes can be produced by using the
        :func:`sqlalchemy.sql.expression.text` construct::

            from alembic import op
            from sqlalchemy import text
            op.create_index('ik_test', 't1', [text('lower(foo)')])

        .. versionadded:: 0.6.7 support for making use of the
           :func:`~sqlalchemy.sql.expression.text` construct in
           conjunction with
           :meth:`.Operations.create_index` in
           order to produce functional expressions within CREATE INDEX.

        :param index_name: name of the index.
        :param table_name: name of the owning table.
        :param columns: a list consisting of string column names and/or
         :func:`~sqlalchemy.sql.expression.text` constructs.
        :param schema: Optional schema name to operate within.  To control
         quoting of the schema outside of the default behavior, use
         the SQLAlchemy construct
         :class:`~sqlalchemy.sql.elements.quoted_name`.

         .. versionadded:: 0.7.0 'schema' can now accept a
            :class:`~sqlalchemy.sql.elements.quoted_name` construct.

        :param unique: If True, create a unique index.

        :param quote:
            Force quoting of this column's name on or off, corresponding
            to ``True`` or ``False``. When left at its default
            of ``None``, the column identifier will be quoted according to
            whether the name is case sensitive (identifiers with at least one
            upper case character are treated as case sensitive), or if it's a
            reserved word. This flag is only needed to force quoting of a
            reserved word which is not known by the SQLAlchemy dialect.

        :param \**kw: Additional keyword arguments not mentioned above are
            dialect specific, and passed in the form
            ``<dialectname>_<argname>``.
            See the documentation regarding an individual dialect at
            :ref:`dialect_toplevel` for detail on documented arguments.

        .. versionchanged:: 0.8.0 The following positional argument names
           have been changed:

           * name -> index_name

        )r-r3)r:)	r!r;rbr,rAr-r3rBr<rrr
r_s>
zCreateIndexOp.create_indexcKs*|||jj|fd|jji|��}|�|�S)z�Issue a "create index" instruction using the
        current batch migration context.

        .. seealso::

            :meth:`.Operations.create_index`

        r-)r=r,r-r:)r!r;rbrArBr<rrr
r`Ssz CreateIndexOp.batch_create_index)NFN)N)NF)rrrrr0r%r&r(rerfrr>r_r`rrrr
ra�s
	

?ra�
drop_index�batch_drop_indexc@steZdZdZddd�Zdd�Zdd�Zed	d
��Zddd�Z	ee
�d
dg�ddd���Zee
�d
g�dd���Z
dS)rdz!Represent a drop index operation.NcCs||_||_||_||_dS)N)rbr,r-rc)rrbr,r-rcrrr
r0jszDropIndexOp.__init__cCsd|��fS)NZremove_index)rf)rrrr
r&qszDropIndexOp.to_diff_tuplecCs|jdkrtd��t�|j�S)Nz:operation is not reversible; original index is not present)rcr1rare)rrrr
r%ts
zDropIndexOp.reversecCs||j|jj|jj|d�S)N)r-rc)r6rgr-)r!rirrr
re{s
zDropIndexOp.from_indexcCs4|jdk	r|jSt�|�}|j|j|jdg|jd�S)N�x)r-)rcrrCrirbr,r-)rrDrErrr
rf�s


zDropIndexOp.to_index)r6rb)Z	tablenamer,cCs||||d�}|�|�S)a&Issue a "drop index" instruction using the current
        migration context.

        e.g.::

            drop_index("accounts")

        :param index_name: name of the index.
        :param table_name: name of the owning table.  Some
         backends such as Microsoft SQL Server require this.
        :param schema: Optional schema name to operate within.  To control
         quoting of the schema outside of the default behavior, use
         the SQLAlchemy construct
         :class:`~sqlalchemy.sql.elements.quoted_name`.

         .. versionadded:: 0.7.0 'schema' can now accept a
            :class:`~sqlalchemy.sql.elements.quoted_name` construct.

        .. versionchanged:: 0.8.0 The following positional argument names
           have been changed:

           * name -> index_name

        )r,r-)r:)r!r;rbr,r-r<rrr
rj�szDropIndexOp.drop_indexcKs |||jj|jjd�}|�|�S)a)Issue a "drop index" instruction using the
        current batch migration context.

        .. seealso::

            :meth:`.Operations.drop_index`

        .. versionchanged:: 0.8.0 The following positional argument names
           have been changed:

           * name -> index_name

        )r,r-)r=r,r-r:)r!r;rbrBr<rrr
rk�szDropIndexOp.batch_drop_index)NNN)N)NN)rrrrr0r&r%r(rerfrr>rjrkrrrr
rdes
	
rd�create_tablec@sXeZdZdZddd�Zdd�Zdd�Zed	d
��Zddd�Z	ee
�d
g�dd���ZdS)�
CreateTableOpz#Represent a create table operation.NcKs"||_||_||_||_||_dS)N)r,rAr-rB�_orig_table)rr,rAr-rorBrrr
r0�s
zCreateTableOp.__init__cCst�|���S)N)�DropTableOp�
from_table�to_table)rrrr
r%�szCreateTableOp.reversecCsd|��fS)NZ	add_table)rr)rrrr
r&�szCreateTableOp.to_diff_tuplecCs.||jt|j�t|j�f|j|d�|j��S)N)r-ro)r6�listrKZconstraintsr-rh)r!rgrrr
rq�szCreateTableOp.from_tablecCs<|jdk	r|jSt�|�}|j|jf|j�d|ji|j��S)Nr-)rorrCrgr,rAr-rB)rrDrErrr
rr�s


zCreateTableOp.to_table)r6r,cOs|||f|�}|�|�S)a�
Issue a "create table" instruction using the current migration
        context.

        This directive receives an argument list similar to that of the
        traditional :class:`sqlalchemy.schema.Table` construct, but without the
        metadata::

            from sqlalchemy import INTEGER, VARCHAR, NVARCHAR, Column
            from alembic import op

            op.create_table(
                'account',
                Column('id', INTEGER, primary_key=True),
                Column('name', VARCHAR(50), nullable=False),
                Column('description', NVARCHAR(200)),
                Column('timestamp', TIMESTAMP, server_default=func.now())
            )

        Note that :meth:`.create_table` accepts
        :class:`~sqlalchemy.schema.Column`
        constructs directly from the SQLAlchemy library.  In particular,
        default values to be created on the database side are
        specified using the ``server_default`` parameter, and not
        ``default`` which only specifies Python-side defaults::

            from alembic import op
            from sqlalchemy import Column, TIMESTAMP, func

            # specify "DEFAULT NOW" along with the "timestamp" column
            op.create_table('account',
                Column('id', INTEGER, primary_key=True),
                Column('timestamp', TIMESTAMP, server_default=func.now())
            )

        The function also returns a newly created
        :class:`~sqlalchemy.schema.Table` object, corresponding to the table
        specification given, which is suitable for
        immediate SQL operations, in particular
        :meth:`.Operations.bulk_insert`::

            from sqlalchemy import INTEGER, VARCHAR, NVARCHAR, Column
            from alembic import op

            account_table = op.create_table(
                'account',
                Column('id', INTEGER, primary_key=True),
                Column('name', VARCHAR(50), nullable=False),
                Column('description', NVARCHAR(200)),
                Column('timestamp', TIMESTAMP, server_default=func.now())
            )

            op.bulk_insert(
                account_table,
                [
                    {"name": "A1", "description": "account 1"},
                    {"name": "A2", "description": "account 2"},
                ]
            )

        .. versionadded:: 0.7.0

        :param table_name: Name of the table
        :param \*columns: collection of :class:`~sqlalchemy.schema.Column`
         objects within
         the table, as well as optional :class:`~sqlalchemy.schema.Constraint`
         objects
         and :class:`~.sqlalchemy.schema.Index` objects.
        :param schema: Optional schema name to operate within.  To control
         quoting of the schema outside of the default behavior, use
         the SQLAlchemy construct
         :class:`~sqlalchemy.sql.elements.quoted_name`.

         .. versionadded:: 0.7.0 'schema' can now accept a
            :class:`~sqlalchemy.sql.elements.quoted_name` construct.
        :param \**kw: Other keyword arguments are passed to the underlying
         :class:`sqlalchemy.schema.Table` object created for the command.

        :return: the :class:`~sqlalchemy.schema.Table` object corresponding
         to the parameters given.

         .. versionadded:: 0.7.0 - the :class:`~sqlalchemy.schema.Table`
            object is returned.

        .. versionchanged:: 0.8.0 The following positional argument names
           have been changed:

           * name -> table_name

        )r:)r!r;r,rArBr<rrr
rm�s\zCreateTableOp.create_table)NN)N)
rrrrr0r%r&r(rqrrrr>rmrrrr
rn�s


	rn�
drop_tablec@sZeZdZdZddd�Zdd�Zdd�Zed	d
��Zddd�Z	ee
�d
g�ddd���ZdS)rpz!Represent a drop table operation.NcCs ||_||_|pi|_||_dS)N)r,r-�table_kwro)rr,r-rurorrr
r0Qs
zDropTableOp.__init__cCsd|��fS)NZremove_table)rr)rrrr
r&XszDropTableOp.to_diff_tuplecCs|jdkrtd��t�|j�S)Nz:operation is not reversible; original table is not present)ror1rnrq)rrrr
r%[s
zDropTableOp.reversecCs||j|j|d�S)N)r-ro)r6r-)r!rgrrr
rqbszDropTableOp.from_tablecCs6|jdk	r|jSt�|�}|j|jfd|ji|j��S)Nr-)rorrCrgr,r-ru)rrDrErrr
rrfs

zDropTableOp.to_table)r6r,cKs||||d�}|�|�dS)aDIssue a "drop table" instruction using the current
        migration context.


        e.g.::

            drop_table("accounts")

        :param table_name: Name of the table
        :param schema: Optional schema name to operate within.  To control
         quoting of the schema outside of the default behavior, use
         the SQLAlchemy construct
         :class:`~sqlalchemy.sql.elements.quoted_name`.

         .. versionadded:: 0.7.0 'schema' can now accept a
            :class:`~sqlalchemy.sql.elements.quoted_name` construct.

        :param \**kw: Other keyword arguments are passed to the underlying
         :class:`sqlalchemy.schema.Table` object created for the command.

        .. versionchanged:: 0.8.0 The following positional argument names
           have been changed:

           * name -> table_name

        )r-ruN)r:)r!r;r,r-rBr<rrr
rtoszDropTableOp.drop_table)NNN)N)N)
rrrrr0r&r%r(rqrrrr>rtrrrr
rpMs

	
rpc@seZdZdZddd�ZdS)�AlterTableOpz#Represent an alter table operation.NcCs||_||_dS)N)r,r-)rr,r-rrr
r0�szAlterTableOp.__init__)N)rrrrr0rrrr
rv�srv�rename_tablecs0eZdZdZd�fdd�	Zeddd��Z�ZS)	�
RenameTableOpz#Represent a rename table operation.Ncstt|�j||d�||_dS)N)r-)�superrxr0�new_table_name)r�old_table_namerzr-)�	__class__rr
r0�szRenameTableOp.__init__cCs||||d�}|�|�S)a�Emit an ALTER TABLE to rename a table.

        :param old_table_name: old name.
        :param new_table_name: new name.
        :param schema: Optional schema name to operate within.  To control
         quoting of the schema outside of the default behavior, use
         the SQLAlchemy construct
         :class:`~sqlalchemy.sql.elements.quoted_name`.

         .. versionadded:: 0.7.0 'schema' can now accept a
            :class:`~sqlalchemy.sql.elements.quoted_name` construct.

        )r-)r:)r!r;r{rzr-r<rrr
rw�szRenameTableOp.rename_table)N)N)rrrrr0r(rw�
__classcell__rr)r|r
rx�srx�alter_column�batch_alter_columnc
sbeZdZdZd�fdd�	Zdd�Zdd	�Zd
d�Zee	�
dg�dd
d���Zeddd��Z�Z
S)�
AlterColumnOpz$Represent an alter column operation.NFcsNtt|�j||d�||_||_||_||_||_||_|	|_	|
|_
||_dS)N)r-)ryr�r0�column_name�
existing_type�existing_server_default�existing_nullable�modify_nullable�modify_server_default�modify_name�modify_typerB)rr,r�r-r�r�r�r�r�r�r�rB)r|rr
r0�szAlterColumnOp.__init__c	Cs�g}|j|j|j}}}|jdk	rJ|�d||||j|jd�|j|jf�|jdk	rz|�d||||j|jd�|j|jf�|j	dk	r�|�d||||j|jd�|j|j	f�|S)Nr�)r�r�r�)r�r�FZmodify_default)r�r�)
r-r,r�r��appendr�r�r�r�r�)rZcol_diffr-�tnameZcnamerrr
r&�s0





zAlterColumnOp.to_diff_tuplecCsL|jdk	p|jdk	p|jdk	}|r&dSx |jD]}|�d�r.dSq.WdSdS)NFTZmodify_)r�r�r�rB�
startswith)rZhc1rBrrr
�has_changes�s



zAlterColumnOp.has_changescCs�|j��}|j|d<|j|d<|j|d<|jdk	r<|j|d<|jdk	rP|j|d<|jdk	rd|j|d<tdd	�d
d�|D�D��}xD|D]<}d||kr�|d
|}|d||d
|<||d|<q�W|j	|j
|jfd|ji|��S)Nr�r�r�r�r�Fr�css|]}|r|�d�VqdS)rN)�group)rJ�mrrr
�	<genexpr>sz(AlterColumnOp.reverse.<locals>.<genexpr>cSsg|]}t�d|��qS)z^(?:existing_|modify_)(.+)$)�rerY)rJ�krrr
rLsz)AlterColumnOp.reverse.<locals>.<listcomp>z	modify_%szexisting_%sr-)
rB�copyr�r�r�r�r�r��setr|r,r�r-)rrBZall_keysr�Zswaprrr
r%s*










zAlterColumnOp.reverse)r6�new_column_namecKs.|||f|||	|
||||d�|��}
|�|
�S)aXIssue an "alter column" instruction using the
        current migration context.

        Generally, only that aspect of the column which
        is being changed, i.e. name, type, nullability,
        default, needs to be specified.  Multiple changes
        can also be specified at once and the backend should
        "do the right thing", emitting each change either
        separately or together as the backend allows.

        MySQL has special requirements here, since MySQL
        cannot ALTER a column without a full specification.
        When producing MySQL-compatible migration files,
        it is recommended that the ``existing_type``,
        ``existing_server_default``, and ``existing_nullable``
        parameters be present, if not being altered.

        Type changes which are against the SQLAlchemy
        "schema" types :class:`~sqlalchemy.types.Boolean`
        and  :class:`~sqlalchemy.types.Enum` may also
        add or drop constraints which accompany those
        types on backends that don't support them natively.
        The ``existing_server_default`` argument is
        used in this case as well to remove a previous
        constraint.

        :param table_name: string name of the target table.
        :param column_name: string name of the target column,
         as it exists before the operation begins.
        :param nullable: Optional; specify ``True`` or ``False``
         to alter the column's nullability.
        :param server_default: Optional; specify a string
         SQL expression, :func:`~sqlalchemy.sql.expression.text`,
         or :class:`~sqlalchemy.schema.DefaultClause` to indicate
         an alteration to the column's default value.
         Set to ``None`` to have the default removed.
        :param new_column_name: Optional; specify a string name here to
         indicate the new name within a column rename operation.
        :param ``type_``: Optional; a :class:`~sqlalchemy.types.TypeEngine`
         type object to specify a change to the column's type.
         For SQLAlchemy types that also indicate a constraint (i.e.
         :class:`~sqlalchemy.types.Boolean`, :class:`~sqlalchemy.types.Enum`),
         the constraint is also generated.
        :param autoincrement: set the ``AUTO_INCREMENT`` flag of the column;
         currently understood by the MySQL dialect.
        :param existing_type: Optional; a
         :class:`~sqlalchemy.types.TypeEngine`
         type object to specify the previous type.   This
         is required for all MySQL column alter operations that
         don't otherwise specify a new type, as well as for
         when nullability is being changed on a SQL Server
         column.  It is also used if the type is a so-called
         SQLlchemy "schema" type which may define a constraint (i.e.
         :class:`~sqlalchemy.types.Boolean`,
         :class:`~sqlalchemy.types.Enum`),
         so that the constraint can be dropped.
        :param existing_server_default: Optional; The existing
         default value of the column.   Required on MySQL if
         an existing default is not being changed; else MySQL
         removes the default.
        :param existing_nullable: Optional; the existing nullability
         of the column.  Required on MySQL if the existing nullability
         is not being changed; else MySQL sets this to NULL.
        :param existing_autoincrement: Optional; the existing autoincrement
         of the column.  Used for MySQL's system of altering a column
         that specifies ``AUTO_INCREMENT``.
        :param schema: Optional schema name to operate within.  To control
         quoting of the schema outside of the default behavior, use
         the SQLAlchemy construct
         :class:`~sqlalchemy.sql.elements.quoted_name`.

         .. versionadded:: 0.7.0 'schema' can now accept a
            :class:`~sqlalchemy.sql.elements.quoted_name` construct.

        )r-r�r�r�r�r�r�r�)r:)r!r;r,r��nullable�server_defaultr�r/r�r�r�r-rB�altrrr
r~!sYzAlterColumnOp.alter_columnc
Ks6||jj|f|jj|||	||||d�|
��}|�|�S)z�Issue an "alter column" instruction using the current
        batch migration context.

        .. seealso::

            :meth:`.Operations.add_column`

        )r-r�r�r�r�r�r�r�)r=r,r-r:)r!r;r�r�r�r�r/r�r�r�rBr�rrr
r�s
z AlterColumnOp.batch_alter_column)NNFNNFNN)NFNNNFNN)NFNNNFN)rrrrr0r&r�r%r(rr>r~rr}rr)r|r
r��s<'
\r��
add_column�batch_add_columncsleZdZdZd�fdd�	Zdd�Zdd�Zd	d
�Zedd��Z	ed
d��Z
eddd��Zedd��Z�Z
S)�AddColumnOpz"Represent an add column operation.Ncstt|�j||d�||_dS)N)r-)ryr�r0�column)rr,r�r-)r|rr
r0�szAddColumnOp.__init__cCst�|j|j|j�S)N)�DropColumnOp�from_column_and_tablenamer-r,r�)rrrr
r%�szAddColumnOp.reversecCsd|j|j|jfS)Nr�)r-r,r�)rrrr
r&�szAddColumnOp.to_diff_tuplecCs|jS)N)r�)rrrr
�	to_column�szAddColumnOp.to_columncCs||jj||jjd�S)N)r-)rgr6r-)r!�colrrr
�from_column�szAddColumnOp.from_columncCs||||d�S)N)r-r)r!r-r�r�rrr
r��sz%AddColumnOp.from_column_and_tablenamecCs||||d�}|�|�S)a�Issue an "add column" instruction using the current
        migration context.

        e.g.::

            from alembic import op
            from sqlalchemy import Column, String

            op.add_column('organization',
                Column('name', String())
            )

        The provided :class:`~sqlalchemy.schema.Column` object can also
        specify a :class:`~sqlalchemy.schema.ForeignKey`, referencing
        a remote table name.  Alembic will automatically generate a stub
        "referenced" table and emit a second ALTER statement in order
        to add the constraint separately::

            from alembic import op
            from sqlalchemy import Column, INTEGER, ForeignKey

            op.add_column('organization',
                Column('account_id', INTEGER, ForeignKey('accounts.id'))
            )

        Note that this statement uses the :class:`~sqlalchemy.schema.Column`
        construct as is from the SQLAlchemy library.  In particular,
        default values to be created on the database side are
        specified using the ``server_default`` parameter, and not
        ``default`` which only specifies Python-side defaults::

            from alembic import op
            from sqlalchemy import Column, TIMESTAMP, func

            # specify "DEFAULT NOW" along with the column add
            op.add_column('account',
                Column('timestamp', TIMESTAMP, server_default=func.now())
            )

        :param table_name: String name of the parent table.
        :param column: a :class:`sqlalchemy.schema.Column` object
         representing the new column.
        :param schema: Optional schema name to operate within.  To control
         quoting of the schema outside of the default behavior, use
         the SQLAlchemy construct
         :class:`~sqlalchemy.sql.elements.quoted_name`.

         .. versionadded:: 0.7.0 'schema' can now accept a
            :class:`~sqlalchemy.sql.elements.quoted_name` construct.


        )r-)r:)r!r;r,r�r-r<rrr
r��s7zAddColumnOp.add_columncCs ||jj||jjd�}|�|�S)z�Issue an "add column" instruction using the current
        batch migration context.

        .. seealso::

            :meth:`.Operations.add_column`

        )r-)r=r,r-r:)r!r;r�r<rrr
r�s
zAddColumnOp.batch_add_column)N)N)rrrrr0r%r&r�r(r�r�r�r�r}rr)r|r
r��s9r��drop_column�batch_drop_columncsbeZdZdZd�fdd�	Zdd�Zdd�Zed	d
��Zddd�Z	edd
d��Z
edd��Z�ZS)r�z"Represent a drop column operation.Ncs*tt|�j||d�||_||_||_dS)N)r-)ryr�r0r�rB�_orig_column)rr,r�r-r�rB)r|rr
r0szDropColumnOp.__init__cCsd|j|j|��fS)NZ
remove_column)r-r,r�)rrrr
r&szDropColumnOp.to_diff_tuplecCs&|jdkrtd��t�|j|j|j�S)Nz;operation is not reversible; original column is not present)r�r1r�r�r-r,)rrrr
r%#s

zDropColumnOp.reversecCs|||j||d�S)N)r-r�)r6)r!r-r�r�rrr
r�,sz&DropColumnOp.from_column_and_tablenamecCs(|jdk	r|jSt�|�}|�|jt�S)N)r�rrCr�r�r)rrDrErrr
r�0s

zDropColumnOp.to_columncKs |||fd|i|��}|�|�S)aIssue a "drop column" instruction using the current
        migration context.

        e.g.::

            drop_column('organization', 'account_id')

        :param table_name: name of table
        :param column_name: name of column
        :param schema: Optional schema name to operate within.  To control
         quoting of the schema outside of the default behavior, use
         the SQLAlchemy construct
         :class:`~sqlalchemy.sql.elements.quoted_name`.

         .. versionadded:: 0.7.0 'schema' can now accept a
            :class:`~sqlalchemy.sql.elements.quoted_name` construct.

        :param mssql_drop_check: Optional boolean.  When ``True``, on
         Microsoft SQL Server only, first
         drop the CHECK constraint on the column using a
         SQL-script-compatible
         block that selects into a @variable from sys.check_constraints,
         then exec's a separate DROP CONSTRAINT for that constraint.
        :param mssql_drop_default: Optional boolean.  When ``True``, on
         Microsoft SQL Server only, first
         drop the DEFAULT constraint on the column using a
         SQL-script-compatible
         block that selects into a @variable from sys.default_constraints,
         then exec's a separate DROP CONSTRAINT for that default.
        :param mssql_drop_foreign_key: Optional boolean.  When ``True``, on
         Microsoft SQL Server only, first
         drop a single FOREIGN KEY constraint on the column using a
         SQL-script-compatible
         block that selects into a @variable from
         sys.foreign_keys/sys.foreign_key_columns,
         then exec's a separate DROP CONSTRAINT for that default.  Only
         works if the column has exactly one FK constraint which refers to
         it, at the moment.

         .. versionadded:: 0.6.2

        r-)r:)r!r;r,r�r-rBr<rrr
r�6s.zDropColumnOp.drop_columncCs ||jj||jjd�}|�|�S)z�Issue a "drop column" instruction using the current
        batch migration context.

        .. seealso::

            :meth:`.Operations.drop_column`

        )r-)r=r,r-r:)r!r;r�r<rrr
r�gs
zDropColumnOp.batch_drop_column)NN)N)N)
rrrrr0r&r%r(r�r�r�r�r}rr)r|r
r�s	
/r��bulk_insertc@s(eZdZdZddd�Zed	dd��ZdS)
�BulkInsertOpz"Represent a bulk insert operation.TcCs||_||_||_dS)N)rg�rows�multiinsert)rrgr�r�rrr
r0{szBulkInsertOp.__init__cCs||||d�}|�|�dS)a�
Issue a "bulk insert" operation using the current
        migration context.

        This provides a means of representing an INSERT of multiple rows
        which works equally well in the context of executing on a live
        connection as well as that of generating a SQL script.   In the
        case of a SQL script, the values are rendered inline into the
        statement.

        e.g.::

            from alembic import op
            from datetime import date
            from sqlalchemy.sql import table, column
            from sqlalchemy import String, Integer, Date

            # Create an ad-hoc table to use for the insert statement.
            accounts_table = table('account',
                column('id', Integer),
                column('name', String),
                column('create_date', Date)
            )

            op.bulk_insert(accounts_table,
                [
                    {'id':1, 'name':'John Smith',
                            'create_date':date(2010, 10, 5)},
                    {'id':2, 'name':'Ed Williams',
                            'create_date':date(2007, 5, 27)},
                    {'id':3, 'name':'Wendy Jones',
                            'create_date':date(2008, 8, 15)},
                ]
            )

        When using --sql mode, some datatypes may not render inline
        automatically, such as dates and other special types.   When this
        issue is present, :meth:`.Operations.inline_literal` may be used::

            op.bulk_insert(accounts_table,
                [
                    {'id':1, 'name':'John Smith',
                            'create_date':op.inline_literal("2010-10-05")},
                    {'id':2, 'name':'Ed Williams',
                            'create_date':op.inline_literal("2007-05-27")},
                    {'id':3, 'name':'Wendy Jones',
                            'create_date':op.inline_literal("2008-08-15")},
                ],
                multiinsert=False
            )

        When using :meth:`.Operations.inline_literal` in conjunction with
        :meth:`.Operations.bulk_insert`, in order for the statement to work
        in "online" (e.g. non --sql) mode, the
        :paramref:`~.Operations.bulk_insert.multiinsert`
        flag should be set to ``False``, which will have the effect of
        individual INSERT statements being emitted to the database, each
        with a distinct VALUES clause, so that the "inline" values can
        still be rendered, rather than attempting to pass the values
        as bound parameters.

        .. versionadded:: 0.6.4 :meth:`.Operations.inline_literal` can now
           be used with :meth:`.Operations.bulk_insert`, and the
           :paramref:`~.Operations.bulk_insert.multiinsert` flag has
           been added to assist in this usage when running in "online"
           mode.

        :param table: a table object which represents the target of the INSERT.

        :param rows: a list of dictionaries indicating rows.

        :param multiinsert: when at its default of True and --sql mode is not
           enabled, the INSERT statement will be executed using
           "executemany()" style, where all elements in the list of
           dictionaries are passed as bound parameters in a single
           list.   Setting this to False results in individual INSERT
           statements being emitted per parameter set, and is needed
           in those cases where non-literal values are present in the
           parameter sets.

           .. versionadded:: 0.6.4

          )r�N)r:)r!r;rgr�r�r<rrr
r��sUzBulkInsertOp.bulk_insertN)T)T)rrrrr0r(r�rrrr
r�ws
r��executec@s(eZdZdZddd�Zeddd��ZdS)	�ExecuteSQLOpz#Represent an execute SQL operation.NcCs||_||_dS)N)r^�execution_options)rr^r�rrr
r0�szExecuteSQLOp.__init__cCs|||d�}|�|�S)a�
Execute the given SQL using the current migration context.

        In a SQL script context, the statement is emitted directly to the
        output stream.   There is *no* return result, however, as this
        function is oriented towards generating a change script
        that can run in "offline" mode.  For full interaction
        with a connected database, use the "bind" available
        from the context::

            from alembic import op
            connection = op.get_bind()

        Also note that any parameterized statement here *will not work*
        in offline mode - INSERT, UPDATE and DELETE statements which refer
        to literal values would need to render
        inline expressions.   For simple use cases, the
        :meth:`.inline_literal` function can be used for **rudimentary**
        quoting of string values.  For "bulk" inserts, consider using
        :meth:`.bulk_insert`.

        For example, to emit an UPDATE statement which is equally
        compatible with both online and offline mode::

            from sqlalchemy.sql import table, column
            from sqlalchemy import String
            from alembic import op

            account = table('account',
                column('name', String)
            )
            op.execute(
                account.update().\
                    where(account.c.name==op.inline_literal('account 1')).\
                    values({'name':op.inline_literal('account 2')})
                    )

        Note above we also used the SQLAlchemy
        :func:`sqlalchemy.sql.expression.table`
        and :func:`sqlalchemy.sql.expression.column` constructs to
        make a brief, ad-hoc table construct just for our UPDATE
        statement.  A full :class:`~sqlalchemy.schema.Table` construct
        of course works perfectly fine as well, though note it's a
        recommended practice to at least ensure the definition of a
        table is self-contained within the migration script, rather
        than imported from a module that may break compatibility with
        older migrations.

        :param sql: Any legal SQLAlchemy expression, including:

        * a string
        * a :func:`sqlalchemy.sql.expression.text` construct.
        * a :func:`sqlalchemy.sql.expression.insert` construct.
        * a :func:`sqlalchemy.sql.expression.update`,
          :func:`sqlalchemy.sql.expression.insert`,
          or :func:`sqlalchemy.sql.expression.delete`  construct.
        * Pretty much anything that's "executable" as described
          in :ref:`sqlexpression_toplevel`.

        :param execution_options: Optional dictionary of
         execution options, will be passed to
         :meth:`sqlalchemy.engine.Connection.execution_options`.
        )r�)r:)r!r;r^r�r<rrr
r��s@zExecuteSQLOp.execute)N)N)rrrrr0r(r�rrrr
r��s
r�c@s6eZdZdZddd�Zdd�Zdd�Zed	d
��ZdS)
�OpContainerz-Represent a sequence of operations operation.rcCs
||_dS)N)�ops)rr�rrr
r0'szOpContainer.__init__cCs|jS)N)r�)rrrr
�is_empty*szOpContainer.is_emptycCstt�|��S)N)rsr��
_ops_as_diffs)rrrr
�as_diffs-szOpContainer.as_diffsccsDx>|jD]4}t|d�r2x$|�|�D]
}|Vq"Wq|��VqWdS)Nr�)r��hasattrr�r&)r!Z
migrationsr<Zsub_oprrr
r�0s

zOpContainer._ops_as_diffsN)r)	rrrrr0r�r�r(r�rrrr
r�%s

r�cs*eZdZdZd�fdd�	Zdd�Z�ZS)�ModifyTableOpszCContains a sequence of operations that all apply to a single Table.Ncs tt|��|�||_||_dS)N)ryr�r0r,r-)rr,r�r-)r|rr
r0=szModifyTableOps.__init__cCs&t|jttdd�|jD���|jd�S)NcSsg|]}|���qSr)r%)rJr<rrr
rLFsz*ModifyTableOps.reverse.<locals>.<listcomp>)r�r-)r�r,rs�reversedr�r-)rrrr
r%Bs
zModifyTableOps.reverse)N)rrrrr0r%r}rr)r|r
r�:sr�cs2eZdZdZd
�fdd�	Zdd�Zdd	�Z�ZS)�
UpgradeOpsz�contains a sequence of operations that would apply to the
    'upgrade' stream of a script.

    .. seealso::

        :ref:`customizing_revision`

    r�upgradescstt|�j|d�||_dS)N)r�)ryr�r0�
upgrade_token)rr�r�)r|rr
r0VszUpgradeOps.__init__cCs&ttdd�|jD���|jdd�<|S)NcSsg|]}|���qSr)r%)rJr<rrr
rL\sz+UpgradeOps.reverse_into.<locals>.<listcomp>)rsr�r�)r�
downgrade_opsrrr
�reverse_intoZszUpgradeOps.reverse_intocCs|�tgd��S)N)r�)r��DowngradeOps)rrrr
r%`szUpgradeOps.reverse)rr�)rrrrr0r�r%r}rr)r|r
r�Lsr�cs*eZdZdZd�fdd�	Zdd�Z�ZS)	r�z�contains a sequence of operations that would apply to the
    'downgrade' stream of a script.

    .. seealso::

        :ref:`customizing_revision`

    r�
downgradescstt|�j|d�||_dS)N)r�)ryr�r0�downgrade_token)rr�r�)r|rr
r0nszDowngradeOps.__init__cCstttdd�|jD���d�S)NcSsg|]}|���qSr)r%)rJr<rrr
rLusz(DowngradeOps.reverse.<locals>.<listcomp>)r�)r�rsr�r�)rrrr
r%rszDowngradeOps.reverse)rr�)rrrrr0r%r}rr)r|r
r�dsr�c@sveZdZdZde�dddddfdd�Zedd��Zejdd��Zedd	��Z	e	jd
d	��Z	edd��Z
ed
d��ZdS)�MigrationScripta�represents a migration script.

    E.g. when autogenerate encounters this object, this corresponds to the
    production of an actual script file.

    A normal :class:`.MigrationScript` object would contain a single
    :class:`.UpgradeOps` and a single :class:`.DowngradeOps` directive.
    These are accessible via the ``.upgrade_ops`` and ``.downgrade_ops``
    attributes.

    In the case of an autogenerate operation that runs multiple times,
    such as the multiple database example in the "multidb" template,
    the ``.upgrade_ops`` and ``.downgrade_ops`` attributes are disabled,
    and instead these objects should be accessed via the ``.upgrade_ops_list``
    and ``.downgrade_ops_list`` list-based attributes.  These latter
    attributes are always available at the very least as single-element lists.

    .. versionchanged:: 0.8.1 the ``.upgrade_ops`` and ``.downgrade_ops``
       attributes should be accessed via the ``.upgrade_ops_list``
       and ``.downgrade_ops_list`` attributes if multiple autogenerate
       passes proceed on the same :class:`.MigrationScript` object.

    .. seealso::

        :ref:`customizing_revision`

    NcCs@||_||_||_||_||_||_|	|_|
|_||_||_	dS)N)
�rev_id�message�imports�head�splice�branch_label�version_path�
depends_on�upgrade_opsr�)rr�r�r�r�r�r�r�r�r�r�rrr
r0�szMigrationScript.__init__cCs0t|j�dkrtd��n|js"dS|jdSdS)zzAn instance of :class:`.UpgradeOps`.

        .. seealso::

            :attr:`.MigrationScript.upgrade_ops_list`
        rzrThis MigrationScript instance has a multiple-entry list for UpgradeOps; please use the upgrade_ops_list attribute.Nr)�len�_upgrade_opsr1)rrrr
r��szMigrationScript.upgrade_opscCs.t�|�|_x|jD]}t|t�st�qWdS)N)r�to_listr��
isinstancer��AssertionError)rr��elemrrr
r��scCs0t|j�dkrtd��n|js"dS|jdSdS)z~An instance of :class:`.DowngradeOps`.

        .. seealso::

            :attr:`.MigrationScript.downgrade_ops_list`
        rzvThis MigrationScript instance has a multiple-entry list for DowngradeOps; please use the downgrade_ops_list attribute.Nr)r��_downgrade_opsr1)rrrr
r��szMigrationScript.downgrade_opscCs.t�|�|_x|jD]}t|t�st�qWdS)N)rr�r�r�r�r�)rr�r�rrr
r��scCs|jS)aA list of :class:`.UpgradeOps` instances.

        This is used in place of the :attr:`.MigrationScript.upgrade_ops`
        attribute when dealing with a revision operation that does
        multiple autogenerate passes.

        .. versionadded:: 0.8.1

        )r�)rrrr
�upgrade_ops_list�sz MigrationScript.upgrade_ops_listcCs|jS)aA list of :class:`.DowngradeOps` instances.

        This is used in place of the :attr:`.MigrationScript.downgrade_ops`
        attribute when dealing with a revision operation that does
        multiple autogenerate passes.

        .. versionadded:: 0.8.1

        )r�)rrrr
�downgrade_ops_list�sz"MigrationScript.downgrade_ops_list)rrrrr�r0r'r��setterr�r�r�rrrr
r�zs
r�)#�rrrZsqlalchemy.typesr�baserr	r��objectr
rZregister_operationr#rrrrrardrnrprvrxr�r�r�r�r�r�r�r�r�r�rrrr
�<module>sz
n
p

>
z
~
aB
w
d
caK

Zerion Mini Shell 1.0