� J�g���R�ddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z dd lm Z d d l m Z d d l mZe rBd d lmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZeddedgdfZGd�d��ZdS)�)� annotations)�Any)�Callable)�Iterator)�List)�Tuple)�Type)� TYPE_CHECKING)�Union�)�util)�ops)� AddColumnOp)� AlterColumnOp)� CreateTableOp)� DowngradeOps)�MigrateOperation)�MigrationScript)�ModifyTableOps)� OpContainer)� UpgradeOps)�MigrationContext)� _GetRevArgrrrNc�X�eZdZUdZej��ZdZded<d$d�Z d%d �Z d&d�Z d'd�Z d(d�Z e�ej��d)d���Ze�ej��d*d���Ze�ej��d+d���Zd,d �Zd-d!�Zd(d"�Zd#S).�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 �z7Tuple[Union[ProcessRevisionDirectiveFn, Rewriter], ...]�_chained�return�Nonec�6�tj��|_dS�N)r � Dispatcher�dispatch)�selfs �m/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/alembic/autogenerate/rewriter.py�__init__zRewriter.__init__?s����)�)�� � � ��other�+Union[ProcessRevisionDirectiveFn, Rewriter]c��|j�|j��}|j�|j��|xj|fz c_|S)a�Produce a "chain" of this :class:`.Rewriter` to another. This allows two or more 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.chainBsK��H�^� #� #�D�N� 3� 3�� � ���4�=�)�)�)� � � ��x�� � �� r'�operator�pUnion[Type[AddColumnOp], Type[MigrateOperation], Type[AlterColumnOp], Type[CreateTableOp], Type[ModifyTableOps]]�Callable[..., Any]c�6�|j�|��S)a�Register 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$r1s r%�rewriteszRewriter.rewritesks��,�}�)�)�(�3�3�3r'�contextr�revisionr� directiver�Iterator[MigrateOperation]c#�K� |j�|��}||jvr|V�dStj||||��g��D]&}|j�|g��|_|V��'dS#t $r d}|V�YdSwxYwr!)r#� _mutationsr �to_list�union� ValueError)r$r7r8r9� _rewriter� r_directives r%�_rewritezRewriter._rewrite�s�����  &�� �.�.�y�9�9�I� �y�+�+�+�������#'�<��I�g�x��;�;�R�$�$�&�&�K�.9�-C�-I�-I���.�.�K�*�&�%�%�%�%� &�&��� � � ��I��O�O�O�O�O�O� ���s�A6�6B � B � directives�List[MigrationScript]c�b�|�|||��|jD]}||||���dSr!)�process_revision_directivesr)r$r7r8rCrFs r%�__call__zRewriter.__call__�sT�� �(�(��(�J�G�G�G�+/�=� G� G� '� '� '���:� F� F� F� F� G� Gr'rc��g}|jD]V}|�|||��}t|��dkrtd���|�|d���W||_g}|jD]V}|�|||��}t|��dkrtd���|�|d���W||_dS)N�z5Can only return single object for UpgradeOps traverserz7Can only return single object for DowngradeOps traverse)�upgrade_ops_list� _traverse_for�lenr?�append� upgrade_ops�downgrade_ops_list� downgrade_ops) r$r7r8r9rJrN�retrOrPs r%�_traverse_scriptzRewriter._traverse_script�s���.0��$�5� ,� ,�K��$�$�W�h� �D�D�C��3�x�x�1�}�}� �K���� � #� #�C��F� +� +� +� +� 0� ��13��&�9� .� .�M��$�$�W�h� �F�F�C��3�x�x�1�}�}� �M���� � %� %�c�!�f� -� -� -� -�"4� ���r'rc�>�|�|||j��dSr!)�_traverse_listr�r$r7r8r9s r%�_traverse_op_containerzRewriter._traverse_op_container�s$�� ���G�X�y�}�=�=�=�=�=r'c��dSr!rrUs r%�_traverse_any_directivez Rewriter._traverse_any_directive�s �� �r'rc��t|�|||����}|D]*}|j�|��}|||||���+|Sr!)�listrB� _traverser#)r$r7r8r9rC� traversers r%rKzRewriter._traverse_for�sd�� �$�-�-���9�E�E�F�F� �#� :� :�I���/�/� �:�:�I� �I�d�G�X�y� 9� 9� 9� 9��r'c�v�g}|D],}|�|�|||�����-||dd�<dSr!)�extendrK)r$r7r8rC�destr9s r%rTzRewriter._traverse_list�sR�� ��#� J� J�I� �K�K��*�*�7�H�i�H�H� I� I� I� I�� �1�1�1� � � r'c�4�|�|||��dSr!)rT)r$r7r8rCs r%rFz$Rewriter.process_revision_directives�s"�� ���G�X�z�:�:�:�:�:r'N)rr)r(r)rr)r1r2rr3)r7rr8rr9rrr:)r7rr8rrCrDrr)r7rr8rr9rrr)r7rr8rr9rrr)r7rr8rr9rrr)r7rr8rr9rrr)r7rr8rrCrrr)�__name__� __module__� __qualname__�__doc__r r"r[r�__annotations__r&r0r6rBrGr5rrrRrrVrrXrKrTrFrr'r%rr!s|���������2 ���!�!�I�HJ�H�J�J�J�J�*�*�*�*�'�'�'�'�R4�4�4�4�0&�&�&�&�.G�G�G�G����C�/�0�0�5�5�5�1�0�5�6���C�O�,�,�>�>�>�-�,�>����C�0�1�1� � � �2�1� � � � � � � � � �;�;�;�;�;�;r'r)� __future__r�typingrrrrrr r r �r � operationsr�operations.opsrrrrrrrrr�runtime.migrationr�script.revisionr�ProcessRevisionDirectiveFnrrr'r%�<module>rns���"�"�"�"�"�"������������������������������������� � � � � � �������������������� -�,�,�,�,�,�,�.�.�.�.�.�.�.�.�.�.�.�.�-�-�-�-�-�-�1�1�1�1�1�1�0�0�0�0�0�0�/�/�/�/�/�/�,�,�,�,�,�,�+�+�+�+�+�+�4�4�4�4�4�4�,�,�,�,�,�,�%���t�,=�'>�?��E��� O;�O;�O;�O;�O;�O;�O;�O;�O;�O;r'
Memory