bgk  ddlmZddlmZddlZddlmZddlmZddlmZddlm Z ddlm Z dd lm Z dd lm Z dd lm Z dd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZerddlmZddlmZddlm 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)m/Z/dd)l)m0Z0dd*l)m1Z1dd+l)m2Z2dd,l)m3Z3dd-l)m4Z4dd.l)m5Z5dd/l6m7Z7dd0l8m9Z9dd1l:m;Z;dd2lGd5d6e>Z?ej@d7ej@d7d8Gd9d:e>ZAej@d;ej@d;d<e?Bd=Gd>d?e?ZCej@d@ej@d@dAe?BdBGdCdDe?ZDej@dEej@dEdFe?BdGGdHdIe?ZEej@dJej@dJdKe?BdLe?BdMe?BdNGdOdPe?ZFej@dQej@dQdRGdSdTe>ZGej@dUej@dUdVGdWdXe>ZHej@dYGdZd[e>ZIej@d\Gd]d^e>ZJGd_d`e>ZKej@daGdbdceKZLej@ddej@dddeGdfdgeKZMej@dhej@dhdiGdjdkeKZNej@dlej@dldmGdndoeKZOej@dpej@dpdqGdrdseKZPej@dtej@dtduGdvdweKZQej@dxGdydze>ZRej@d{ej@d{d|Gd}d~e>ZSGdde>ZTGddeTZUGddeTZVGddeTZWGdde>ZXdS)) annotations)abstractmethodN)Any)Callable)cast) FrozenSet)Iterator)List)MutableMapping)Optional)Sequence)Set)Tuple)Type) TYPE_CHECKING)Union)NULLTYPE) schemaobj)BatchOperations) Operations)util) sqla_compat)Literal)Insert)Update)BinaryExpression) ColumnElement)conv) quoted_name) TextClause)Function)CheckConstraint)Column)Computed) Constraint)ForeignKeyConstraint)Identity)Index)MetaData)PrimaryKeyConstraint) SchemaItem)Table)UniqueConstraint) TableClause) TypeEngine)Rewriter)MigrationContextcbeZdZUdZejdZeZde d<d dZ d dZ d S) 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 M/opt/cloudlinux/venv/lib64/python3.11/site-packages/alembic/operations/ops.pyinfozMigrateOperation.infoIs  zFrozenSet[Rewriter] _mutationsreturnctNNotImplementedErrorr8s r:reversezMigrateOperation.reverseS!!r<Tuple[Any, ...]ctr@rAr8s r: to_diff_tuplezMigrateOperation.to_diff_tupleVrDr<N)r>r5)r>rE) __name__ __module__ __qualname____doc__rmemoized_propertyr; frozensetr=__annotations__rCrGr7r<r:r5r5:s   '0ikkJ1111""""""""""r<r5ceZdZdZejZedZe ddZ e dd Z e dddZ ddZddZd S)AddConstraintOpz&Represent an add constraint operation.ctr@rAr8s r:constraint_typezAddConstraintOp.constraint_type_s!###r<type_strr>rcfd}|S)NcXj|j|Sr@)add_constraint_ops dispatch_forfrom_constraint)klassclsrSs r:goz3AddConstraintOp.register_add_constraint..goes, 6C " / / 6 6u7L M M MLr<r7)r[rSr\s`` r:register_add_constraintz'AddConstraintOp.register_add_constraintcs)       r< constraintr'cR|j|j|Sr@)rWdispatch__visit_name__)r[r^s r:rYzAddConstraintOp.from_constraintks-Is%..z/HII    r<Nmigration_contextOptional[MigrationContext]cdSr@r7)r9rbs r: to_constraintzAddConstraintOp.to_constraintqs  r<DropConstraintOpcZt|Sr@)rfrYrer8s r:rCzAddConstraintOp.reversews"//0B0B0D0DEEEr<Tuple[str, Constraint]c.d|fS)Nadd_constraintrer8s r:rGzAddConstraintOp.to_diff_tuplezs $"4"4"6"677r<)rSrTr>r)r^r'r>rPr@)rbrcr>r')r>rf)r>rh)rHrIrJrKr DispatcherrWpropertyrR classmethodr]rYrrerCrGr7r<r:rPrPZs00(** $$X$[   [ >B    ^ FFFF888888r<rPdrop_constraintbatch_drop_constraintceZdZdZ ddddddZd dZd!dZed"dZd#dZ e dddd$dZ e dd%dZ dS)&rfz&Represent a drop constraint operation.Nschema_reverseconstraint_name,Optional[sqla_compat._ConstraintNameDefined] table_namerTrS Optional[str]rsrtOptional[AddConstraintOp]r>NonecL||_||_||_||_||_dSr@)rurwrRrsrt)r9rurwrSrsrts r:__init__zDropConstraintOp.__init__s- /$$   r<rPcZt|Sr@)rPrYrer8s r:rCzDropConstraintOp.reverses"..t/A/A/C/CDDDr<Tuple[str, SchemaItem]cp|jdkrd|fSd|fS)N foreignkey remove_fkremove_constraint)rRrer8s r:rGzDropConstraintOp.to_diff_tuples@  < / /!3!3!5!56 6'););)=)=> >r<r^r'c ddddddd}tj|}|tj|j|j|j||jt |S)Nuniquerprimarycheck)unique_constraintforeign_key_constraintprimary_key_constraintcheck_constraintcolumn_check_constraint table_or_column_check_constraint)rsrSrt)r_table_for_constraintconstraint_name_or_nonenamersrarPrY)r[r^typesconstraint_tables r:rYz DropConstraintOp.from_constraints"*&2&/ ''.07   'rz)r>rP)r>r~)r^r'r>rf)r>r') rrrurTrwrTrSrxrsrxr>rz)rrrurTrSrxr>rz) rHrIrJrKr|rCrGrnrYrerorpr7r<r:rfrf~s10 $ ! !%.2 ! ! ! ! ! !EEEE????   [ &  $ %!%%%%%%[%2 $ %%%%[%%%r<rfcreate_primary_keybatch_create_primary_keyrc~eZdZdZdZddddZed dZ d!d"dZeddd#dZ ed$dZ dS)%CreatePrimaryKeyOpz)Represent a create primary key operation. primarykeyNrrurvrwrTcolumns Sequence[str]rsrxkwrr>rzc L||_||_||_||_||_dSr@rurwrrsrr9rurwrrsrs r:r|zCreatePrimaryKeyOp.__init__, /$  r<r^r'ctj|}td|}|tj|j|j|jfd|ji|jS)Nr,rs) rrrrrrkeysrsdialect_kwargs)r[r^r pk_constraints r:rYz"CreatePrimaryKeyOp.from_constraints&?? 0z0  O L  ;  g    r<rr List[str]cJ|||||}||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[rrurwrrsrs r:rz%CreatePrimaryKeyOp.create_primary_key(s1XS*gf E E E  $$$r<rcr|||jj||jj}||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[rrurrs r:rz+CreatePrimaryKeyOp.batch_create_primary_keyWsF$S  O & ?)       $$$r< rurvrwrTrrrsrxrrr>rz)r^r'r>rr@)rbrcr>r,) rrrurxrwrTrrrsrxr>rz)rrrurTrrr>rz) rHrIrJrKrRr|rnrYrerrr7r<r:rrs 43"O!%          [  ?C      !%,%,%,%,%,%[,%\%%%[%%%r<rcreate_unique_constraintbatch_create_unique_constraintrc~eZdZdZdZddddZeddZ d d!dZeddd"dZ ed#dZ dS)$CreateUniqueConstraintOpz/Represent a create unique constraint operation.rNrrurvrwrTrrrsrxrrr>rzc L||_||_||_||_||_dSr@rrs r:r|z!CreateUniqueConstraintOp.__init__|rr<r^r'c@tj|}td|}i}|jr |j|d<|jr |j|d<||j|tj|j|jd|j Dfd|j i|S)Nr/ deferrable initiallycg|] }|j Sr7)r).0cs r: z.s 3 3 3QV 3 3 3r<rs) rrrrrupdaterrrrrs)r[r^r uq_constraintrs r:rYz(CreateUniqueConstraintOp.from_constraints '?? +z+  O L  ;  g    r<rrc F||||fd|i|}||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`. rsr)r[rrurwrrsrrs r:rz1CreateUniqueConstraintOp.create_unique_constraints9bS*g K Kf K K K  $$$r<rc t|jj|d<|||jj|fi|}||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` rs)rrsrwr)r[rrurrrs r:rz7CreateUniqueConstraintOp.batch_create_unique_constraintsF&"-8 S*/"rr@)rbrcr>r/)rrrurxrwrTrrrsrxrrr>r) rrrurTrrrrr>r) rHrIrJrKrRr|rnrYrerrr7r<r:rrrs :9O!%         [ .?C      !%1%1%1%1%1%[1%f%%%[%%%r<rcreate_foreign_keybatch_create_foreign_keyrc eZdZdZdZd+dZd,dZed-dZ d.d/dZ eddddddddd0d'Z eddddddd(d1d*Z dS)2CreateForeignKeyOpz4Represent a create foreign key constraint operation.rrurv source_tablerTreferent_table local_colsr remote_colsrrr>rzc Z||_||_||_||_||_||_dSr@)rurrrrr)r9rurrrrrs r:r|zCreateForeignKeyOp.__init__s6 /(,$&r< Tuple[str, ForeignKeyConstraint]c.d|fS)Nadd_fkrkr8s r:rGz CreateForeignKeyOp.to_diff_tuples$,,..//r<r^r'c td|}i}|jr |j|d<|jr |j|d<|jr |j|d<|jr |j|d<|jr |j|d<t j|\ }}}}}} } } } } ||d<||d<||j |t j |j |||| fi|S) Nr(onupdateondeleterr use_alter source_schemareferent_schema) rrrrrrr_fk_specrrrr)r[r^ fk_constraintrrrsource_columns target_schema target_tabletarget_columnsrrrrs r:rYz"CreateForeignKeyOp.from_constraints,3Z@@   ! 4*3BzN  ! 4*3BzN  " 6+5B{O  # 8,7B|   " 6+5B{O   / /          ,? -  -.///s  / 0B C C           r<Nrbrcr(ctj|}|j|j|j|j|j|jfi|jSr@) rrrrurrrrrrs r:rez CreateForeignKeyOp.to_constraint@sZ,->?? 0z0      O     g    r<)rrrrmatchrrrrrxrrrOptional[bool]rrrr dialect_kwc V||||||f||| | | | | d|}||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[rrurrrrrrrrrrrrrs r:rz%CreateForeignKeyOp.create_foreign_keyMsfJS       !'+      $$$r<)rrrrrrrc ~|||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` rr)r[rrurrrrrrrrrrrs r:rz+CreateForeignKeyOp.batch_create_foreign_keyspLS  O &     !$/0+      $$$r<)rurvrrTrrTrrrrrrr>rz)r>r)r^r'r>rr@)rbrcr>r()rrrurxrrTrrTrrrrrrxrrxrrrrxrrxrrxrrxrrr>rz)rrrurTrrTrrrrrrxrrxrrxrrrrxrrxrrr>rz) rHrIrJrKrRr|rGrnrYrerrr7r<r:rrs ?>"O 0000& & & [& R?C      #'"&%)#'#'+)-S%S%S%S%S%[S%j*."&"&%)#'#4%4%4%4%4%[4%4%4%r<rcreate_check_constraintbatch_create_check_constraintrrrc~eZdZdZdZddddZed dZ d!d"dZeddd#dZ ed$dZ dS)%CreateCheckConstraintOpz.Represent a create check constraint operation.rNrrurvrwrT condition*Union[str, TextClause, ColumnElement[Any]]rsrxrrr>rzc L||_||_||_||_||_dSr@)rurwrrsr)r9rurwrrsrs r:r|z CreateCheckConstraintOp.__init__s, /$" r<r^r'ctj|}td|}|tj|j|jtd|jfd|ji|jS)Nr$zColumnElement[Any]rs)rrrrrsqltextrsr)r[r^r ck_constraints r:rYz'CreateCheckConstraintOp.from_constraints'?? *z*  O N  ;  g    r<rr(Union[str, BinaryExpression, TextClause]c F||||fd|i|}||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`. rsr)r[rrurwrrsrrs r:rz/CreateCheckConstraintOp.create_check_constraints9fS*i M M M" M M  $$$r<rc n|||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` rsr)r[rrurrrs r:rz5CreateCheckConstraintOp.batch_create_check_constraintGsW&S  O &   ?)       $$$r<) rurvrwrTrrrsrxrrr>rz)r^r'r>rr@)rbrcr>r$)rrrurxrwrTrrrsrxrrr>rz) rrrurTrrrrr>rz) rHrIrJrKrRr|rnrYrerrr7r<r:rrs98O!%          [  ?C      !%3%3%3%3%3%[3%j%%%[%%%r<r create_indexbatch_create_indexceZdZdZdddd$dZd%dZd&dZed'dZ d(d)dZ edddd*d Z ed+d#Z dS), CreateIndexOpz#Represent a create index operation.NFrsr index_namerxrwrTr4Sequence[Union[str, TextClause, ColumnElement[Any]]]rsrboolrrr>rzc Z||_||_||_||_||_||_dSr@)rrwrrsrr)r9rrwrrsrrs r:r|zCreateIndexOp.__init__is2%$   r< DropIndexOpcZt|Sr@)r from_indexto_indexr8s r:rCzCreateIndexOp.reversezs%%dmmoo666r<Tuple[str, Index]c.d|fS)N add_indexrr8s r:rGzCreateIndexOp.to_diff_tuple}T]]__--r<indexr*c|jJ||j|jjtj|f|jj|jd|jSNr)tablerr_get_index_expressionsrsrkwargsr[rs r:rzCreateIndexOp.from_indexsd{&&&s J K   .u 5 5 ;%<   l    r<rbrcctj|}|j|j|j|jf|j|jd|j}|Sr ) rrrrrwrrsrr)r9rbridxs r:rzCreateIndexOp.to_indexsa,->?? j O O L ;;   g    r<rr/Sequence[Union[str, TextClause, Function[Any]]]c H||||f||d|}||S)a'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)")]) :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 \**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[rrrwrrsrrrs r:rzCreateIndexOp.create_indexsJnS  G 4:6  MO    $$$r<rrc n|||jj|fd|jji|}||S)zIssue a "create index" instruction using the current batch migration context. .. seealso:: :meth:`.Operations.create_index` rsr)r[rrrrrs r:rz CreateIndexOp.batch_create_indexsW"S  O &   ?)       $$$r<)rrxrwrTrrrsrxrrrrr>rz)r>rr>r)rr*r>rr@rbrcr>r*)rrrrxrwrTrrrsrxrrrrr>rz) rrrrTrrrrr>rz) rHrIrJrKr|rCrGrnrrrrr7r<r:rrds.-!%"7777....    [  ?C     !%9%9%9%9%9%[9%v%%%[%%%r<r drop_indexbatch_drop_indexceZdZdZ d!dddd"dZd#dZd$dZed%dZ d!d&dZ e d!ddd'dZ ed(d Z dS))rz!Represent a drop index operation.NrrrUnion[quoted_name, str, conv]rwrxrsrtOptional[CreateIndexOp]rrr>rzc L||_||_||_||_||_dSr@)rrwrsrtr)r9rrwrsrtrs r:r|zDropIndexOp.__init__s+%$   r<rc.d|fS)N remove_indexrr8s r:rGzDropIndexOp.to_diff_tuple 00r<rcZt|Sr@)rrrr8s r:rCzDropIndexOp.reverse '' 888r<rr*c|jJ||jf|jj|jjt|d|jS)N)rwrsrt)r rrsrrr r s r:rzDropIndexOp.from_index s`{&&&s J {';%"--e44   l    r<rbrcctj|}|j|j|j|jr |jjndgfd|ji|jS)Nxrs) rrrrrwrtrrsrrs r:rzDropIndexOp.to_indexsk,->??  z O O%)] =DM ! !  ;  g    r<rrrrTc D||f||d|}||S)aQIssue 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 \**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. rwrsr)r[rrrwrsrrs r:rzDropIndexOp.drop_index&s6>S H 6 H HR H H  $$$r<rc l||f|jj|jjd|}||S)zIssue a "drop index" instruction using the current batch migration context. .. seealso:: :meth:`.Operations.drop_index` r$r)r[rrrrs r:rzDropIndexOp.batch_drop_indexHsRS  !1?)        $$$r<r@) rrrwrxrsrxrtrrrr>rzr)r>r)rr*r>rr) rrrrTrwrxrsrxrrr>rz)rrrrTrrr>rz) rHrIrJrKr|rGrCrnrrrrr7r<r:rrs ,+ %)  !%,0      11119999   [ ?C       %) % !% %%%%%[%B%%%[%%%r<r create_tablecveZdZdZddddd#dZd$dZd%dZeddd&dZ d'd(dZ ed)d"Z dS)* CreateTableOpz#Represent a create table operation.NF)rs_namespace_metadata_constraints_includedrwrTrSequence[SchemaItem]rsrxr)Optional[MetaData]r*rrrr>rzc ||_||_||_|di|_|dd|_|dd|_||_||_||_ dS)Nr;commentprefixes) rwrrspopr;r.r/rr)r*)r9rwrrsr)r*rs r:r|zCreateTableOp.__init__bsu%  FF62&& vvi.. z400 #6 %:"""r< DropTableOpcht||jS)Nr))r1 from_tableto_tabler)r8s r:rCzCreateTableOp.reversevs/%% MMOO1I&   r<Tuple[str, Table]c.d|fS)N add_tabler5r8s r:rGzCreateTableOp.to_diff_tuple{rr<r3r r.c ||j}||jt|jt|jzf|j|d|jt|jt|j d|j S)NT)rsr)r*r.r;r/) metadatarlistr constraintsrsr.dictr; _prefixesr r[r r)s r:r4zCreateTableOp.from_table~s  &"'. s J MMD!233 3 < 3#'Mej!!%/**  l   r<rbrcc  tj|}|j|jg|jR|j|jrt|jng|j|j r|j ni|j d|j S)N)rsr/r.r;r*) rrr rwrrsr/r<r.r;copyr*rrs r:r5zCreateTableOp.to_tables,->?? z O  \   ;,0MAT$-(((rL%)Y6!!!B"&"<   g   r<rrr-c@|||fi|}||S)aM 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 \**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. r)r[rrwrrrs r:r&zCreateTableOp.create_tables2jSW + + + +  $$$r<)rwrTrr+rsrxr)r,r*rrrr>rz)r>r1r>r6)r r.r)r,r>r(r@rbrcr>r.) rrrwrTrr-rrr>r.) rHrIrJrKr|rCrGrnr4r5r&r7r<r:r(r(^s--!%26&+;;;;;;(    ....HL     [ 2?C     U%U%U%[U%U%U%r<r( drop_tablec|eZdZdZddddd"dZd#dZd$dZeddd%dZ d&d'dZ eddd(d!Z dS))r1z!Represent a drop table operation.Nrstable_kwrtrwrTrsrxrI"Optional[MutableMapping[Any, Any]]rtOptional[CreateTableOp]r>rzc||_||_|pi|_|jdd|_|jdd|_|jdd|_||_dS)Nr.r;r/)rwrsrIr0r.r;r/rt)r9rwrsrIrts r:r|zDropTableOp.__init__ss%  B }((D99 M%%fd33  ))*d;;   r<r6c.d|fS)N remove_tabler9r8s r:rGzDropTableOp.to_diff_tuplerr<r(cZt|Sr@)r(r4r5r8s r:rCzDropTableOp.reverserr<r3r r.r)r,c ||j|j|jt|jt |jd|jt ||S)N)r.r;r/r3rH) rrsr.r>r;r<r?r r(r4r@s r:r4zDropTableOp.from_tables|s J< =UZ(( 11,  #--+>.    r<rbrcc L|jr |jj}ng}tj|}|j|jg|R|j|jr|jni|j rt|j ng|j |jr |jj ndd|j }|S)NF)r.r;r/rsr*)rtrrrr rwr.r;rBr/r<rsr*rI)r9rbcols_and_constraintsrts r:r5zDropTableOp.to_table,s = &#'=#8 #% ,->?? J  O ! L%)Y6!!!B,0MAT$-(((r;}#$-"E"E m r<rrrrrc L||||}||dS)a8Issue 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 \**kw: Other keyword arguments are passed to the underlying :class:`sqlalchemy.schema.Table` object created for the command. )rsrINr)r[rrwrsrrs r:rFzDropTableOp.drop_tableCs44SFR 8 8 8"r<) rwrTrsrxrIrJrtrKr>rzrD)r>r()r r.r)r,r>r1r@rE) rrrwrTrsrxrrr>rz) rHrIrJrKr|rGrCrnr4r5rFr7r<r:r1r1s++ !%7;,0 !!!!!! 11119999HL     [ $?C. !% [r<r1c eZdZdZddd d ZdS) AlterTableOpz#Represent an alter table operation.NrrwrTrsrxr>rzc"||_||_dSr@r$)r9rwrss r:r|zAlterTableOp.__init__ds % r<)rwrTrsrxr>rz)rHrIrJrKr|r7r<r:rVrVas=-- !% r<rV rename_tablecHeZdZdZdddfd ZeddddZxZS) RenameTableOpz#Represent a rename table operation.Nrold_table_namerTnew_table_namersrxr>rzc\t||||_dSNr)superr|r\)r9r[r\rs __class__s r:r|zRenameTableOp.__init__rs0 777,r<rrcH||||}||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[rr[r\rsrs r:rXzRenameTableOp.rename_table|s.&S ? ? ?  $$$r<)r[rTr\rTrsrxr>rz) rrr[rTr\rTrsrxr>rz)rHrIrJrKr|rnrX __classcell__r`s@r:rZrZns--!% --------!% %%%%%[%%%%%r<rZcreate_table_commentbatch_create_table_commentcteZdZdZddddd Zeddd ddZeddddZdZddZ dZ dS)CreateTableCommentOpz)Represent a COMMENT ON `table` operation.Nrsexisting_commentrwrTr.rxrsrir>rzc>||_||_||_||_dSr@)rwr.rirs)r9rwr.rsris r:r|zCreateTableCommentOp.__init__s%% 0 r<rirsrrcJ|||||}||S)arEmit a COMMENT ON operation to set the comment for a table. .. versionadded:: 1.0.6 :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` rkr)r[rrwr.rirsrs r:rdz)CreateTableCommentOp.create_table_comments<<S  -       $$$r<rircr||jj|||jj}||S)aEmit a COMMENT ON operation to set the comment for a table using the current batch migration context. .. versionadded:: 1.6.0 :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. rkr)r[rr.rirs r:rez/CreateTableCommentOp.batch_create_table_commentsF,S O & -?)       $$$r<c|j!t|j|j|jSt |j|j|j|jS)2Reverses the COMMENT ON operation against a table.Nrk)riDropTableCommentOprwr.rsrgr8s r:rCzCreateTableCommentOp.reverses_  (%!%{  (%!%{  r<cxtj|}||j|j|jS)N)rsr.)rrr rwrsr.rs r:r5zCreateTableCommentOp.to_tables=,->??  ODK    r<c:d||jfS)Nadd_table_comment)r5rir8s r:rGz"CreateTableCommentOp.to_diff_tuples#T]]__d6KLLr<) rwrTr.rxrsrxrirxr>rz) rrrwrTr.rxrirxrsrxr>rz)rrr.rxrirxr>rzr@) rHrIrJrKr|rnrdrerCr5rGr7r<r:rgrgs 43!%*.      +/ $#%#%#%#%#%[#%J +/ %%%%%[%:     MMMMMr<rgdrop_table_commentbatch_drop_table_commentcteZdZdZddddd Zeddd ddZeddddZdZddZ dZ dS)rqz:Represent an operation to remove the comment from a table.NrhrwrTrsrxrir>rzc0||_||_||_dSr@)rwrirs)r9rwrsris r:r|zDropTableCommentOp.__init__ s% 0 r<rkrrcH||||}||S)aIssue a "drop table comment" operation to remove an existing comment set on a table. .. versionadded:: 1.0.6 :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` rkr)r[rrwrirsrs r:ruz%DropTableCommentOp.drop_table_comments/4S.>v N N N  $$$r<rmrcp||jj||jj}||S)a6Issue a "drop table comment" operation to remove an existing comment set on a table using the current batch operations context. .. versionadded:: 1.6.0 :param existing_comment: An optional string value of a comment already registered on the specified table. rkr)r[rrirs r:rvz+DropTableCommentOp.batch_drop_table_comment5sC$S O &-?)      $$$r<cDt|j|j|jS)rpr)rgrwrirsr8s r:rCzDropTableCommentOp.reverseNs'# OT24;    r<cltj|}||j|jSr^)rrr rwrsrs r:r5zDropTableCommentOp.to_tableTs0,->??  DDDr<c.d|fS)Nremove_table_commentr9r8s r:rGz DropTableCommentOp.to_diff_tupleYs& 88r<)rwrTrsrxrirxr>rz) rrrwrTrirxrsrxr>rz)rrrirxr>rzr@) rHrIrJrKr|rnrurvrCr5rGr7r<r:rqrqs ED !%*.       +/ $ %%%%%[%8 +/ %%%%%[%0   EEEE 99999r<rq alter_columnbatch_alter_columnc eZdZdZddddddddddd d/fdZd0dZd1dZd2dZeddddddddddd d3d)Z edddddddddddd* d4d.Z xZ S)5 AlterColumnOpz$Represent an alter column operation.NF) rs existing_typeexisting_server_defaultexisting_nullablerimodify_nullablemodify_commentmodify_server_default modify_name modify_typerwrT column_namersrxr Optional[Any]rrrrrirr$Optional[Union[str, Literal[False]]]rrrrr>rzc  t||||_||_||_||_||_||_| |_| |_ | |_ | |_ | |_ dSr^) r_r|rrrrrirrrrrr)r9rwrrsrrrrirrrrrrr`s r:r|zAlterColumnOp.__init__bs}" F333&*'>$!2 0.,%:"&&r<c <g}|j|j|j}}}|j9|d||||j|j|jd|j|jf|j 9|d||||j|j|jd|j|j f|j dur9|d||||j|j|jd|j|j f|j dur9|d||||j|j|jd |j|j f|S) Nr)rrrir)rrriFmodify_default)rrrir)rrr) rsrwrrappendrrrirrrr)r9col_diffrstnamecnames r:rGzAlterColumnOp.to_diff_tuples#{DOT=Mu   ' OO!-1-C 8,0,A &$   $   + OO%)-); 8,0,A *(   $  %U 2 2 OO$-1-C)-);,0,A 0.      e + + OO$-1-C)-); 8 )'   $r<rc|jdup|jdup|jdup|jdu}|rdS|jD]}|drdSdS)NFTmodify_)rrrrr startswith)r9hc1rs r: has_changeszAlterColumnOp.has_changess   , 0)6 0t+ 0"%/  4'  B}}Y'' tt 5r<c|j}|j|d<|j|d<|j|d<|j|d<|j |j|d<|j |j|d<|jdur |j|d<|j dur |j |d <d d |DD}|D]-}d |z|vr$|d |z}|d |z|d |z<||d |z<.|j |j |j fd|j i|S)NrrrrirrFrrc<h|]}||dS)r)group)rms r: z(AlterColumnOp.reverse..s8    GGAJJ   r<c8g|]}tjd|S)z^(?:existing_|modify_)(.+)$)rer)rks r:rz)AlterColumnOp.reverse..s%NNNabh=qAANNNr<z modify_%sz existing_%srs)rrBrrrrirrrrr`rwrrs)r9rall_keysrswaps r:rCzAlterColumnOp.reversesf W\\^^"0?"&"8 (,(D $%!%!6    ' $ 0B}    +$($8B !  %U 2 2*.*DB& '  e + +#'#6B   NN2NNN     + +AQ"$$-!+,(*;?(;=1$%&*;?#t~ OT-  6:k EG   r<) nullabler.server_defaultnew_column_namerSrrrrirsrrrr.rrrS-Optional[Union[TypeEngine, Type[TypeEngine]]].Optional[Union[str, bool, Identity, Computed]]c  V|||f| | | | | |||||d |}||S)aIssue 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. .. versionadded:: 1.0.6 :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 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. .. versionadded:: 1.0.6 :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. ) rsrrrrirrrrrr)r[rrwrrr.rrrSrrrrirsralts r:rzAlterColumnOp.alter_columnsf\c   '$;/-'"0$"       %%%r<) rr.rrrSrrrri insert_before insert_afterrrrc  ||jj|f|jj|| | | |||||| | d |}||S)avIssue 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. .. versionadded:: 1.4.0 :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. .. versionadded:: 1.4.0 .. seealso:: :meth:`.Operations.alter_column` ) rsrrrrirrrrrrrr)r[rrrr.rrrSrrrrirrrrs r:rz AlterColumnOp.batch_alter_columnsv^c O &  ?)'$;/-'"0$"'%    $  %%%r<)rwrTrrTrsrxrrrrrrrirxrrrrrrrrxrrrrr>rzr>rr>r)r>r)rrrwrTrrTrrr.rrrrrxrSrrrrrrrrirxrsrxrrr>rz)rrrrTrrr.rrrrrxrSrrrrrrrrirxrrxrrxrrr>rz) rHrIrJrKr|rGrrCrnrrrbrcs@r:rr]s]/.!%'+',,0*.*.?D%*%)%)rzc jt||||_||_dSr^)r_r|rr)r9rwrrsrr`s r:r|zAddColumnOp.__init__s4 F333 r< DropColumnOpcXt|j|j|jSr@)rfrom_column_and_tablenamersrwrr8s r:rCzAddColumnOp.reverses'55 K$+   r<+Tuple[str, Optional[str], str, Column[Any]]c,d|j|j|jfS)Nr)rsrwrr8s r:rGzAddColumnOp.to_diff_tuplesdk4?DKHHr<r%c|jSr@)rr8s r: to_columnzAddColumnOp.to_columns {r<colcF||jj||jjSr^)r rrs)r[rs r: from_columnzAddColumnOp.from_columns"s39>3sy/?@@@@r<rc||||Sr^r7r[rsrrs r:rz%AddColumnOp.from_column_and_tablenamess5#f----r<rrcH||||}||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 :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`. rr)r[rrwrrsrs r:rzAddColumnOp.add_columns/nSVF 3 3 3  $$$r<)rrrrrci}|r||d<|r||d<||jj|fd|jji|}||S)zIssue an "add column" instruction using the current batch migration context. .. seealso:: :meth:`.Operations.add_column` rrrsr)r[rrrrrrs r:rzAddColumnOp.batch_add_columnIs}$  0"/B   .!-B~  S O &   ?)       $$$r<) rwrTrrrsrxrrr>rz)r>rr>r)r>r%)rr%r>r)rsrxrrTrrr>r) rrrwrTrrrsrxr>rz) rrrrrrxrrxr>rz)rHrIrJrKr|rCrGrrnrrrrrbrcs@r:rrs@-,!%            IIII AAA[A...[.!% W%W%W%W%W%[W%r (,&* %%%%%[%%%%%r<r drop_columnbatch_drop_columnceZdZdZdddd"fdZd#dZd$dZed%dZ d&d'dZ eddd(dZ ed)d!Z xZ S)*rz"Represent a drop column operation.NrrrwrTrrsrxrtOptional[AddColumnOp]rrr>rzc xt||||_||_||_dSr^)r_r|rrrt)r9rwrrsrtrr`s r:r|zDropColumnOp.__init__os< F333&  r<rcFd|j|j|fS)N remove_column)rsrwrr8s r:rGzDropColumnOp.to_diff_tuple}s(  K O NN     r<rc|jtdt|j|j|jjS)Nz;operation is not reversible; original column is not present)rtrrrrsrwrr8s r:rCzDropColumnOp.reversesK = 1  44 K$-*>   r<rrrc ^|||j|t|||S)Nrr)rrrrs r:rz&DropColumnOp.from_column_and_tablenames=s  H ::65#NN     r<rbrcr%c|j |jjStj|}||jt Sr@)rtrrrrrrs r:rzDropColumnOp.to_columnsA = $=' ',->??   !18<< > >2 > >  $$$r<rc l||jj|fd|jji|}||S)zIssue a "drop column" instruction using the current batch migration context. .. seealso:: :meth:`.Operations.drop_column` rsr)r[rrrrs r:rzDropColumnOp.batch_drop_columnsTS O &   ?)       $$$r<) rwrTrrTrsrxrtrrrr>rzr)r>r)rsrxrrTrrr>rr@)rbrcr>r%) rrrwrTrrTrsrxrrr>rz)rrrrTrrr>rz) rHrIrJrKr|rGrCrnrrrrrbrcs@r:rrjs-,!%*. ! ! ! ! ! ! ! !             [  ?C=====!% /%/%/%/%/%[/%b%%%[%%%%%r<r bulk_insertc>eZdZdZdddd ZeddddZdS) BulkInsertOpz"Represent a bulk insert operation.T multiinsertr Union[Table, TableClause]rows List[dict]rrr>rzc0||_||_||_dSr@)r rr)r9r rrs r:r|zBulkInsertOp.__init__s   &r<rrcL||||}||dS)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[rr rrrs r:rzBulkInsertOp.bulk_inserts5RS+ 6 6 6"r<N)r rrrrrr>rz) rrr rrrrrr>rz)rHrIrJrKr|rnrr7r<r:rrst,,! ' ' ' ' ' '! iiiii[iiir<rexecute batch_executec\eZdZdZdddd ZeddddZeddddZdS) ExecuteSQLOpz#Represent an execute SQL operation.Nexecution_optionsr&Union[Update, str, Insert, TextClause]rOptional[dict[str, Any]]r>rzc"||_||_dSr@)rr)r9rrs r:r|zExecuteSQLOp.__init__p s  !2r<rrUnion[str, TextClause, Update]cF|||}||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 coerceed 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`, :func:`sqlalchemy.sql.expression.insert`, or :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.executey s.rS,= > > >  $$$r<c2||||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<)rrrrr>rz)rrrrrrr>rz)rHrIrJrKr|rnrrr7r<r:rrk s.- 7; 333333 7; Y%Y%Y%Y%Y%[Y%v 7;      [   r<rcDeZdZdZdddZdd Zdd ZeddZdS) OpContainerz-Represent a sequence of operations operation.r7opsSequence[MigrateOperation]r>rzc.t||_dSr@)r<r)r9rs r:r|zOpContainer.__init__ s99r<rc|j Sr@rr8s r:is_emptyzOpContainer.is_empty s 8|r<rcPtt|Sr@)r<r _ops_as_diffsr8s r:as_diffszOpContainer.as_diffs sK--d33444r< migrationsIterator[Tuple[Any, ...]]c#K|jD]R}t|dr*|td|Ed{V<|VSdS)Nrr)rhasattrrrrG)r[rrs r:rzOpContainer._ops_as_diffs s. ) )Br5!! ),,T--D-DEEEEEEEEEE&&((((((  ) )r<N)r7)rrr>rzrr)rrr>r) rHrIrJrKr|rrrnrr7r<r:rr s{775555)))[)))r<rc2eZdZdZdddfd Zdd ZxZS)ModifyTableOpszCContains a sequence of operations that all apply to a single Table.NrrwrTrrrsrxr>rzcft|||_||_dSr@)r_r|rwrs)r9rwrrsr`s r:r|zModifyTableOps.__init__ s/ $ r<c t|jttd|jD|jS)Nc6g|]}|Sr7rCrrs r:rz*ModifyTableOps.reverse.. ???rzz||???r<)rrs)rrwr<reversedrrsr8s r:rCzModifyTableOps.reverse sG OX??dh???@@AA;    r<)rwrTrrrsrxr>rz)r>rrHrIrJrKr|rCrbrcs@r:rr sfMM!%                r<rc:eZdZdZ ddfd Zdd ZddZxZS) UpgradeOpszcontains a sequence of operations that would apply to the 'upgrade' stream of a script. .. seealso:: :ref:`customizing_revision` r7upgradesrr upgrade_tokenrTr>rzcZt|||_dSNr)r_r|r)r9rrr`s r:r|zUpgradeOps.__init__ s. S!!!*r< downgrade_ops DowngradeOpscpttd|jD|jdd<|S)Nc6g|]}|Sr7rrs r:rz+UpgradeOps.reverse_into..* s 666rbjjll666r<)r<rr)r9rs r: reverse_intozUpgradeOps.reverse_into( sA# 66TX666 7 7  !!!r<cH|tgSr)r rr8s r:rCzUpgradeOps.reverse. s!  "!5!5!5666r<)r7r)rrrrTr>rz)rrr>r)r>r)rHrIrJrKr|r rCrbrcs@r:rr s|+-'+++++++ 77777777r<rc0eZdZdZ d d fd Zd ZxZS)rzcontains a sequence of operations that would apply to the 'downgrade' stream of a script. .. seealso:: :ref:`customizing_revision` r7 downgradesrrdowngrade_tokenrTr>rzcZt|||_dSr)r_r|r)r9rrr`s r:r|zDowngradeOps.__init__< s. S!!!.r<cttttd|jDS)Nc6g|]}|Sr7rrs r:rz(DowngradeOps.reverse..F rr<r)rr<rrr8s r:rCzDowngradeOps.reverseD s=X??dh???@@AA    r<)r7r)rrrrTr>rzrrcs@r:rr2 sc+-+///////       r<rceZdZUdZded<deddddddd dZedZej dZedZ e j dZ ed!dZ ed"dZ dS)#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_renderN)messageimportsheadsplice branch_label version_path depends_onrev_idrx upgrade_opsrrrrrSet[str]rrrrr#Optional[Union[str, Sequence[str]]]r>rzc||_||_||_||_||_||_| |_| |_||_||_ dSr@) rrrrrrrrrr) r9rrrrrrrrrrs r:r|zMigrationScript.__init__d sT     (($&*r<c|t|jdkrtd|jsdS|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)len _upgrade_opsrr8s r:rzMigrationScript.upgrade_ops} sQ t ! !A % %.  " (4$Q' 'r<cztj||_|jD]}t|tsJdSr@)rto_listr$ isinstancer)r9relems r:rzMigrationScript.upgrade_ops sI L55% 0 0DdJ// / // / 0 0r<c|t|jdkrtd|jsdS|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)r#_downgrade_opsrr8s r:rzMigrationScript.downgrade_ops sQ t" # #a ' '0  $ *4&q) )r<cztj||_|jD]}t|tsJdSr@)rr&r*r'r)r9rr(s r:rzMigrationScript.downgrade_ops sI"l=99' 2 2DdL11 1 11 1 2 2r<List[UpgradeOps]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. )r$r8s r:upgrade_ops_listz MigrationScript.upgrade_ops_list s   r<List[DowngradeOps]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. )r*r8s r:downgrade_ops_listz"MigrationScript.downgrade_ops_list s ""r<)rrxrrrrrrxrrrrxrrrrxrrxrr r>rz)r>r,)r>r/) rHrIrJrKrNsetr|rmrsetterrr.r1r7r<r:rrJ s."!!!"&CEE"!%&*&*:>++++++2((X($000 **X*$222 !!!X!###X###r<r)Y __future__rabcrrtypingrrrrr r r r r rrrrrsqlalchemy.typesrrbaserrrrrsqlalchemy.sql.dmlrrsqlalchemy.sql.elementsrrr r!r"sqlalchemy.sql.functionsr#sqlalchemy.sql.schemar$r%r&r'r(r)r*r+r,r-r.r/sqlalchemy.sql.selectabler0sqlalchemy.sql.type_apir1autogenerate.rewriterr2runtime.migrationr3r5rPregister_operationrfr]rrrrrrr(r1rVrZrgrqrrrrrrrrrrr7r<r:rCs/ """""" !!!!!! %%%%%%!!!!!!5))))))))))))888888555555,,,,,,333333222222111111555555,,,,,,......000000::::::......++++++......::::::000000++++++666666555555222222000000444444""""""""@!8!8!8!8!8&!8!8!8H011##$57NOOs%s%s%s%s%'s%s%PO21s%l344##4(()ABBt%t%t%t%t%t%t%CB54 t%n9::## @(()<==@%@%@%@%@%@%@%>=;: @%F344##4(()ABBY%Y%Y%Y%Y%Y%Y%CB54 Y%x899##>(();<<(()KLL(()BCC%%%%%o%%DCML=<:9%D~..##N4HIII%I%I%I%I%$I%I%JI/.I%X|,,##L2DEEg%g%g%g%g%"g%g%FE-,g%T~..^%^%^%^%^%$^%^%/.^%B|,,]]]]]"]]-,]@     #   ~..!%!%!%!%!%L!%!%/.!%H566##8lMlMlMlMlM<lMlM76lM^344##4P9P9P9P9P9P9P954P9f~..##N4HIIb&b&b&b&b&Lb&b&JI/.b&J |,,##L2DEEa%a%a%a%a%,a%a%FE-,a%H}--##M3FGG@%@%@%@%@%<@%@%HG.-@%F}--xxxxx#xx.-xvy))##I??y y y y y #y y @?*)y x)))))"))).     [   ,777777778     ;   0y#y#y#y#y#&y#y#y#y#y#r<