|L ix  ddlmZddlmZddlZddlZddlZddlmZddlm Z ddlm Z ddlm Z ddlm Z dd lm Z dd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z erddlm!Z!ddl"m#Z#ddl$m%Z%ddl$m&Z&dd l$m'Z'dd!l$m(Z(dd"l)m*Z*dd#l)m+Z+dd$l)m,Z,dd%l)m-Z-dd&l)m.Z.dd'l)m/Z/dd(l)m0Z0dd)l)m1Z1dd*l)m2Z2dd+l)m3Z3dd,l)m4Z4dd-l)m5Z5dd.l6m7Z7dd/l8m9Z9dd0l:m;Z;dd1lm?Z?ed3e4Z@ed5d64ZAGd7d8ZBGd9d6eBZCejd:ejd:d;Gd<d=eBZEejd>ejd>d?eCjd@GdAdBeCZGejdCejdCdDeCjdEGdFdGeCZHejdHejdHdIeCjdJGdKdLeCZIejdMejdMdNeCjdOeCjdPeCjdQGdRdSeCZJejdTejdTdUGdVdWeBZKejdXejdXdYGdZd[eBZLejd\Gd]d^eBZMejd_Gd`daeBZNGdbdceBZOejddGdedfeOZPejdgejdgdhGdidjeOZQejdkejdkdlGdmdneOZRejdoejdodpGdqdreOZSejdsejdsdtGdudveOZTejdwejdwdxGdydzeOZUejd{Gd|d}eBZVejd~ejd~dGddeBZWGddeBZXGddeXZYGddeXZZGddeXZ[GddeBZ\y)) annotations)abstractmethodN)Any)Callable)cast)Dict) FrozenSet)Iterator)List)MutableMapping)Optional)Sequence)Set)Tuple)Type) TYPE_CHECKING)TypeVar)Union)NULLTYPE) schemaobj)BatchOperations) Operations)util) sqla_compat)Literal) Executable) ColumnElement)conv) quoted_name) TextClause)CheckConstraint)Column)Computed) Constraint)ForeignKeyConstraint)Identity)Index)MetaData)PrimaryKeyConstraint) SchemaItem)Table)UniqueConstraint) TableClause) TypeEngine)Rewriter)MigrationContext) _RevIdType_T)bound_ACAddConstraintOpc`eZdZUdZej ddZeZde d<d dZ d dZ y) MigrateOperationzbase class for migration command and organization objects. This system is part of the operation extensibility API. .. seealso:: :ref:`operation_objects` :ref:`operation_plugins` :ref:`customizing_revision` ciS)zA dictionary that may be used to store arbitrary information along with this :class:`.MigrateOperation` object. selfs \/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/alembic/operations/ops.pyinfozMigrateOperation.infoNs  zFrozenSet[Rewriter] _mutationsctNNotImplementedErrorr<s r>reversezMigrateOperation.reverseX!!r@ctrCrDr<s r> to_diff_tuplezMigrateOperation.to_diff_tuple[rGr@N)returnzDict[Any, Any])rJr9rJzTuple[Any, ...]) __name__ __module__ __qualname____doc__rmemoized_propertyr? frozensetrA__annotations__rFrIr;r@r>r9r9?s:  '0kJ#1""r@r9ceZdZdZej Zed dZe d dZ e d dZ e d d dZ ddZddZy)r7z&Represent an add constraint operation.ctrCrDr<s r>constraint_typezAddConstraintOp.constraint_typeds !##r@cdfd }|S)Nc^jj|j|SrC)add_constraint_ops dispatch_forfrom_constraint)klassclstype_s r>goz3AddConstraintOp.register_add_constraint..gols) 6C " " / / 6u7L7L MLr@)r[ Type[_AC]rJr_r;)r\r]r^s`` r>register_add_constraintz'AddConstraintOp.register_add_constrainths  r@cX|jj|j|SrC)rXdispatch__visit_name__)r\ constraints r>rZzAddConstraintOp.from_constraintrs+Is%%..z/H/HI   r@NcyrCr;)r=migration_contexts r> to_constraintzAddConstraintOp.to_constraintxs r@cHtj|jSrC)DropConstraintOprZrgr<s r>rFzAddConstraintOp.reverse~s//0B0B0DEEr@c&d|jfS)Nadd_constraintrgr<s r>rIzAddConstraintOp.to_diff_tuples $"4"4"677r@)rJstr)r]rmrJz Callable[[Type[_AC]], Type[_AC]])rdr&rJr7rC)rfOptional[MigrationContext]rJr&)rJri)rJzTuple[str, Constraint])rLrMrNrOr DispatcherrXpropertyrU classmethodr`rZrrgrFrIr;r@r>r7r7_s0(* $$ )  >B !;   F8r@drop_constraintbatch_drop_constraintceZdZdZ d dddd d dZddZ ddZeddZddZ e d ddd  dd Z e d dd Z y)riz&Represent a drop constraint operation.Nschema if_exists_reversecX||_||_||_||_||_||_yrC)constraint_name table_namerUrvrwrx)r=rzr{r]rvrwrxs r>__init__zDropConstraintOp.__init__s0 /$$ "  r@cHtj|jSrC)r7rZrgr<s r>rFzDropConstraintOp.reverses..t/A/A/CDDr@ch|jdk(rd|jfSd|jfS)N foreignkey remove_fkremove_constraint)rUrgr<s r>rIzDropConstraintOp.to_diff_tuples:   < /!3!3!56 6'););)=> >r@c ddddddd}tj|}|tj|j|j|j|j |j tj|S)Nuniquerprimarycheck)unique_constraintforeign_key_constraintprimary_key_constraintcheck_constraintcolumn_check_constraint table_or_column_check_constraint)rvr]rx) r_table_for_constraintconstraint_name_or_nonenamervgetrcr7rZ)r\rdtypesconstraint_tables r>rZz DropConstraintOp.from_constraints"*&2&/ ''.07  '<rgzDropConstraintOp.to_constraintsn == $446J"22JO*@@L $(OO  !&*kk  # 5 r@rvrwc>||||||}|j|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`. :param if_exists: If True, adds IF EXISTS operator when dropping the constraint .. versionadded:: 1.16.0 )r]rvrwinvoke)r\ operationsrzr{r]rvrwops r>rrz DropConstraintOp.drop_constraints08      $$r@c|||jj||jj}|j|S)aIssue 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` )r]rvimplr{rvr)r\rrzr]rs r>rsz&DropConstraintOp.batch_drop_constraintsA$  OO & &??))     $$r@rC)rz,Optional[sqla_compat._ConstraintNameDefined]r{rmr] Optional[str]rvrrwOptional[bool]rxzOptional[AddConstraintOp]rJNone)rJr7)rJzTuple[str, SchemaItem])rdr&rJri)rJr&)rrrzrmr{rmr]rrvrrwrrJr)rrrzrmr]rrJr) rLrMrNrOr|rFrIrqrZrgrrrsr;r@r>riris;1 $ ! !%$(.2!E!! !  !"!,! !"E? ?  &  $ "%!%$("%"%"% "%  "%"%""% "%"%H $ %#%% %  %%r@ricreate_primary_keybatch_create_primary_keyrceZdZdZdZdd d dZed dZ d d dZedd ddZ e dd Z y)CreatePrimaryKeyOpz)Represent a create primary key operation. primarykeyNrvc J||_||_||_||_||_yrCrzr{columnsrvkwr=rzr{rrvrs r>r|zCreatePrimaryKeyOp.__init__( /$  r@ctj|}td|}|tj|j|j|j j fd|ji|jS)Nr+rv) rrrrrrkeysrvdialect_kwargs)r\rdr pk_constraints r>rZz"CreatePrimaryKeyOp.from_constraint"s|&<rgz CreatePrimaryKeyOp.to_constraint.s],,->? 0z00  OO LL ;;  gg   r@c<|||||}|j|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 constraint_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`. rr)r\rrzr{rrvrs r>rz%CreatePrimaryKeyOp.create_primary_key;s&X*gf E  $$r@c|||jj||jj}|j|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` rr)r\rrzrrs r>rz+CreatePrimaryKeyOp.batch_create_primary_keyjsA$  OO & & ??))     $$r@ rzrr{rmr Sequence[str]rvrrrrJr)rdr&rJrrC)rfrnrJr+) rrrzrr{rmr List[str]rvrrJr)rrrzrrrrJr) rLrMrNrOrUr|rqrZrgrrr;r@r>rr s  4"O!% E            ?C  !;    !%,%,%',% ,%  ,%,% ,%,%\%#%'% %  %%r@rcreate_unique_constraintbatch_create_unique_constraintrceZdZdZdZdd d dZe d dZ d d dZedd ddZ e dd Z y)CreateUniqueConstraintOpz/Represent a create unique constraint operation.rNrc J||_||_||_||_||_yrCrrs r>r|z!CreateUniqueConstraintOp.__init__rr@ctj|}td|}i}|jr|j|d<|jr|j|d<|j |j |tj|j|j|jDcgc]}|jc}fd|ji|Scc}w)Nr. deferrable initiallyrv) rrrrrupdaterrrrrv)r\rdr uq_constraintrcs r>rZz(CreateUniqueConstraintOp.from_constraints'<rgz&CreateUniqueConstraintOp.to_constraints],,->? +z++  OO LL ;;  gg   r@c >||||fd|i|}|j|S)aIssue 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 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`. rvr)r\rrzr{rrvrrs r>rz1CreateUniqueConstraintOp.create_unique_constraints.b*g Kf K K  $$r@c |jj|d<|||jj|fi|}|j|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` rv)rrvr{r)r\rrzrrrs r>rz7CreateUniqueConstraintOp.batch_create_unique_constraintsE&"--8 *//"<"rrs1 :O!% E         # !  ,?C  !;    !%1%1%'1% 1%  1%1%1% 1%1%f%#%% %  % %%r@rcreate_foreign_keybatch_create_foreign_keyrc eZdZdZdZ d dZd dZeddZ d ddZ edddddddd dd Z eddddddd  dd Z y)CreateForeignKeyOpz4Represent a create foreign key constraint operation.rc X||_||_||_||_||_||_yrC)rz source_tablereferent_table local_cols remote_colsr)r=rzrrrrrs r>r|zCreateForeignKeyOp.__init__s2 /(,$&r@c&d|jfS)Nadd_fkrlr<s r>rIz CreateForeignKeyOp.to_diff_tuple&s$,,.//r@c @td|}i}|jr|j|d<|jr|j|d<|jr|j|d<|jr|j|d<|j r|j |d<|j r|j |d<tj|\ }}}}}} } } } } ||d<||d <|j|j|tj|j|||| fi|S) Nr'onupdateondeleterr use_altermatch source_schemareferent_schema) rrrrrrrr_fk_specrrrr)r\rd fk_constraintrrrsource_columns target_schema target_tabletarget_columnsrrrrs r>rZz"CreateForeignKeyOp.from_constraint)s83Z@   ! !*33BzN  ! !*33BzN  " "+55B{O  # #,77B|   " "+55B{O   '--BwK   /          ,? -  -../  / / 0B0B C         r@Nctj|}|j|j|j|j |j |jfi|jSrC) rrrrzrrrrrrs r>rgz CreateForeignKeyOp.to_constraintSsc,,->? 0z00        OO     gg   r@)rrrrrrrc N||||||f||| | | | | d|}|j|S)aIssue 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 constraint_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 when issuing DDL for this constraint. Typical values include CASCADE, DELETE and RESTRICT. :param ondelete: Optional string. If set, emit ON DELETE 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. rrrrrrrr)r\rrzrrrrrrrrrrr dialect_kwrs r>rz%CreateForeignKeyOp.create_foreign_key`sWJ       !'+    $$r@)rrrrrrc |||jj|||f||| |jj|| | d| } |j| 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` rr)r\rrzrrrrrrrrrrrs r>rz+CreateForeignKeyOp.batch_create_foreign_keyskL  OO & &     !$//00+    $$r@)rzrrrmrrmrrrrrrrJr)rJz Tuple[str, ForeignKeyConstraint])rdr&rJrrC)rfrnrJr')rrrzrrrmrrmrrrrrrrrrrrrrrrrrrrrrJr)rrrzrrrmrrrrrrrrrrrrrrrrrrrJr) rLrMrNrOrUr|rIrqrZrgrrr;r@r>rr s ?"OE       0' ' T?C  !;    #'"&%)#'#'+)-S%S%'S% S%  S%  S%S% S% S%#S%!S%S%%S%'S% !S%" #S%S%j*."&"&%)#'#4%#4%'4% 4%  4%  4%'4% 4% 4%#4%!4%4%4% 4%4%r@rcreate_check_constraintbatch_create_check_constraintrrrceZdZdZdZdd d dZe d dZ d d dZedd ddZ e dd Z y)CreateCheckConstraintOpz.Represent a create check constraint operation.rNrc J||_||_||_||_||_yrC)rzr{ conditionrvr)r=rzr{rrvrs r>r|z CreateCheckConstraintOp.__init__s( /$" r@ctj|}td|}|tj|j|jtd|j fd|j i|jS)Nr#zColumnElement[Any]rv)rrrrrsqltextrvr)r\rdr ck_constraints r>rZz'CreateCheckConstraintOp.from_constraint s}'<rgz%CreateCheckConstraintOp.to_constraints],,->? *z**  OO NN ;;  gg   r@c >||||fd|i|}|j|S)aIssue 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 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`. rvr)r\rrzr{rrvrrs r>rz/CreateCheckConstraintOp.create_check_constraint$s.f*i M M" M  $$r@c |||jj|fd|jji|}|j|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` rvr)r\rrzrrrs r>rz5CreateCheckConstraintOp.batch_create_check_constraintZsR&  OO & &  ??))      $$r@) rzrr{rmrz*Union[str, TextClause, ColumnElement[Any]]rvrrrrJr)rdr&rJrrC)rfrnrJr#)rrrzrr{rmr+Union[str, ColumnElement[bool], TextClause]rvrrrrJr) rrrzrmrrrrrJr) rLrMrNrOrUr|rqrZrgrrr;r@r>rrs19O!% E  >        #      ?C  !;    !%3%3%'3% 3% ? 3%3%3% 3%3%j%#%%? %  %  %%r@r create_indexbatch_create_indexceZdZdZdddd d dZd dZddZeddZ d dd Z edddd dd Z e dd Z y) CreateIndexOpz#Represent a create index operation.NFrvr if_not_existsc f||_||_||_||_||_||_||_yrC) index_namer{rrvrrr)r=rr{rrvrrrs r>r|zCreateIndexOp.__init__|s6%$   *r@cHtj|jSrC) DropIndexOp from_indexto_indexr<s r>rFzCreateIndexOp.reverses%%dmmo66r@c&d|jfS)N add_indexrr<s r>rIzCreateIndexOp.to_diff_tupleT]]_--r@c|jJ||j|jj|jf|jj|jd|j SN)rvr)tabler expressionsrvrkwargsr\indexs r>rzCreateIndexOp.from_indexse{{&&& JJ KK      ;;%%<<  ll   r@ctj|}|j|j|j|j f|j |jd|j}|Sr) rrr rr{rrvrr)r=rfridxs r>rzCreateIndexOp.to_indexsf,,->? j OO OO LL ;;;;  gg   r@c B||||f|||d|} |j| S)aIssue 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)")]) :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`. :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 if_not_exists: If True, adds IF NOT EXISTS operator when creating the new index. .. versionadded:: 1.12.0 :param \**kw: Additional keyword arguments not mentioned above are dialect specific, and passed in the form ``_``. See the documentation regarding an individual dialect at :ref:`dialect_toplevel` for detail on documented arguments. rr) r\rrr{rrvrrrrs r>rzCreateIndexOp.create_indexsEx    '     $$r@c |||jj|fd|jji|}|j|S)zIssue a "create index" instruction using the current batch migration context. .. seealso:: :meth:`.Operations.create_index` rvr)r\rrrrrs r>rz CreateIndexOp.batch_create_indexsR"  OO & &  ??))      $$r@)rrr{rmr4Sequence[Union[str, TextClause, ColumnElement[Any]]]rvrrboolrrrrrJr)rJrrJzTuple[str, Index])r r)rJrrCrfrnrJr))rrrrr{rmrrrvrrrrrrrrJr) rrrrmrrrrrJr) rLrMrNrOr|rFrIrqrrrrr;r@r>rrwsg.!%(,!F   & &7.    ?C !;   !%(,D%D%"D% D% F D%D%D%&D%D% D%D%L%#%% %  %  %%r@r drop_indexbatch_drop_indexceZdZdZ d dddd d dZddZddZeddZ d ddZ e d ddd  dd Z e dd Z y)rz!Represent a drop index operation.Nruc X||_||_||_||_||_||_yrC)rr{rvrwrxr)r=rr{rvrwrxrs r>r|zDropIndexOp.__init__s.%$ "  r@c&d|jfS)N remove_indexrr<s r>rIzDropIndexOp.to_diff_tuple( 00r@cHtj|jSrC)rrrr<s r>rFzDropIndexOp.reverse+'' 88r@c|jJ||jf|jj|jjtj ||j d|j S)N)r{rvrxr)rrrvrrrrrs r>rzDropIndexOp.from_index.sh{{&&& JJ {{'';;%%"--e4<<  ll   r@ctj|}|j|j|j|j r|j j ndgfd|ji|jS)Nxrv) rrr rr{rxrrvrrs r>rzDropIndexOp.to_index:sm,,->?  z OO OO%)]]DMM ! ! ;;  gg   r@rc >||f|||d|}|j|S)aIssue 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`. :param if_exists: If True, adds IF EXISTS operator when dropping the index. .. versionadded:: 1.12.0 :param \**kw: Additional keyword arguments not mentioned above are dialect specific, and passed in the form ``_``. See the documentation regarding an individual dialect at :ref:`dialect_toplevel` for detail on documented arguments. )r{rvrwr)r\rrr{rvrwrrs r>rzDropIndexOp.drop_indexIs=L  !      $$r@c ||f|jj|jjd|}|j|S)zIssue a "drop index" instruction using the current batch migration context. .. seealso:: :meth:`.Operations.drop_index` r{rvr)r\rrrrs r>rzDropIndexOp.batch_drop_indexxsM  !11??))      $$r@rC)rzUnion[quoted_name, str, conv]r{rrvrrwrrxzOptional[CreateIndexOp]rrrJrr)rJr)r r)rJrr)rrrrmr{rrvrrwrrrrJr)rrrrmrrrJr) rLrMrNrOr|rIrFrqrrrrr;r@r>rrs=, %) !%$(,01"   " * "19    ?C  !;     %) ,% !%$(,%,%,%" ,%  ,%",%,% ,%,%\%(%69%AD% %%r@r create_tableceZdZdZddddd d dZddZddZedd dd Z d dd Z edd  dd Z y) CreateTableOpz#Represent a create table operation.NF)rvr_namespace_metadata_constraints_includedc ||_||_||_||_|j di|_|j dd|_|j dd|_||_||_ ||_ y)Nr?commentprefixes) r{rrvrpopr?r'r(rr$r%)r=r{rrvrr$r%rs r>r|zCreateTableOp.__init__sn%  *FF62& vvi. z40 #6 %:"r@c`tj|j|jS)Nr$) DropTableOp from_tableto_tabler$r<s r>rFzCreateTableOp.reverses+%% MMO1I1I&  r@c&d|jfS)N add_tabler.r<s r>rIzCreateTableOp.to_diff_tuplerr@r+c .| |j}||jt|jt|jzf|j |d|j t|jt|jd|jS)NT)rvr$r%r'r?r() metadatarlistr constraintsrvr'dictr? _prefixesrr\rr$s r>r-zCreateTableOp.from_tables  &"'..  JJ MD!2!23 3 << 3#'MMejj!%//* ll  r@c jtj|}|j|jg|j|j |j rt|j ng|j|jr|jjni|jd|jS)N)rvr(r'r?r%) rrrr{rrvr(r4r'r?copyr%rrs r>r.zCreateTableOp.to_tables,,->? z OO  \\  ;;,0MMT$--(rLL%)YY!B"&"<"<  gg  r@)rc<|||fd|i|}|j|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"}, ], ) :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`. :param if_not_exists: If True, adds IF NOT EXISTS operator when creating the new table. .. versionadded:: 1.13.3 :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. rr)r\rr{rrrrs r>r!zCreateTableOp.create_tables,tW HM HR H  $$r@)r{rmrzSequence[SchemaItem]rvrrrr$Optional[MetaData]r%rrrrJr)rJr,rJzTuple[str, Table])rr-r$r<rJr#rCrfrnrJr-) rrr{rmrr,rrrrrJr-) rLrMrNrOr|rFrIrqr-r.r!r;r@r>r#r#s-!%(,26&+;;&;  ; & ;0; $;; ;, .HL  3E   2?C !;   )- Z%Z%Z% Z% & Z%  Z% Z%Z%r@r# drop_tableceZdZdZddddd d dZd dZddZedd ddZ d dd Z eddd  dd Z y)r,z!Represent a drop table operation.N)rvrwtable_kwrxc||_||_||_|xsi|_|jj dd|_|jj dd|_|jj dd|_||_y)Nr'r?r() r{rvrwrAr)r'r?r(rx)r=r{rvrwrArxs r>r|zDropTableOp.__init__;ss% " B }}((D9 MM%%fd3  ))*d;   r@c&d|jfS)N remove_tabler1r<s r>rIzDropTableOp.to_diff_tupleMrr@cHtj|jSrC)r#r-r.r<s r>rFzDropTableOp.reversePrr@r+c ||j|j|jt|jt |j d|jtj||S)N)r'r?r(r+)rvrArx) rrvr'r6r?r4r7rr#r-r8s r>r-zDropTableOp.from_tableSsl JJ<< ==UZZ( 1,,  #--+>.  r@c |jr|jj}ng}tj|}|j|j g||j |jr|jjni|jrt|jng|j|jr|jjndd|j}|S)NF)r'r?r(rvr%)rxrrrrr{r'r?r:r(r4rvr%rA)r=rfcols_and_constraintsrts r>r.zDropTableOp.to_tablees ==#'==#8#8 #% ,,->? J   OO ! LL%)YY!B,0MMT$--(r;;7;}} 33% mm r@rc >|||||}|j|y)aIssue 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`. :param if_exists: If True, adds IF EXISTS operator when dropping the table. .. versionadded:: 1.13.3 :param \**kw: Other keyword arguments are passed to the underlying :class:`sqlalchemy.schema.Table` object created for the command. )rvrwrANr)r\rr{rvrwrrs r>r?zDropTableOp.drop_table|s">Fi" M"r@) r{rmrvrrwrrAz"Optional[MutableMapping[Any, Any]]rxzOptional[CreateTableOp]rJrr=)rJr#)rr-r$r<rJr,rCr>) rrr{rmrvrrwrrrrJr) rLrMrNrOr|rIrFrqr-r.r?r;r@r>r,r,7s+ !%$(7;,0!! ! " ! 5 !*! !$19HL  3E   $?C!; . !%$(    "  r@r,c(eZdZdZdd ddZy) AlterTableOpz#Represent an alter table operation.Nrc ||_||_yrCr )r=r{rvs r>r|zAlterTableOp.__init__s % r@)r{rmrvrrJr)rLrMrNrOr|r;r@r>rLrLs+- !%    r@rL rename_tablecbeZdZdZdd dfdZedd ddZxZS) RenameTableOpz#Represent a rename table operation.Nrc6t|||||_yNr)superr|new_table_name)r=old_table_namerTrv __class__s r>r|zRenameTableOp.__init__s 7,r@c:||||}|j|S)alEmit 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`. rr)r\rrUrTrvrs r>rNzRenameTableOp.rename_tables#& ?  $$r@)rUrmrTrmrvrrJr) rrrUrmrTrmrvrrJr)rLrMrNrOr|rqrN __classcell__rVs@r>rPrPs-!% ---  -  -!% %%% %  % %%r@rPcreate_table_commentbatch_create_table_commentceZdZdZddd d dZeddd d dZedd ddZdd Z d dd Z dd Z y)CreateTableCommentOpz)Represent a COMMENT ON `table` operation.Nrvexisting_commentc<||_||_||_||_yrC)r{r'r_rv)r=r{r'rvr_s r>r|zCreateTableCommentOp.__init__s!% 0 r@r_rvc<|||||}|j|S)aQEmit a COMMENT ON operation to set the comment for a table. :param table_name: string name of the target table. :param comment: string value of the comment being registered against the specified table. :param existing_comment: String value of a comment already registered on the specified table, used within autogenerate so that the operation is reversible, but not required for direct use. .. seealso:: :meth:`.Operations.drop_table_comment` :paramref:`.Operations.alter_column.comment` rar)r\rr{r'r_rvrs r>rZz)CreateTableCommentOp.create_table_comments-8  -     $$r@r_c||jj|||jj}|j|S)aEmit a COMMENT ON operation to set the comment for a table using the current batch migration context. :param comment: string value of the comment being registered against the specified table. :param existing_comment: String value of a comment already registered on the specified table, used within autogenerate so that the operation is reversible, but not required for direct use. rar)r\rr'r_rs r>r[z/CreateTableCommentOp.batch_create_table_comment sA( OO & & -??))     $$r@c|j,t|j|j|jSt |j|j|j|jS)2Reverses the COMMENT ON operation against a table.ra)r_DropTableCommentOpr{r'rvr]r<s r>rFzCreateTableCommentOp.reverse%s]  (%!%{{  (%%!%{{  r@ctj|}|j|j|j|j S)N)rvr')rrrr{rvr'rs r>r.zCreateTableCommentOp.to_table5s@,,->?  OODKK   r@c<d|j|jfS)Nadd_table_comment)r.r_r<s r>rIz"CreateTableCommentOp.to_diff_tuple>s#T]]_d6K6KLLr@) r{rmr'rrvrr_rrJr) rrr{rmr'rr_rrvrrJr)rrr'rr_rrJr)rJz/Union[CreateTableCommentOp, DropTableCommentOp]rCr>rK) rLrMrNrOr|rqrZr[rFr.rIr;r@r>r]r]s 4!%*.      (   +/ $!%!%!% !% ( !%!% !%!%F +/ %#%% ( %  %%6"?C !;  Mr@r]drop_table_commentbatch_drop_table_commentceZdZdZddd d dZeddd d dZedd ddZdd Z d dd Z dd Z y)rgz:Represent an operation to remove the comment from a table.Nr^c.||_||_||_yrC)r{r_rv)r=r{rvr_s r>r|zDropTableCommentOp.__init__Is% 0 r@rac:||||}|j|S)aIssue a "drop table comment" operation to remove an existing comment set on a table. :param table_name: string name of the target table. :param existing_comment: An optional string value of a comment already registered on the specified table. .. seealso:: :meth:`.Operations.create_table_comment` :paramref:`.Operations.alter_column.comment` rar)r\rr{r_rvrs r>rkz%DropTableCommentOp.drop_table_commentTs$0.>v N  $$r@rcc||jj||jj}|j|S)aIssue a "drop table comment" operation to remove an existing comment set on a table using the current batch operations context. :param existing_comment: An optional string value of a comment already registered on the specified table. rar)r\rr_rs r>rlz+DropTableCommentOp.batch_drop_table_commentos>  OO & &-??))    $$r@cZt|j|j|jS)rfr)r]r{r_rvr<s r>rFzDropTableCommentOp.reverses$# OOT224;;  r@cztj|}|j|j|jSrR)rrrr{rvrs r>r.zDropTableCommentOp.to_tables3,,->?  DDr@c&d|jfS)Nremove_table_commentr1r<s r>rIz DropTableCommentOp.to_diff_tuples& 88r@)r{rmrvrr_rrJr) rrr{rmr_rrvrrJr)rrr_rrJr)rJr]rCr>rK) rLrMrNrOr|rqrkrlrFr.rIr;r@r>rgrgBs E !%*.    (    +/ $ %%% ( %  % %%4 +/ %#%( %  %%, ?CE!;E E9r@rg alter_columnbatch_alter_columnc TeZdZdZddddddddddd d fdZddZddZddZeddddddddddd dd Z edddddddddddd dd Z xZ S) AlterColumnOpz$Represent an alter column operation.NF) rv existing_typeexisting_server_defaultexisting_nullabler_modify_nullablemodify_commentmodify_server_default modify_name modify_typec  t|||||_||_||_||_||_||_| |_| |_ | |_ | |_ | |_ yrR) rSr| column_nameryrzr{r_r|r}r~rrr)r=r{rrvryrzr{r_r|r}r~rrrrVs r>r|zAlterColumnOp.__init__sn" F3&*'>$!2 0.,%:"&&r@c *g}|j|j|j}}}|jN|j d||||j |j |jd|j|jf|jN|j d||||j|j |jd|j |jf|jdurN|j d||||j |j|jd|j |jf|jdurN|j d||||j |j|j d |j|jf|S) Nr)r{rzr_r|)ryrzr_Fmodify_default)r{ryr_r})r{ryrz) rvr{rrappendr{rzr_ryr|r~r})r=col_diffrvtnamecnames r>rIzAlterColumnOp.to_diff_tuples#{{DOOT=M=Mu    ' OO!-1-C-C 88,0,A,A &&$$ $    + OO%)-);); 88,0,A,A **(( $  % %U 2 OO$-1-C-C)-););,0,A,A 00..     e + OO$-1-C-C)-);); 88 ))'' $r@c|jduxs.|jduxs|jduxs|jdu}|ry|jD]}|j dsyy)NFTmodify_)r|r~rr}r startswith)r=hc1rs r> has_changeszAlterColumnOp.has_changes s   , 0))6 0t+ 0""%/ '' B}}Y' r@c|jj}|j|d<|j|d<|j|d<|j |d<|j |j |d<|j|j|d<|jdur|j|d<|jdur|j|d <|Dcgc]}tjd |c}Dchc]}|r|jd }}|D](}d |z|vs |d |z}|d |z|d |z<||d |z<*|j|j|jfd|j i|Scc}wcc}w)Nryr{rzr_rr|Fr~r}z^(?:existing_|modify_)(.+)$rz modify_%sz existing_%srv)rr:ryr{rzr_rr|r~r}rergrouprVr{rrv)r=rkmall_keysswaps r>rFzAlterColumnOp.reverses WW\\^"00?"&"8"8 (,(D(D $%!%!6!6     ' $ 0 0B}     +$($8$8B !  % %U 2*.*D*DB& '   e +#'#6#6B LNNabhh=qAN  GGAJ   +AQ"$-!+,(*;?(;=1$%&*;?#  + t~~ OOT-- 6:kk EG  O s E*-E/) nullabler'server_defaultnew_column_namer]ryrzr{r_rvc  N|||f| | | | | |||||d |}|j|S)agIssue 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_type`` argument is used in this case to identify and remove a previous constraint that was bound to the type object. :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 comment: optional string text of a new comment to add to the column. :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 SQLAlchemy "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 existing_comment: string text of the existing comment on the column to be maintained. Required on MySQL if the existing comment on the column is not being changed. :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`. :param postgresql_using: String argument which will indicate a SQL expression to render within the Postgresql-specific USING clause within ALTER COLUMN. This string is taken directly as raw SQL which must explicitly include any necessary quoting or escaping of tokens within the expression. ) rvryrzr{r_rrr~r|r}r)r\rr{rrr'rrr]ryrzr{r_rvralts r>ruzAlterColumnOp.alter_column9sWX   '$;/-'"0$"     %%r@) rr'rrr]ryrzr{r_ insert_before insert_afterc  ||jj|f|jj|| | | |||||| | d |}|j|S)a2Issue an "alter column" instruction using the current batch migration context. Parameters are the same as that of :meth:`.Operations.alter_column`, as well as the following option(s): :param insert_before: String name of an existing column which this column should be placed before, when creating the new table. :param insert_after: String name of an existing column which this column should be placed after, when creating the new table. If both :paramref:`.BatchOperations.alter_column.insert_before` and :paramref:`.BatchOperations.alter_column.insert_after` are omitted, the column is inserted after the last existing column in the table. .. seealso:: :meth:`.Operations.alter_column` ) rvryrzr{r_rrr~r|r}rrr)r\rrrr'rrr]ryrzr{r_rrrrs r>rvz AlterColumnOp.batch_alter_columnsqZ OO & &  ??))'$;/-'"0$"'%  $  %%r@)r{rmrrmrvrry Optional[Any]rzrr{rr_rr|rr}$Optional[Union[str, Literal[False]]]r~rrrrrrrrJrrJrrJr)rJrx)rrr{rmrrmrrr'rr6Union[str, bool, Identity, Computed, TextClause, None]rrr]7Optional[Union[TypeEngine[Any], Type[TypeEngine[Any]]]]ryrrzrr{rr_rrvrrrrJr)rrrrmrrr'rrrrrr]rryrrzz.Optional[Union[str, bool, Identity, Computed]]r{rr_rrrrrrrrJr) rLrMrNrOr|rIrrFrqrurvrXrYs@r>rxrxsz/!%'+',,0*.*.?D%*%)%)   % "%*((= ### !&#>&>& ! >& 6 >&>&'>&G>& >&" >& *!>&"(#>&$%%>&&$'>&()>&* +>&>&r@rx add_columnbatch_add_columnceZdZdZddd d fdZddZ ddZddZeddZ e dd Z eddd dd Z edddd  dd Z xZ S) AddColumnOpz"Represent an add column operation.Nrvrc Rt|||||_||_||_yrR)rSr|columnrr)r=r{rrvrrrVs r>r|zAddColumnOp.__init__s- F3 *r@ctj|j|j|j}|j |_|SrC) DropColumnOpfrom_column_and_tablenamervr{rrrwr=rs r>rFzAddColumnOp.reverse s9  3 3 KK$++ ))  r@cJd|j|j|jfS)Nr)rvr{rr<s r>rIzAddColumnOp.to_diff_tuplesdkk4??DKKHHr@c|jSrC)rr<s r> to_columnzAddColumnOp.to_columns {{r@ch||jj||jjSrR)rrrv)r\cols r> from_columnzAddColumnOp.from_columns#399>>3syy/?/?@@r@c||||SrRr;r\rvrrs r>rz%AddColumnOp.from_column_and_tablenames5#f--r@c<|||||}|j|S)anIssue 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 :meth:`.Operations.add_column` method typically corresponds to the SQL command "ALTER TABLE... ADD COLUMN". Within the scope of this command, the column's name, datatype, nullability, and optional server-generated defaults may be indicated. .. note:: With the exception of NOT NULL constraints or single-column FOREIGN KEY constraints, other kinds of constraints such as PRIMARY KEY, UNIQUE or CHECK constraints **cannot** be generated using this method; for these constraints, refer to operations such as :meth:`.Operations.create_primary_key` and :meth:`.Operations.create_check_constraint`. In particular, the following :class:`~sqlalchemy.schema.Column` parameters are **ignored**: * :paramref:`~sqlalchemy.schema.Column.primary_key` - SQL databases typically do not support an ALTER operation that can add individual columns one at a time to an existing primary key constraint, therefore it's less ambiguous to use the :meth:`.Operations.create_primary_key` method, which assumes no existing primary key constraint is present. * :paramref:`~sqlalchemy.schema.Column.unique` - use the :meth:`.Operations.create_unique_constraint` method * :paramref:`~sqlalchemy.schema.Column.index` - use the :meth:`.Operations.create_index` method The provided :class:`~sqlalchemy.schema.Column` object may include a :class:`~sqlalchemy.schema.ForeignKey` constraint directive, referencing a remote table name. For this specific type of constraint, Alembic will automatically emit a second ALTER statement in order to add the single-column FOREIGN KEY constraint separately:: from alembic import op from sqlalchemy import Column, INTEGER, ForeignKey op.add_column( "organization", Column("account_id", INTEGER, ForeignKey("accounts.id")), ) The column argument passed to :meth:`.Operations.add_column` is a :class:`~sqlalchemy.schema.Column` construct, used in the same way it's used in SQLAlchemy. In particular, values or functions to be indicated as producing the column's default value 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`. :param if_not_exists: If True, adds IF NOT EXISTS operator when creating the new column for compatible dialects .. versionadded:: 1.16.0 rr)r\rr{rrvrrs r>rzAddColumnOp.add_column(s.x  '     $$r@)rrrci}|r||d<|r||d<||jj|f|jj|d|}|j|S)zIssue an "add column" instruction using the current batch migration context. .. seealso:: :meth:`.Operations.add_column` rrrr)r\rrrrrrrs r>rzAddColumnOp.batch_add_columnsq& "/B  !-B~   OO & &  ??))'      $$r@) r{rmr Column[Any]rvrrrrrrJr)rJrrJz+Tuple[str, Optional[str], str, Column[Any]])rJr)rrrJr)rvrrrmrrrJr) rrr{rmrrrvrrrrJr) rrrrrrrrrrrJr)rLrMrNrOr|rFrIrrqrrrrrXrYs@r>rrsp-!%(,      &    I 4I AA... .  ..!%(,a%a%a% a%  a%&a% a%a%F (,&*(,%#%% % % $ %&% %%r@r drop_columnbatch_drop_columnceZdZdZdddd d fdZ d dZddZe ddZ d ddZ edd  dd Z e dd Z xZ S)rz"Represent a drop column operation.Nruc `t|||||_||_||_||_yrR)rSr|rrrwrx)r=r{rrvrwrxrrVs r>r|zDropColumnOp.__init__s4 F3&"  r@cRd|j|j|jfS)N remove_column)rvr{rr<s r>rIzDropColumnOp.to_diff_tuples)  KK OO NN    r@c|j tdtj|j|j |jj }|j|_|S)Nz;operation is not reversible; original column is not present) rxrrrrvr{rrwrrs r>rFzDropColumnOp.reverses\ == 1   2 2 KK$--*>*>  >> r@c X|||j|tj|||S)N)rvrx)rrrrs r>rz&DropColumnOp.from_column_and_tablenames0  HH ::65#N   r@c|j|jjStj|}|j|jt SrC)rxrrrrrrs r>rzDropColumnOp.to_columnsH == $=='' ',,->?   !1!18<rzDropColumnOp.drop_columns,f[ > >2 >  $$r@c ||jj|fd|jji|}|j|S)zIssue a "drop column" instruction using the current batch migration context. .. seealso:: :meth:`.Operations.drop_column` rvr)r\rrrrs r>rzDropColumnOp.batch_drop_column' sO OO & &  ??))      $$r@)r{rmrrmrvrrwrrxzOptional[AddColumnOp]rrrJrr)rJr)rvrrrmrrrJrrC)rfrnrJr) rrr{rmrrmrvrrrrJr)rrrrmrrrJr) rLrMrNrOr|rIrFrqrrrrrXrYs@r>rrsK-!%$(*.!!!  ! " !(!! !  4              ?C=!;= =!% 3%3%3% 3%  3%3% 3%3%j%(%7:%BE% %%r@r bulk_insertcVeZdZdZdd ddZedd ddZy) BulkInsertOpz"Represent a bulk insert operation.T multiinsertc.||_||_||_yrC)rrowsr)r=rrrs r>r|zBulkInsertOp.__init__@ s  &r@c<||||}|j|y)axIssue 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. :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. rNr)r\rrrrrs r>rzBulkInsertOp.bulk_insertK s!R+ 6"r@N)rUnion[Table, TableClause]rList[Dict[str, Any]]rrrJr) rrrrrrrrrJr)rLrMrNrOr|rqrr;r@r>rr< s,! '( '# '  '  '! ii)i# i  i iir@rexecute batch_executec|eZdZdZdd ddZedd d dZedd d dZd dZy) ExecuteSQLOpz#Represent an execute SQL operation.Nexecution_optionsc ||_||_yrC)rr)r=rrs r>r|zExecuteSQLOp.__init__ s  !2r@c8|||}|j|S)a Execute the given SQL using the current migration context. The given SQL can be a plain string, e.g.:: op.execute("INSERT INTO table (foo) VALUES ('some value')") Or it can be any kind of Core SQL Expression construct, such as below where we use an update construct:: 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")}) ) Above, we made use of 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. 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. Additionally, parameterized statements are discouraged here, as they *will not work* in offline mode. Above, we use :meth:`.inline_literal` where parameters are to be used. For full interaction with a connected database where parameters can also be used normally, use the "bind" available from the context:: from alembic import op connection = op.get_bind() connection.execute( account.update() .where(account.c.name == "account 1") .values({"name": "account 2"}) ) Additionally, when passing the statement as a plain string, it is first coerced into a :func:`sqlalchemy.sql.expression.text` construct before being passed along. In the less likely case that the literal SQL string contains a colon, it must be escaped with a backslash, as:: op.execute(r"INSERT INTO table (foo) VALUES ('\:colon_value')") :param sqltext: 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` construct. * a :func:`sqlalchemy.sql.expression.delete` construct. * Any "executable" described in SQLAlchemy Core documentation, noting that no result set is returned. .. note:: when passing a plain string, the statement is coerced into a :func:`sqlalchemy.sql.expression.text` construct. This construct considers symbols with colons, e.g. ``:foo`` to be bound parameters. To avoid this, ensure that colon symbols are escaped, e.g. ``\:foo``. :param execution_options: Optional dictionary of execution options, will be passed to :meth:`sqlalchemy.engine.Connection.execution_options`. rr)r\rrrrs r>rzExecuteSQLOp.execute s#p,= >  $$r@c*|j|||S)zExecute the given SQL using the current migration context. .. seealso:: :meth:`.Operations.execute` r)r)r\rrrs r>rzExecuteSQLOp.batch_execute! s"{{ 3D  r@cd|jfS)Nr)rr<s r>rIzExecuteSQLOp.to_diff_tuple4 s4<<((r@)rUnion[Executable, str]rOptional[dict[str, Any]]rJr)rrrrrrrJr)rJz"Tuple[str, Union[Executable, str]]) rLrMrNrOr|rqrrrIr;r@r>rr s. 7; 3'34 3  3 7; X%X%(X% 4 X%  X%X%t 7;   ( 4     $)r@rcDeZdZdZdddZd dZd dZe d dZy) OpContainerz-Represent a sequence of operations operation.c$t||_yrC)r4ops)r=rs r>r|zOpContainer.__init__; s 9r@c|j SrCrr<s r>is_emptyzOpContainer.is_empty> s88|r@c>ttj|SrC)r4r _ops_as_diffsr<s r>as_diffszOpContainer.as_diffsA sK--d344r@c#K|jD]D}t|dr$|jtd|Ed{3|j Fy7w)Nrr)rhasattrrrrI)r\ migrationsrs r>rzOpContainer._ops_as_diffsD sR.. )Br5!,,T--DEEE&&((  )Es:AAAN)r;)rSequence[MigrateOperation]rJrrr)rrrJzIterator[Tuple[Any, ...]]) rLrMrNrOr|rrrqrr;r@r>rr8 s875)$) "))r@rc@eZdZdZdd dfdZddZxZS)ModifyTableOpszCContains a sequence of operations that all apply to a single Table.Nrc@t||||_||_yrC)rSr|r{rv)r=r{rrvrVs r>r|zModifyTableOps.__init__R s  $ r@c t|jtt|jDcgc]}|j c}|j Scc}w)N)rrv)rr{r4reversedrrFrvrs r>rFzModifyTableOps.reverse] sB OOXdhh?rzz|?@A;;  ?sA)r{rmrrrvrrJr)rJrrLrMrNrOr|rFrXrYs@r>rrO s;M!%  (      r@rcDeZdZdZ d dfd ZddZddZxZS) UpgradeOpszcontains a sequence of operations that would apply to the 'upgrade' stream of a script. .. seealso:: :ref:`customizing_revision` c4t||||_yNr)rSr| upgrade_token)r=rrrVs r>r|zUpgradeOps.__init__o s S!*r@c tt|jDcgc]}|jc}|jdd|Scc}wrC)r4rrrF)r= downgrade_opsrs r> reverse_intozUpgradeOps.reverse_intow sA# TXX6rbjjl6 7 !7sA c8|jtgSr)r DowngradeOpsr<s r>rFzUpgradeOps.reverse} s  "!566r@)r;upgrades)rrrrmrJr)rrrJr)rJr)rLrMrNrOr|rrFrXrYs@r>rre s;+-'+ '++  + 7r@rc<eZdZdZ d dfd ZddZxZS)rzcontains a sequence of operations that would apply to the 'downgrade' stream of a script. .. seealso:: :ref:`customizing_revision` c4t||||_yr)rSr|downgrade_token)r=rrrVs r>r|zDowngradeOps.__init__ s S!.r@c ttt|jDcgc]}|j c}Scc}wr)rr4rrrFrs r>rFzDowngradeOps.reverse s4Xdhh?rzz|?@A  ?sA)r; downgrades)rrrrmrJr)rJrrrYs@r>rr s6+-+/ '//  / r@rc"eZdZUdZded<ded<ded<dedddddd  dd Zedd Zej dd Zedd Z e j ddZ eddZ eddZ y)MigrationScriptaprepresents 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. .. seealso:: :ref:`customizing_revision` r _needs_renderList[UpgradeOps] _upgrade_opsList[DowngradeOps]_downgrade_opsN)messageimportsheadsplice branch_label version_path depends_onc||_||_||_||_||_||_| r#t j| jnd|_ | |_ ||_ ||_ yrC) rev_idrrrr r pathlibPathas_posixr r  upgrade_opsr) r=rrrrrrr r r r s r>r|zMigrationScript.__init__ si     (5AGLL & / / 1t %&*r@ct|jdkDr td|jsy|jdS)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)lenrrr<s r>rzMigrationScript.upgrade_ops sH t  !A %.  ""$$Q' 'r@c~tj||_|jD]}t|trJyrC)rto_listr isinstancer)r=relems r>rzMigrationScript.upgrade_ops s:!LL5%% 0DdJ/ // 0r@ct|jdkDr td|jsy|jdS)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)rrrr<s r>rzMigrationScript.downgrade_ops sH t"" #a '0  $$&&q) )r@c~tj||_|jD]}t|trJyrC)rrrrr)r=rrs r>rzMigrationScript.downgrade_ops s:#ll=9'' 2DdL1 11 2r@c|jS)zA 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. )rr<s r>upgrade_ops_listz MigrationScript.upgrade_ops_list s   r@c|jS)zA 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. )rr<s r>downgrade_ops_listz"MigrationScript.downgrade_ops_list s"""r@)rrrrrrrrrzSet[str]rrr rr Optional[_RevIdType]r z"Union[str, os.PathLike[str], None]r rrJr)rJzOptional[UpgradeOps])rz#Union[UpgradeOps, List[UpgradeOps]]rJr)rJzOptional[DowngradeOps])rz'Union[DowngradeOps, List[DowngradeOps]]rJr)rJr)rJr) rLrMrNrOrRsetr|rprsetterrrrr;r@r>rr sI."!""&&"&E"!%-1;?+/++ +$ +  ++++++9+)+ +6(($0>0 00**$2D2 22!!##r@r)] __future__rabcrosrrtypingrrrrr r r r r rrrrrrrsqlalchemy.typesrrbaserrrrrsqlalchemy.sqlrsqlalchemy.sql.elementsrr r!r"sqlalchemy.sql.schemar#r$r%r&r'r(r)r*r+r,r-r.sqlalchemy.sql.selectabler/sqlalchemy.sql.type_apir0autogenerate.rewriterr1runtime.migrationr2script.revisionr3r4r6r9r7register_operationrir`rrrrrrr#r,rLrPr]rgrxrrrrrrrrrr;r@r>r2s"  ! %!)5,325,.0:.+.:0+65204, T e,-""@#8&#8L01###$57NO%'%P2%D34###4(()ABt%t%C5 t%n9:### @(()<=%%>; %D34###4(()ABZ%Z%C5 Z%z89###>(();<(()KL(()BC%o%DM=:%D~.###N4HIV%$V%J/V%r|,###L2DEw%"w%F-w%t~.e%$e%/e%P|,d"d-dN # ~.!%L!%/!%H56###8jM<jM7jMZ34###4N9N95N9b~.###N4HI]&L]&J/]&@ |,###L2DEq%,q%F-q%h}-###M3FGH%<H%H.H%V}-x#x.xvy)###I?{)#{)@*{)|)"). [ ,778 ; 0A#&A#r@