>il'NddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z dd lm Z dd l m Z dd l mZe r6dd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZGddZdS)) annotations)Any)Callable)Iterator)List)Optional)Type) TYPE_CHECKING)Union)util)ops) AddColumnOp) AlterColumnOp) CreateTableOp)MigrateOperation)MigrationScript)ModifyTableOps) OpContainer)MigrationContext)RevisioncXeZdZUdZejZdZded<d"dZ d#d Z d$d Z d%dZ d&dZ eejd'dZeejd(dZeejd)dZd*dZd+d Zd&d!ZdS),Rewritera5A helper object that allows easy 'rewriting' of ops streams. The :class:`.Rewriter` object is intended to be passed along to the :paramref:`.EnvironmentContext.configure.process_revision_directives` parameter in an ``env.py`` script. Once constructed, any number of "rewrites" functions can be associated with it, which will be given the opportunity to modify the structure without having to have explicit knowledge of the overall structure. The function is passed the :class:`.MigrationContext` object and ``revision`` tuple that are passed to the :paramref:`.Environment Context.configure.process_revision_directives` function normally, and the third argument is an individual directive of the type noted in the decorator. The function has the choice of returning a single op directive, which normally can be the directive that was actually passed, or a new directive to replace it, or a list of zero or more directives to replace it. .. seealso:: :ref:`autogen_rewriter` - usage example NzOptional[Rewriter]_chainedreturnNonec6tj|_dSN)r Dispatcherdispatch)selfs /srv/buildsys-work-dir/castor/build_node/builder-2/WGSG1/unpkd_srcs/cloudlinux-venv-1.0.6/venv/lib/python3.11/site-packages/alembic/autogenerate/rewriter.py__init__zRewriter.__init__9s)) otherc|j|j}|j|j||_|S)aProduce a "chain" of this :class:`.Rewriter` to another. This allows two rewriters to operate serially on a stream, e.g.:: writer1 = autogenerate.Rewriter() writer2 = autogenerate.Rewriter() @writer1.rewrites(ops.AddColumnOp) def add_column_nullable(context, revision, op): op.column.nullable = True return op @writer2.rewrites(ops.AddColumnOp) def add_column_idx(context, revision, op): idx_op = ops.CreateIndexOp( "ixc", op.table_name, [op.column.name] ) return [op, idx_op] writer = writer1.chain(writer2) :param other: a :class:`.Rewriter` instance :return: a new :class:`.Rewriter` that will run the operations of this writer, then the "other" writer, in succession. ) __class____new____dict__updater)r r$wrs r!chainzRewriter.chain<s?<^ # #DN 3 3 4=)))  r#operatorpUnion[Type[AddColumnOp], Type[MigrateOperation], Type[AlterColumnOp], Type[CreateTableOp], Type[ModifyTableOps]]rc6|j|S)aRegister a function as rewriter for a given type. The function should receive three arguments, which are the :class:`.MigrationContext`, a ``revision`` tuple, and an op directive of the type indicated. E.g.:: @writer1.rewrites(ops.AddColumnOp) def add_column_nullable(context, revision, op): op.column.nullable = True return op )r dispatch_for)r r,s r!rewriteszRewriter.rewrites_s,}))(333r#contextrrevisionr directiverIterator[MigrateOperation]c#K |j|}||jvr|VdStj||||gD]&}|j|g|_|V'dS#t $r d}|VYdSwxYwr)r _mutationsr to_listunion ValueError)r r1r2r3 _rewriter r_directives r!_rewritezRewriter._rewritews  & ..y99I y+++#'<Igx;;R$$&&K.9-C-I-I..K*&%%%% &&   IOOOOOO sA66B  B  directivesList[MigrationScript]ct|||||jr||||dSdSr)process_revision_directivesrr r1r2r=s r!__call__zRewriter.__call__sL (((JGGG = 9 MM'8Z 8 8 8 8 8 9 9r#rcg}|jD]V}||||}t|dkrtd||dW||_g}|jD]V}||||}t|dkrtd||dW||_dS)Nz5Can only return single object for UpgradeOps traverserz7Can only return single object for DowngradeOps traverse)upgrade_ops_list _traverse_forlenr9append upgrade_opsdowngrade_ops_list downgrade_ops) r r1r2r3rErIretrJrKs r!_traverse_scriptzRewriter._traverse_scripts$5 , ,K$$Wh DDC3xx1}} K  # #CF + + + + 0 &9 . .M$$Wh FFC3xx1}} M  % %c!f - - - -"4 r#rc>||||jdSr)_traverse_listr r r1r2r3s r!_traverse_op_containerzRewriter._traverse_op_containers$ GXy}=====r#cdSrrPs r!_traverse_any_directivez Rewriter._traverse_any_directives  r#rct||||}|D]*}|j|}|||||+|Sr)listr< _traverser)r r1r2r3r= traversers r!rFzRewriter._traverse_forsd $--9EEFF # : :I// ::I IdGXy 9 9 9 9r#cvg}|D],}|||||-||dd<dSr)extendrF)r r1r2r=destr3s r!rOzRewriter._traverse_listsR # J JI KK**7HiHH I I I I 111 r#c4||||dSr)rOrAs r!r@z$Rewriter.process_revision_directivess" GXz:::::r#)rr)r$rrr)r,r-rr)r1rr2rr3rrr4)r1rr2rr=r>rr)r1rr2rr3rrr)r1rr2rr3rrr)r1rr2rr3rrr)r1rr2rr3rrr)r1rr2rr=rrr)__name__ __module__ __qualname____doc__r rrWr__annotations__r"r+r0r<rBr/r rrMrrQrrTrFrOr@rSr#r!rrsx2 !!I#'H''''****!!!!F44440&&&&.9999C/005551054CO,,>>>-,>C011   21         ;;;;;;r#rN) __future__rtypingrrrrrr r r alembicr alembic.operationsr alembic.operations.opsrrrrrrralembic.runtime.migrationralembic.script.revisionrrrSr#r!ris"""""" """""" 1222222444444444444777777666666555555222222::::::000000H;H;H;H;H;H;H;H;H;H;r#