� J�g������ddlmZddlmZddlmZddlZddlZddlmZddlm Z ddlm Z ddlm Z dd lm Z dd lm Z dd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddl!m"Z"ddl#m$Z$ddl%m&Z&erNddlm'Z'ddlm(Z(dd l)m*Z*dd!l)m+Z+dd"l,m-Z-dd#l.m/Z/d$d%l0m1Z1dd&l2m3Z3dd'l4m5Z5dd(l4m6Z6dd)l7m8Z8dd*l7m9Z9dd+l7m:Z:ej;e<��Z=Gd,�d-��Z>Gd.�d/��Z?Gd0�d1��Z@Gd2�d3��ZAGd4�d5��ZBGd6�d7eB��ZCGd8�d9eB��ZDdS):�)� annotations)�contextmanager)� nullcontextN)�Any)�Callable)�cast)� Collection)�ContextManager)�Dict)�Iterable)�Iterator)�List)�Optional)�Set)�Tuple)� TYPE_CHECKING)�Union)�Column)�literal_column)�Engine)�url)�MockEngineStrategy�)�ddl)�util)� sqla_compat)� EncodedIO)�_select)�Dialect)�URL)� Connection)� Transaction)�MockConnection)� Executable�)�EnvironmentContext)�Config)�Script)�ScriptDirectory)�_RevisionOrBase)�Revision)� RevisionMapc�N�eZdZdd�Zedd���Zdd�Zdd �Zdd �Zdd�Z dS)�_ProxyTransaction�migration_context�MigrationContext�return�Nonec��||_dS�N)r/)�selfr/s �i/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/alembic/runtime/migration.py�__init__z_ProxyTransaction.__init__9s��!2������Optional[Transaction]c��|jjSr4)r/� _transaction�r5s r6�_proxied_transactionz&_ProxyTransaction._proxied_transaction<s���%�2�2r8c�\�|j}|�J�|���d|j_dSr4)r=�rollbackr/r;�r5�ts r6r?z_ProxyTransaction.rollback@s1�� � %���}�}�}� � � � � � �.2���+�+�+r8c�\�|j}|�J�|���d|j_dSr4)r=�commitr/r;r@s r6rCz_ProxyTransaction.commitFs1�� � %���}�}�}� ��� � � �.2���+�+�+r8c��|Sr4�r<s r6� __enter__z_ProxyTransaction.__enter__Ls��� r8�type_r�value� tracebackc�h�|j�*|j�|||��d|j_dSdSr4)r=�__exit__r/r;)r5rGrHrIs r6rKz_ProxyTransaction.__exit__Os?�� � $� 0� � %� .� .�u�e�Y� G� G� G�26�D� "� /� /� /� 1� 0r8N)r/r0r1r2)r1r9)r1r2)r1r.)rGrrHrrIrr1r2) �__name__� __module__� __qualname__r7�propertyr=r?rCrFrKrEr8r6r.r.8s�������3�3�3�3��3�3�3��X�3�3�3�3�3� 3�3�3�3� ����7�7�7�7�7�7r8r.c���eZdZdZ d?d@d �Ze dAdBd���ZedCd���Z dDdEd�Z dFd�Z dGd �Z dDdHd"�Z dId#�Z dJd(�ZdKd+�ZdId,�Z d?dLd1�ZdMd3�ZedNd4���ZedOd6���ZdPd;�ZdQd>�ZdS)Rr0a�Represent the database state made available to a migration script. :class:`.MigrationContext` is the front end to an actual database connection, or alternatively a string output stream given a particular database dialect, from an Alembic perspective. When inside the ``env.py`` script, the :class:`.MigrationContext` is available via the :meth:`.EnvironmentContext.get_context` method, which is available at ``alembic.context``:: # from within env.py script from alembic import context migration_context = context.get_context() For usage outside of an ``env.py`` script, such as for utility routines that want to check the current version in the database, the :meth:`.MigrationContext.configure` method to create new :class:`.MigrationContext` objects. For example, to get at the current revision in the database using :meth:`.MigrationContext.get_current_revision`:: # in any application, outside of an env.py script from alembic.migration import MigrationContext from sqlalchemy import create_engine engine = create_engine("postgresql://mydatabase") conn = engine.connect() context = MigrationContext.configure(conn) current_rev = context.get_current_revision() The above context can also be used to produce Alembic migration operations with an :class:`.Operations` instance:: # in any application, outside of the normal Alembic environment from alembic.operations import Operations op = Operations(context) op.alter_column("mytable", "somecolumn", nullable=True) N�dialectr� connection�Optional[Connection]�opts�Dict[str, Any]�environment_context�Optional[EnvironmentContext]r1r2c�(�||_||_||_|�d��|_|�dd��}|�d��}|�dd��|_|�dd��|_d|_|rDttd|� |����|_ |j �J�d|_ n ||_ tj|��|_ |�d ��|_||_|�d d��|_d |vr;t%|�d ��p t&j|d ��|_n%|�d t&j��|_|�d d��|_|�dd��|_|�dd��x|_}|�dd��x|_}|�d��|_t7j�|��||j |j||j|��|_|j�|||�dd�����|_ tB�"d|jj#j$��|jrtB�"d��tB�"d|jj%rdnd��dS)N�script�as_sqlF�transactional_ddl�transaction_per_migration�on_version_applyrEr!�fn�purge�output_encoding� output_buffer� compare_typeT�compare_server_default� version_table�alembic_version�version_table_schema� starting_rev�version_table_pk)rdrfrhzContext impl %s.zGenerating static SQLzWill assume %s DDL.� transactionalznon-transactional)&rVrTrQ�getrY�_transaction_per_migration�on_version_apply_callbacksr;rr�_stdout_connectionrR�_in_external_transactionr�_get_connection_in_transaction�_migrations_fnrZr_r�sys�stdoutra�_user_compare_type�_user_compare_server_defaultrdrf�_start_from_revr� DefaultImpl�get_by_dialect�impl�version_table_impl�_version�log�info� __class__rLr[) r5rQrRrTrVrZr[rdrfs r6r7zMigrationContext.__init__�s��$7�� ��� ��� �15���(�1C�1C�� ��x�x��%�0�0�� �H�H�%8�9�9��*.�(�(� '��+ �+ ��'�+/�(�(�3E�r�*J�*J��'�37��� � �"���&��(?�(?� �(K�(K���D�O��?�.�.�.�,1�D� )� )�(�D�O��:�:�F�F� � )� �H�H�T�N�N� ���� ��X�X�g�u�-�-�� � �� $� $�!*�����)�)���:��&�'�"�"�D� � � "&���/�3�:�!F�!F�D� �"&�(�(�>�4�"@�"@���,0�H�H� $�e�- �- ��)�.2�X�X� �.�. �. � ���]�<@�8�8� "�D�< �< � ��!�$8�/3�h�h�~�.F�.F����O�2�2�7�;�;� � �O� �K� � � � �  � �� �� �4�4�'�!5�!�X�X�&8�$�?�?�5� � �� � ���#�T�Y�%8�%A�B�B�B� �;� .� �H�H�,� -� -� -� ��� !��9�.�)���(�  � � � � r8r�Optional[Union[str, URL]]� dialect_name� Optional[str]�Optional[Dialect]� dialect_opts�Optional[Dict[str, str]]� Optional[Any]c��|�i}|�i}|r4t|t��rtjd|z���|j}nv|r/t j|��}|���di|��}nE|r2t jd|z��}|���di|��}n|std���|�J�t||||��S)a�Create a new :class:`.MigrationContext`. This is a factory method usually called by :meth:`.EnvironmentContext.configure`. :param connection: a :class:`~sqlalchemy.engine.Connection` to use for SQL execution in "online" mode. When present, is also used to determine the type of dialect in use. :param url: a string database url, or a :class:`sqlalchemy.engine.url.URL` object. The type of dialect to be used will be derived from this if ``connection`` is not passed. :param dialect_name: string name of a dialect, such as "postgresql", "mssql", etc. The type of dialect to be used will be derived from this if ``connection`` and ``url`` are not passed. :param opts: dictionary of options. Most other options accepted by :meth:`.EnvironmentContext.configure` are passed via this dictionary. Nzf'connection' argument to configure() is expected to be a sqlalchemy.engine.Connection instance, got %rz%s://z-Connection, url, or dialect_name is required.rE) � isinstancerr� CommandErrorrQ�sqla_url�make_url� get_dialect� Exceptionr0) �clsrRrrrQrVr�rT�url_objs r6� configurezMigrationContext.configure�s��> �<��D� � ��L� � M��*�f�-�-� ��'��)�*���� !�(�G�G� � M��'��,�,�G�+�g�)�)�+�+�;�;�l�;�;�G�G� � M��'��,�(>�?�?�G�+�g�)�)�+�+�;�;�l�;�;�G�G�� M��K�L�L� L��"�"�"����T�;N�O�O�Or8�Iterator[None]c#�K�|���}|jjr!|jr|j���n+|r)|j�J�|j���d|_|jsj|j�J�|j���}|j}|� d���x|_|j_|j� ��}nd} dV�|jsM|j�J�|�|���|j� |���|x|_|j_|jjr"|jr|j� ��dS|r)|j�J�|j� ��|_dSdS#|jsM|j�J�|�|���|j� |���|x|_|j_|jjr!|jr|j� ��n)|r'|j�J�|j� ��|_wxYw)aLEnter an "autocommit" block, for databases that support AUTOCOMMIT isolation levels. This special directive is intended to support the occasional database DDL or system operation that specifically has to be run outside of any kind of transaction block. The PostgreSQL database platform is the most common target for this style of operation, as many of its DDL operations must be run outside of transaction blocks, even though the database overall supports transactional DDL. The method is used as a context manager within a migration script, by calling on :meth:`.Operations.get_context` to retrieve the :class:`.MigrationContext`, then invoking :meth:`.MigrationContext.autocommit_block` using the ``with:`` statement:: def upgrade(): with op.get_context().autocommit_block(): op.execute("ALTER TYPE mood ADD VALUE 'soso'") Above, a PostgreSQL "ALTER TYPE..ADD VALUE" directive is emitted, which must be run outside of a transaction block at the database level. The :meth:`.MigrationContext.autocommit_block` method makes use of the SQLAlchemy ``AUTOCOMMIT`` isolation level setting, which against the psycogp2 DBAPI corresponds to the ``connection.autocommit`` setting, to ensure that the database driver is not inside of a DBAPI level transaction block. .. warning:: As is necessary, **the database transaction preceding the block is unconditionally committed**. This means that the run of migrations preceding the operation will be committed, before the overall migration operation is complete. It is recommended that when an application includes migrations with "autocommit" blocks, that :paramref:`.EnvironmentContext.transaction_per_migration` be used so that the calling environment is tuned to expect short per-file migrations whether or not one of them has an autocommit block. N� AUTOCOMMIT)�isolation_level) �_in_connection_transactionrxr[rZ� emit_commitr;rCrR�get_isolation_level�execution_options�begin� emit_begin)r5r�� current_level�base_connection� fake_transs r6�autocommit_blockz!MigrationContext.autocommit_blocks�����Z&*�%D�%D�%F�%F�"� �9� &� %�4�;� %� �I� !� !� #� #� #� #� '� %��$�0�0�0� � � $� $� &� &� &� $�D� ��{� ��?�.�.�.� �O�?�?�A�A�M�"�o�O� �1�1�,�1�O�O� �D�O�d�i�2� 15��0E�0E�0G�0G�J�J��J� <� �E�E�E��;� I���2�2�2��)��%�%�'�'�'���1�1�$1�2����:I�H���$�)�"6��y�*� <�t�{� <�� �$�$�&�&�&�&�&�+� <���2�2�2�$(�O�$9�$9�$;�$;��!�!�!� <� <���;� I���2�2�2��)��%�%�'�'�'���1�1�$1�2����:I�H���$�)�"6��y�*� <�t�{� <�� �$�$�&�&�&�&�+� <���2�2�2�$(�O�$9�$9�$;�$;��!�;�;�;�;s �#F�B,IF�_per_migration�bool�.Union[_ProxyTransaction, ContextManager[None]]c� ���jrt��S�jjr |�jk}n|du}|st��S�jjsh|sJ��jrt��S�jdu}|rt��S�j�J�tj �j���_t���S�jrt�fd���}|��S�j�J�tj �j���_t���S)a�Begin a logical transaction for migration operations. This method is used within an ``env.py`` script to demarcate where the outer "transaction" for a series of migrations begins. Example:: def run_migrations_online(): connectable = create_engine(...) with connectable.connect() as connection: context.configure( connection=connection, target_metadata=target_metadata ) with context.begin_transaction(): context.run_migrations() Above, :meth:`.MigrationContext.begin_transaction` is used to demarcate where the outer logical transaction occurs around the :meth:`.MigrationContext.run_migrations` operation. A "Logical" transaction means that the operation may or may not correspond to a real database transaction. If the target database supports transactional DDL (or :paramref:`.EnvironmentContext.configure.transactional_ddl` is true), the :paramref:`.EnvironmentContext.configure.transaction_per_migration` flag is not set, and the migration is against a real database connection (as opposed to using "offline" ``--sql`` mode), a real transaction will be started. If ``--sql`` mode is in effect, the operation would instead correspond to a string such as "BEGIN" being emitted to the string output. The returned object is a Python context manager that should only be used in the context of a ``with:`` statement as indicated above. The object has no other guaranteed API features present. .. seealso:: :meth:`.MigrationContext.autocommit_block` TNc3�x�K��j���dV��j���dSr4)rxr�r�r<s�r6� begin_commitz8MigrationContext.begin_transaction.<locals>.begin_commit�s>������ �$�$�&�&�&������ �%�%�'�'�'�'�'r8) rnrrxr[rkrZr;rRr�"_safe_begin_connection_transactionr.r)r5r��transaction_now�in_transactionr�s` r6�begin_transactionz"MigrationContext.begin_transactionqsN���X � (� !��=�=� � �9� &� 5�,��0O�O�O�O�,��4�O��. +��=�=� ���,�+ +�!� !� !�>��{� 3�"�}�}�$�"&�!2�$�!>��!� 3�&�=�=�(��?�6�6�6�#�F� �O����%� -�T�2�2�2� �[� +� � (� (� (� (��^� (�  �<�>�>� !��?�.�.�.� +� N���!�!�D� �%�T�*�*� *r8c���|���}t|��dkrdSt|��dkrtjd|jz���|dS)a�Return the current revision, usually that which is present in the ``alembic_version`` table in the database. This method intends to be used only for a migration stream that does not contain unmerged branches in the target database; if there are multiple branches present, an exception is raised. The :meth:`.MigrationContext.get_current_heads` should be preferred over this method going forward in order to be compatible with branch migration support. If this :class:`.MigrationContext` was configured in "offline" mode, that is with ``as_sql=True``, the ``starting_rev`` parameter is returned instead, if any. rNr%zQVersion table '%s' has more than one head present; please use get_current_heads())�get_current_heads�lenrr�rd�r5�headss r6�get_current_revisionz%MigrationContext.get_current_revision�si�� �&�&�(�(�� �u�:�:��?�?��4� ��Z�Z�!�^�^��#�1�37�3E�F��� � ��8�Or8�Tuple[str, ...]c����jrO�j}|dkrd}n)|�'�jr �fd�tj|��D��}tj|d���S�jrtjd�������sdS�j�J�td��j� t�j j j����D����S)a�Return a tuple of the current 'head versions' that are represented in the target database. For a migration stream without branches, this will be a single value, synonymous with that of :meth:`.MigrationContext.get_current_revision`. However when multiple unmerged branches exist within the target database, the returned tuple will contain a value for each head. If this :class:`.MigrationContext` was configured in "offline" mode, that is with ``as_sql=True``, the ``starting_rev`` parameter is returned in a one-length tuple. If no version table is present, or if there are no revisions present, an empty tuple is returned. �baseNc�V��g|]%}|dv��j�|��j��&S))Nr�)rY� get_revision�revision)�.0�sfrr5s �r6� <listcomp>z6MigrationContext.get_current_heads.<locals>.<listcomp>sA���"�"�"���.�0�0��K�,�,�S�1�1�:�0�0�0r8rE��defaultzECan't specify current_rev to context when using a database connectionc3�&K�|] }|dV�� dS)rNrE)r��rows r6� <genexpr>z5MigrationContext.get_current_heads.<locals>.<genexpr>s:���� � �� ��F� � � � � � r8)rZrurYr�to_list�to_tupler��_has_version_tablerR�tuple�executerrz�c� version_num)r5�start_from_revs` r6r�z"MigrationContext.get_current_heads�s���$ �;� �"&�"6�N���'�'�!%����+�� �+�"�"�"�"�#�|�N�;�;�"�"�"�� �=���<�<�<� <��#� ��'�7�����*�*�,�,� ��r���*�*�*�� � ���.�.��� ��3�4�4��� � � � � � r8r_c�6�tj|j��5|j�J�|j�|jd���|r:|j�J�|j�|j�����ddd��dS#1swxYwYdS)NT)� checkfirst)r�_ensure_scope_for_ddlrRrz�creater��delete)r5r_s r6�_ensure_version_tablez&MigrationContext._ensure_version_tables��� � .�t�� ?� ?� @� @��?�.�.�.� �M� � ���T� � B� B� B�� @���2�2�2���'�'�� �(<�(<�(>�(>�?�?�?�  @� @� @� @� @� @� @� @� @� @� @� @���� @� @� @� @� @� @s�A'B�B�Bc�^�|j�J�tj|j|j|j��Sr4)rRr�_connectable_has_tablerdrfr<s r6r�z#MigrationContext._has_version_table%s4����*�*�*��1� �O�T�/��1J� � � r8�script_directoryr)r��strc���|���}|js|s|���t||��}|�||��D]}|�|���dS)a\Stamp the version table with a specific revision. This method calculates those branches to which the given revision can apply, and updates those branches as though they were migrated towards that revision (either up or down). If no current branches include the revision, it is added as a new branch head. N)r�rZr��HeadMaintainer� _stamp_revs�update_to_step)r5r�r�r��head_maintainer�steps r6�stampzMigrationContext.stamp+s����&�&�(�(���{� )�5� )� � &� &� (� (� (�(��u�5�5��$�0�0��5�A�A� 1� 1�D� � *� *�4� 0� 0� 0� 0� 1� 1r8�kwrc ��|j���|jr4|jrt jd���|�d���d}nN|���}|j� dd��}|js|s|s|���t||��}|j �J�|� ||��D]�}|� d���5|jr/|j s(|j�J�|j�|j��t"�d |��|jr"|j�d |j����|jdi|��|�|��|jD](}|||jt1|j ��|� ���) ddd��n #1swxYwY��|jr1|j s,|j�J�|j�|j��dSdSdS) a-Run the migration scripts established for this :class:`.MigrationContext`, if any. The commands in :mod:`alembic.command` will set up a function that is ultimately passed to the :class:`.MigrationContext` as the ``fn`` argument. This function represents the "work" that will be done when :meth:`.MigrationContext.run_migrations` is called, typically from within the ``env.py`` script of the migration environment. The "work function" then provides an iterable of version callables and other version information which in the case of the ``upgrade`` or ``downgrade`` commands are the list of version scripts to invoke. Other commands yield nothing, in the case that a command wants to run some other operation against the database such as the ``current`` or ``stamp`` commands. :param \**kw: keyword arguments here will be passed to each migration callable, that is the ``upgrade()`` or ``downgrade()`` method within revision scripts. z!Can't use --purge with --sql modeT)r_rE� dont_mutateFN)r�z Running %sz -- Running )�ctxr�r��run_args)rx�start_migrationsr_rZrr�r�r�rTrjr�rpr�r�rRrzr�r{r|� static_output� short_log� migration_fnr�rl�set�drop)r5r�r�r�r�r��callbacks r6�run_migrationszMigrationContext.run_migrations;s���* � �"�"�$�$�$� �:� -��{� M��'�(K�L�L�L� � &� &�T� &� 2� 2� 2��E�E��*�*�,�,�E��)�-�-� �u�=�=�K��;� -�u� -�[� -��*�*�,�,�,�(��u�5�5���"�.�.�.��'�'��t�4�4� � �D��'�'�t�'�<�<� � ��;�:��'<�:� �?�6�6�6��M�(�(���9�9�9�����t�,�,�,��;���I�+�+�+�+/�>�>�;����"��!�'�'�B�'�'�'� �.�.�t�4�4�4� $� ?���H��H� �!�Y�!�/�"7�8�8�!#� ������' � � � � � � � � � � ���� � � � ��6 �;� 0��4� 0��?�.�.�.� �M� � �t�� /� /� /� /� /� 0� 0� 0� 0s�*C G�G � G c�R� |jj}|��S#t$rYdSwxYw�NF)rRr��AttributeError)r5�meths r6r�z+MigrationContext._in_connection_transaction�sB�� ��?�1�D��4�6�6�M��� � � ��5�5� ���s � � &�&�sql�Union[Executable, str]r��Optional[Dict[str, Any]]c�<�|j�||��dS)aExecute a SQL construct or string statement. The underlying execution mechanics are used, that is if this is "offline mode" the SQL is written to the output buffer, otherwise the SQL is emitted on the current SQLAlchemy connection. N�rx�_exec)r5r�r�s r6r�zMigrationContext.execute�s!�� � ����.�/�/�/�/�/r8r#c�B���fd�}tj�j|��S)Nc�<���j�|��dSr4r�)� construct� multiparams�paramsr5s �r6�dumpz1MigrationContext._stdout_connection.<locals>.dump�s��� �I�O�O�I� &� &� &� &� &r8)rr#rQ)r5rRr�s` r6rmz#MigrationContext._stdout_connection�s3��� '� '� '� '� '�"�0���t�D�D�Dr8c��|jS)a�Return the current "bind". In online mode, this is an instance of :class:`sqlalchemy.engine.Connection`, and is suitable for ad-hoc execution of any kind of usage described in SQLAlchemy Core documentation as well as for usage with the :meth:`sqlalchemy.schema.Table.create` and :meth:`sqlalchemy.schema.MetaData.create_all` methods of :class:`~sqlalchemy.schema.Table`, :class:`~sqlalchemy.schema.MetaData`. Note that when "standard output" mode is enabled, this bind will be a "mock" connection handler that cannot return results and is only appropriate for a very limited subset of commands. )rRr<s r6�bindzMigrationContext.bind�s ��&��r8�Optional[Config]c�,�|jr |jjSdS)zLReturn the :class:`.Config` used by the current environment, if any.N)rV�configr<s r6r�zMigrationContext.config�s �� � #� ��+�2� 2��4r8�inspector_column� Column[Any]�metadata_columnrc���|jdurdSt|j��r'|�||||j|j��}|�|S|j�||��Sr�)rs�callable�typerxrb)r5r�r�� user_values r6� _compare_typezMigrationContext._compare_type�s{�� � "�e� +� +��5� �D�+� ,� ,� "��0�0�� �� �%��$� ��J��%�!�!��y�%�%�&6��H�H�Hr8�rendered_metadata_default�rendered_column_defaultc���|jdurdSt|j��r#|�|||||j|��}|�|S|j�||||��Sr�)rtr��server_defaultrxrc)r5r�r�r�r�r�s r6�_compare_server_defaultz(MigrationContext._compare_server_default�s��� � ,�� 5� 5��5� �D�5� 6� 6� "��:�:�� ��'��.�)� ��J��%�!�!��y�/�/� � � %� #�  � � r8r4) rQrrRrSrTrUrVrWr1r2)NNNNNNN)rRrSrr~rr�rQr�rVrWr�r�rTr�r1r0)r1r�)F)r�r�r1r��r1r��r1r�)r_r�r1r2�r1r�)r�r)r�r�r1r2�r�rr1r2)r�r�r�r�r1r2)rRrSr1r#)r1rS)r1r�)r�r�r�rr1r�) r�r�r�r�r�r�r�r�r1r�)rLrMrN�__doc__r7� classmethodr�rr�r�r�r�r�r�r�r�r�r�rmrOr�r�r�rrEr8r6r0r0Us ������-�-�h=A� T �T �T �T �T �l�,0�)-�&*�%)�<@�15�"�5P�5P�5P�5P��[�5P�n�[<�[<�[<��^�[<�|&+�b+�b+�b+�b+�b+�H����6+ �+ �+ �+ �Z@�@�@�@�@� � � � � 1�1�1�1� F0�F0�F0�F0�P����7;� 0� 0� 0� 0� 0�E�E�E�E������X��(�����X��I�I�I�I�& � � � � � r8r0c�6�eZdZdd�Zdd �Zdd �Zdd�Zdd�ZdS)r��contextr0r�rr1r2c�<�||_t|��|_dSr4)r r�r�)r5r r�s r6r7zHeadMaintainer.__init__�s���� ���Z�Z�� � � r8�versionr�c��||jvsJ�|j�|��|jj�|jj����td|z�������dS)N�'%s'�r�) r��addr rxr�rz�insert�valuesr)r5r s r6�_insert_versionzHeadMaintainer._insert_version�s����d�j�(�(�(�(� � ���w���� � ���� �L� !� (� (� *� *� 1� 1�*�6�G�+;�<�<� 2� � � � � � � r8c ���|j�|��|jj�|jj����|jjjj td|z��k����}|jj sG|jj j r8|�8|jdkr/tjd||jj|jfz���dSdSdSdS)Nrr%zOOnline migration expected to match one row when deleting '%s' in '%s'; %d found)r��remover rxr�rzr��wherer�r�rrZrQ�supports_sane_rowcount�rowcountrr�rd)r5r �rets r6�_delete_versionzHeadMaintainer._delete_versions�� � ���'�"�"�"��l��%�%� �L� !� (� (� *� *� 0� 0�� �%�'�3�!�&�7�"2�3�3�4� � � � ��� �#� �� �$�;� ���� ��!�!��#���D�L�6�� �E�F��� � � � � � ��!�!r8�from_�to_c �l�||jvsJ�|j�|��|j�|��|jj�|jj����td|z������ |jjj j td|z��k����}|jj sH|jjjr9|�9|jdkr0t#jd|||jj|jfz���dSdSdSdS)Nrrr%zWOnline migration expected to match one row when updating '%s' to '%s' in '%s'; %d found)r�rrr rxr�rz�updaterrrr�r�rZrQrrrr�rd)r5rrrs r6�_update_versionzHeadMaintainer._update_versionsB���$�*�$�$�$�$� � ���%� � � � � ���s�����l��%�%� �L� !� (� (� *� *� �V��v��|� <� <�V� =� =� �U�� �%�'�3�!�&�5�.�1�1�2��� � ��� �#� �� �$�;� ���� ��!�!��#���#�t�|�9�3�<�H�I��� � � � � � ��!�!r8r��Union[RevisionStep, StampStep]c� �|�|j��r9|j}t�d|��|�|��dS|�|j��r9|j}t�d|��|�|��dS|� |j��rm|� |j��\}}}t�d|||��|D]}|�|���|� ||��dS|� |j��rm|� |j��\}}}t�d|||��|D]}|�|���|� ||��dS|�|j��\} } t�d| | ��|� | | ��dS)Nzbranch delete %sznew branch insert %sz!merge, delete %s, update %s to %sz#unmerge, insert %s, update %s to %szupdate %s to %s)�should_delete_branchr��delete_version_numr{�debugr�should_create_branch�insert_version_numr�should_merge_branches�merge_branch_identsr�should_unmerge_branches�unmerge_branch_idents�update_version_num) r5r��vers� delete_revs�update_from_rev� update_to_rev�delrev� insert_revs�insrevrrs r6r�zHeadMaintainer.update_to_step3s.�� � $� $�T�Z� 0� 0�* -��*�D� �I�I�(�$� /� /� /� � � �� &� &� &� &� &� � &� &�t�z� 2� 2�& -��*�D� �I�I�,�d� 3� 3� 3� � � �� &� &� &� &� &� � '� '�� � 3� 3�" -� �(�(���4�4�  ���� �I�I�3����  � � � &� -� -���$�$�V�,�,�,�,� � � ��-� @� @� @� @� @� � )� )�$�*� 5� 5� -� �*�*�4�:�6�6�  ���� �I�I�5����  � � � &� -� -���$�$�V�,�,�,�,� � � ��-� @� @� @� @� @��0�0���<�<�J�E�3� �I�I�'��� 4� 4� 4� � � ��� ,� ,� ,� ,� ,r8N)r r0r�rr1r2)r r�r1r2)rr�rr�r1r2)r�r r1r2)rLrMrNr7rrrr�rEr8r6r�r��sx������ � � � � � � � �����.����6+-�+-�+-�+-�+-�+-r8r�c�$�eZdZUdZded< ded< ded< ded< ded < d ed < dd�Zedd���Zedd���Zedd���Z ed d���Z ed!d���Z ed!d���Z ed!d���Z ed!d���ZdS)"� MigrationInfoz�Exposes information about a migration step to a callback listener. The :class:`.MigrationInfo` object is available exclusively for the benefit of the :paramref:`.EnvironmentContext.on_version_apply` callback hook. r�� is_upgrade�is_stampr��up_revision_idr��up_revision_ids�down_revision_idsr,� revision_map� up_revisions�Union[str, Tuple[str, ...]]�down_revisionsr1r2c���||_||_||_tj|d���|_|jr|jd|_nd|_tj|d���|_dS)NrEr�r)r:r5r6rr�r8r7r9)r5r:r5r6r;r=s r6r7zMigrationInfo.__init__�sv��)���$��� �� �#�}�\�2�F�F�F��� � � '�"&�"6�q�"9�D� � � #'�D� �!%��~�r�!J�!J�!J����r8c��|j S)aTrue/False: indicates whether this operation is a migration. At present this is true if and only the migration is not a stamp. If other operation types are added in the future, both this attribute and :attr:`~.MigrationInfo.is_stamp` will be false. )r6r<s r6� is_migrationzMigrationInfo.is_migration�s���=� � r8c�,�|jr|jn|jS)z7Active revisions before this migration step is applied.)r5r9r8r<s r6�source_revision_idsz!MigrationInfo.source_revision_ids�s��'+�o� O�D� "� "�4�;O� r8c�,�|jr|jn|jS)z6Active revisions after this migration step is applied.)r5r8r9r<s r6�destination_revision_idsz&MigrationInfo.destination_revision_ids�s��%)�O� O�D� � ��9O� r8�Optional[Revision]c�@�|j�|j��S)zUGet :attr:`~.MigrationInfo.up_revision_id` as a :class:`.Revision`. )r:r�r7r<s r6� up_revisionzMigrationInfo.up_revision�s�� � �-�-�d�.A�B�B�Br8�%Tuple[Optional[_RevisionOrBase], ...]c�@�|j�|j��S)zLGet :attr:`~.MigrationInfo.up_revision_ids` as a :class:`.Revision`.)r:� get_revisionsr8r<s r6r;zMigrationInfo.up_revisions�s��� �.�.�t�/C�D�D�Dr8c�@�|j�|j��S)zcGet :attr:`~.MigrationInfo.down_revision_ids` as a tuple of :class:`Revisions <.Revision>`.)r:rJr9r<s r6r=zMigrationInfo.down_revisions�s��� �.�.�t�/E�F�F�Fr8c�@�|j�|j��S)zdGet :attr:`~MigrationInfo.source_revision_ids` as a tuple of :class:`Revisions <.Revision>`.)r:rJrBr<s r6�source_revisionszMigrationInfo.source_revisions�s��� �.�.�t�/G�H�H�Hr8c�@�|j�|j��S)ziGet :attr:`~MigrationInfo.destination_revision_ids` as a tuple of :class:`Revisions <.Revision>`.)r:rJrDr<s r6�destination_revisionsz#MigrationInfo.destination_revisions�s��� �.�.�t�/L�M�M�Mr8N) r:r,r5r�r6r�r;r<r=r<r1r2rr)r1rE)r1rH)rLrMrNr�__annotations__r7rOr@rBrDrGr;r=rMrOrEr8r6r4r4as����������������N�N�N�6�"�!�!�!� �%�$�$�$��'�&�&�&������A�K�K�K�K�*�!�!�!��X�!�� � � ��X� � � � � ��X� � �C�C�C��X�C��E�E�E��X�E� �G�G�G��X�G� �I�I�I��X�I� �N�N�N��X�N�N�Nr8r4c���eZdZUded<ded<ded<ded<er edd ���Zedd ���Zedd���Z edd���Z edd���Z edd���Z d�Z dS)� MigrationStepr��from_revisions_no_deps�to_revisions_no_depsr�r5rr�r1r�c��dSr4rEr<s r6�doczMigrationStep.doc�s��(+�r8r�c��|jjSr4)r�rLr<s r6�namezMigrationStep.name�s��� �)�)r8r:r,rYr(� RevisionStepc�$�t||d��S)NT�rY�r�r:rYs r6�upgrade_from_scriptz!MigrationStep.upgrade_from_script�s���L�&�$�7�7�7r8c�$�t||d��Sr�r[r\s r6�downgrade_from_scriptz#MigrationStep.downgrade_from_script�s���L�&�%�8�8�8r8c��|j Sr4)r5r<s r6� is_downgradezMigrationStep.is_downgrade�s ���?�"�"r8c�|�|j�dtj|j���dtj|j����S)N� � -> )rXr�format_as_commarSrTr<s r6r�zMigrationStep.short_logsB�� �I�I�I� � ��!<� =� =� =� =� � ��!:� ;� ;� ;� � r8c��|jrE|j�dtj|j���dtj|j���d|j��S|jS)Nrcrdz, )rVrXrrerSrTr�r<s r6�__str__zMigrationStep.__str__ s^�� �8� "�� � � ��$�T�%@�A�A�A�A��$�T�%>�?�?�?�?���� � ��>� !r8Nr�r1r�)r:r,rYr(r1rYr)rLrMrNrPrrOrVrXrr]r_rar�rgrEr8r6rRrR�s�������+�+�+�+�)�)�)�)����������,� �+�+�+� ��+� �*�*�*��X�*��8�8�8��[�8� �9�9�9��[�9� �#�#�#��X�#�� � � ��X� � "� "� "� "� "r8rRc�<�eZdZd)d �Zd �Zd*d �Zed+d���Zed,d���Zed,d���Z ed,d���Z ed,d���Z ed-d���Z d.d�Z d/d�Zd0d�Zd1d�Zd.d�Zd.d�Zd.d �Zd2d"�Zed3d$���Zed3d%���Zed4d'���Zd(S)5rYr:r,r�r(r5r�r1r2c�|�||_||_||_|r|jj|_dS|jj|_dSr4)r:r�r5�module�upgrader�� downgrade)r5r:r�r5s r6r7zRevisionStep.__init__sH��)��� �� �$��� � :� (�� 7�D� � � � (�� 9�D� � � r8c�2�d|jj�d|j�d�S)Nz RevisionStep(z , is_upgrade=�))r�r5r<s r6�__repr__zRevisionStep.__repr__#s%��� �M� "� "� "� �O�O�O� � r8�other�objectc�l�t|t��o|j|jko|j|jkSr4)r�rYr�r5�r5rqs r6�__eq__zRevisionStep.__eq__)s7�� �u�l� +� +� 4���$�-�/� 4���5�#3�3� r8r�c��|jjSr4)r�rVr<s r6rVzRevisionStep.doc0s ���}� � r8r�c�B�|jr |jjS|jjfSr4�r5r��_normalized_down_revisionsr<s r6�from_revisionszRevisionStep.from_revisions4s%�� �?� -��=�;� ;��M�*�,� ,r8c�B�|jr |jjS|jjfSr4�r5r��_versioned_down_revisionsr<s r6rSz#RevisionStep.from_revisions_no_deps;s'�� �?� -��=�:� :��M�*�,� ,r8c�B�|jr |jjfS|jjSr4rxr<s r6� to_revisionszRevisionStep.to_revisionsDs%�� �?� <��M�*�,� ,��=�;� ;r8c�B�|jr |jjfS|jjSr4r|r<s r6rTz!RevisionStep.to_revisions_no_depsKs'�� �?� ;��M�*�,� ,��=�:� :r8c�<�t|jj��dkS�Nr%)r�r�ryr<s r6�_has_scalar_down_revisionz&RevisionStep._has_scalar_down_revisionTs���4�=�;�<�<��A�Ar8r��Set[str]c��|jsdS|jj|vrdS|jj}|sdS|�|��}| S)z�A delete is when we are a. in a downgrade and b. we are going to the "base" or we are going to a version that is implied as a dependency on another version that is remaining. FT)rar�ry�_unmerge_to_revisions)r5r��downrevsrs r6r"z!RevisionStep.should_delete_branchXs^�� � � ��5� �=� !�� .� .��5��=�;��� $��4� �5�5�e�<�<�L�#�#� #r8�Tuple[List[str], str, str]c��t|���|j��}|rsd�|j�|j�|��d���D��}t t|j���|����}nt |j��}t |dd���|d|jdfS)Nc��h|] }|j�� SrE�r��r��rs r6� <setcomp>z3RevisionStep.merge_branch_idents.<locals>.<setcomp>u�*������� ���r8F��checkr�����)r�� differencerzr:�_get_ancestor_nodesrJ�listr)r5r�� other_heads� ancestorsrzs r6r(z RevisionStep.merge_branch_identsos����%�j�j�+�+�D�,?�@�@� � � 7����*�>�>��%�3�3�K�@�@��?������I� "��D�'�(�(�3�3�I�>�>���N�N�"�$�"5�6�6�N� ���"��%� &� &� �2� � � �a� �  � r8c����t|����jjg��}|rrd��j��j�|��d���D��}t t�j���|����S�fd��jD��}t t�j���|����S)Nc��h|] }|j�� SrEr�r�s r6r�z5RevisionStep._unmerge_to_revisions.<locals>.<setcomp>�r�r8Fr�c���h|]K}�j��j�|��d���D]}|j|k� |j���LS)Fr�)r:r�rJr�)r�� to_revisionr�r5s �r6r�z5RevisionStep._unmerge_to_revisions.<locals>.<setcomp>�sy��������*�>�>��%�3�3�K�@�@��?�������:��,�,� � � -�,�,�,r8)r�r�r�r:r�rJr�r)r5r�r�r�s` r6r�z"RevisionStep._unmerge_to_revisions�s�����%�j�j�+�+�T�]�-C�,D�E�E� � � G����*�>�>��%�3�3�K�@�@��?������I� ��T�.�/�/�:�:�9�E�E�F�F� F� ����#'�#4����I���T�.�/�/�:�:�9�E�E�F�F� Fr8� Tuple[str, str, Tuple[str, ...]]c�h�|�|��}|jd|d|dd�fS�Nrr�)r�rz)r5r�rs r6r*z"RevisionStep.unmerge_branch_idents�sB���1�1�%�8�8� � � �� "� �� � ��2�� �  � r8c�f�|jsdS|jj}|sdS|�|��sdSdS)NFT)r5r�ry� intersection�r5r�r�s r6r%z!RevisionStep.should_create_branch�sJ���� ��5��=�;��� ��4� �%�%�h�/�/� ��t��ur8c��|jsdS|jj}t|��dkr(t|�|����dkrdSdS�NFr%T)r5r�ryr�r�r�s r6r'z"RevisionStep.should_merge_branches�sV���� ��5��=�;�� �x�=�=�1� � ��U�%7�%7��%A�%A�!B�!B�Q�!F�!F��4��ur8c�v�|jsdS|jj}|jj|vrt|��dkrdSdSr�)rar�ryr�r�s r6r)z$RevisionStep.should_unmerge_branches�sF��� � ��5��=�;�� �=� !�U� *� *�s�8�}�}�q�/@�/@��4��ur8�Tuple[str, str]c��|jsR|�|jj��}t |��dks Jd���t |��d}n|jjd}|jr||jjfS|jj|fS)Nr%z4Can't do an UPDATE because downrevision is ambiguousr)r�r�r�ryr�r�r5)r5r��downrev� down_revisions r6r+zRevisionStep.update_version_num�s����-� H��(�(�� �8���G��G� � ��!�!�!�E�"�!�!� ��M�M�!�,�M�M� �M�D�Q�G�M� �?� 9� �$�-�"8�8� 8��=�)�=�8� 8r8r�c��|jjSr4r�r<s r6r#zRevisionStep.delete_version_num�� ���}�%�%r8c��|jjSr4r�r<s r6r&zRevisionStep.insert_version_num�r�r8r4c�f�t|j|jj|jj|jd���S)NF�r:r;r=r5r6)r4r:r�ryr5r<s r6r|zRevisionStep.info�s7����*���/��=�C����  � � � r8N)r:r,r�r(r5r�r1r2)rqrrr1r�rrr�r�r�r1r�)r�r�r1r�)r�r�r1r�)r�r�r1r��r�r�r1r�rh�r1r4)rLrMrNr7rprurOrVrzrSrrTr�r"r(r�r*r%r'r)r+r#r&r|rEr8r6rYrYs������ :� :� :� :� � � �  � � � ��!�!�!��X�!��-�-�-��X�-� �-�-�-��X�-��<�<�<��X�<� �;�;�;��X�;��B�B�B��X�B�$�$�$�$�. � � � �2G�G�G�G�0  �  �  �  �����& � � � � � � � �9�9�9�9�"�&�&�&��X�&��&�&�&��X�&�� � � ��X� � � r8rYc��eZdZU d+d,d �ZdZd ed<d-d�Zd�Zed���Z ed.d���Z ed.d���Z ed.d���Z ed/d���Z ed/d���Zd0d�Zd1d!�Zd2d#�Zd3d$�Zd4d&�Zd3d'�Zd3d(�Zed5d*���ZdS)6� StampStepNr�%Optional[Union[str, Collection[str]]]rr5r�� branch_mover:�Optional[RevisionMap]r1r2c��tj|d���|_tj|d���|_||_||_|j|_||_dS)NrEr�) rr�rrr5r��stamp_revisionr�r:)r5rrr5r�r:s r6r7zStampStep.__init__�sX��'+�m�E�2�&F�&F�&F�� �$(�M�#�r�$B�$B�$B���$���&��� �/���(����r8r�rVr�rc ��dSr4rE)r5r�s r6r�zStampStep.stamp_revision s���tr8c��t|t��o?|j|jko/|j|jko|j|jko|j|jkSr4)r�r�rzrr�r5rts r6ruzStampStep.__eq__sc�� �u�i� (� (� 4��$��(;�;� 4��"�d�&7�7� 4��!�T�%5�5� 4���5�#3�3�  r8c��|jSr4�rr<s r6rzzStampStep.from_revisionss ���z�r8r�c��|jSr4�rr<s r6rzStampStep.to_revisionss ���x�r8c��|jSr4r�r<s r6rSz StampStep.from_revisions_no_depss ���z�r8c��|jSr4r�r<s r6rTzStampStep.to_revisions_no_deps%s ���x�r8r�c�P�t|j��dksJ�|jdS�Nr%r�r�rr<s r6r#zStampStep.delete_version_num+s'���4�:���!�#�#�#�#��z�!�}�r8c�P�t|j��dksJ�|jdSr��r�rr<s r6r&zStampStep.insert_version_num0s'���4�8�}�}��!�!�!�!��x��{�r8r�r�r�c��t|j��dksJ�t|j��dksJ�|jd|jdfSr�)r�rrr�s r6r+zStampStep.update_version_num5sK���4�:���!�#�#�#�#��4�8�}�}��!�!�!�!��z�!�}�d�h�q�k�)�)r8�Union[Set[str], List[str]]�=Union[Tuple[List[Any], str, str], Tuple[List[str], str, str]]c�l�t|jdd���|jd|jdfSr�)r�rrr�s r6r(zStampStep.merge_branch_idents:s6�� ���A�b�D�!� "� "� �J�r�N� �H�Q�K�  � r8�Tuple[str, str, List[str]]c�l�|jd|jdt|jdd���fSr�)rrr�r�s r6r*zStampStep.unmerge_branch_identsDs5�� �J�q�M� �H�R�L� ���!�B�$�� � �  � r8c��|jo|jSr4)rar�r�s r6r"zStampStep.should_delete_branchNs��� �5�T�%5�5r8�Union[Set[str], bool]c��|joT|jp&t|j���|��o&t|j���|��Sr4)r5r�r�rr�rr�s r6r%zStampStep.should_create_branchTsP�� �O� 0��!�F�S���_�_�%?�%?��%F�%F� 0��D�H� � �(�(��/�/� r8c�2�t|j��dkSr�r�r�s r6r'zStampStep.should_merge_branches[s���4�:����"�"r8c�2�t|j��dkSr�r�r�s r6r)z!StampStep.should_unmerge_branches^s���4�8�}�}�q� � r8r4c��|jr|j|jfn |j|jf\}}|j�J�t |j|||jd���S)NTr�)r5rrr:r4)r5�up�downs r6r|zStampStep.infoasm���� (�T�X�t�z� "� "��*�d�h�'� ��D� � �,�,�,���*������  � � � r8r4) rr�rr�r5r�r�r�r:r�r1r2rrrhr�)r�r�r1r�)r�r�r1r�r�)r�r�r1r�r�)rLrMrNr7rVrPr�rurOrzrrSrTr#r&r+r(r*r"r%r'r)r|rEr8r6r�r��s��������/3� )� )� )� )� )��C��������� � � �����X�������X�������X�� �����X�� �����X�������X��*�*�*�*�  � � � � � � � �6�6�6�6�  � � � �#�#�#�#�!�!�!�!��  �  �  ��X�  �  �  r8r�)E� __future__r� contextlibrr�loggingrq�typingrrrr r r r r rrrrrr� sqlalchemyrr�sqlalchemy.enginerrr��sqlalchemy.engine.strategiesr�rrr� util.compatr�util.sqla_compatrrr �sqlalchemy.engine.baser!r"�sqlalchemy.engine.mockr#�sqlalchemy.sqlr$� environmentr&r�r'� script.baser(r)�script.revisionr*r+r,� getLoggerrLr{r.r0r�r4rRrYr�rEr8r6�<module>r�s`��#�"�"�"�"�"�%�%�%�%�%�%�"�"�"�"�"�"����� � � � �������������������������!�!�!�!�!�!������������������������������������������� � � � � � �������������%�%�%�%�%�%�$�$�$�$�$�$�-�-�-�-�-�-�;�;�;�;�;�;�������������������#�#�#�#�#�#�&�&�&�&�&�&��.�)�)�)�)�)�)�%�%�%�%�%�%�1�1�1�1�1�1�2�2�2�2�2�2�5�5�5�5�5�5�)�)�)�)�)�)�/�/�/�/�/�/�������$�$�$�$�$�$�-�-�-�-�-�-�1�1�1�1�1�1�*�*�*�*�*�*�-�-�-�-�-�-��g���!�!��7�7�7�7�7�7�7�7�:Z  �Z  �Z  �Z  �Z  �Z  �Z  �Z  �zl-�l-�l-�l-�l-�l-�l-�l-�^@N�@N�@N�@N�@N�@N�@N�@N�F0"�0"�0"�0"�0"�0"�0"�0"�f_ �_ �_ �_ �_ �=�_ �_ �_ �Dv �v �v �v �v � �v �v �v �v �v r8
Memory