� J�g�V��p�ddlmZddlZddlmZddlmZddlmZddlmZddlm Z dd lm Z dd l m Z dd lmZerdd lmZdd lmZddlmZddl mZdDd�Z dEdFd�Z dGdHd+�ZdId-�Z dJdKd1�Z dLdMd4�Z dLdMd5�ZdNd7�Z dOdPd;�Z dQdRd=�Z dSdTd>�Z!dSdTd?�Z" dUdVdA�Z#dNdB�Z$dSdWdC�Z%dS)X�)� annotationsN)�List)�Optional)� TYPE_CHECKING)�Union�)� autogenerate)�util)�EnvironmentContext)�ScriptDirectory)�Config)�Script)� _RevIdType)�ProcessRevisionDirectiveFn�configr �return�Nonec���|�d��tj|�����D]�}t tj�|���|d����5}t|�����}ddd��n #1swxYwY|�d||����|�d��|�d��dS)zNList available templates. :param config: a :class:`.Config` object. zAvailable templates: �READMENz%s - %sz1 Templates are used via the 'init' command, e.g.:z, alembic init --template generic ./scripts) � print_stdout�os�listdir�get_template_directory�open�path�join�next�rstrip)r�tempname�readme�synopsiss �_/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/alembic/command.py�list_templatesr#s&�� ���0�1�1�1��J�v�<�<�>�>�?�?�;�;�� � �G�L�L��6�6�8�8�(�H� M� M� � � -� ��F�|�|�*�*�,�,�H� -� -� -� -� -� -� -� -� -� -� -���� -� -� -� -� ���I�x��:�:�:�:� ���L�M�M�M� ���G�H�H�H�H�Hs�>"B,�,B0 �3B0 �genericF� directory�str�template�package�boolc��tj|tj��r+tj|��rt jd|z���tj�|���|��}tj|tj��st jd|z���tj|tj��sct j dtj� |����fi|j ��5tj |��ddd��n #1swxYwYtj�|d��}t j dtj� |����fi|j ��5tj |��ddd��n #1swxYwYt|��}d}tj|��D]�}tj�||��} |dkr�|j�J�tj� |j��}tj|tj��rt jd|�d�fi|j ����|�| ||� ����tj�| ��r6tj�||��} |�| | ����|r�tj�tj� |��d ��tj�tj� |��d ��fD]]} t j d | ��fi|j ��5t'| d ��5 ddd��n #1swxYwYddd��n #1swxYwY�^|�J�t jd |�d�fi|j ��dS)akInitialize a new scripts directory. :param config: a :class:`.Config` object. :param directory: string path of the target directory. :param template: string name of the migration environment template to use. :param package: when True, write ``__init__.py`` files into the environment location as well as the versions/ location. z,Directory %s already exists and is not emptyzNo such template %rzCreating directory N�versionszalembic.ini.makozFile z already exists, skipping)�script_locationz __init__.pyzAdding �wz9Please edit configuration/connection/logging settings in z before proceeding.)r�access�F_OKrr � CommandErrorrrr�status�abspath�messaging_opts�makedirsr �config_file_name�msg�_generate_template�isfile� _copy_filer) rr%r'r(� template_dirr+�script� config_file�file_� file_path� output_filers r"�initr@*s���( �y��B�G�$�$� ���I�)>�)>� ��� :�Y� F� � � ��7�<�<�� =� =� ?� ?��J�J�L� �9�\�2�7� +� +�B��� 5�� @�A�A�A� �9�Y��� (� (�#� �[� @�"�'�/�/�)�"<�"<� @� @� � ��#� � � #� #� �K� � "� "� "�  #� #� #� #� #� #� #� #� #� #� #���� #� #� #� #� �w�|�|�I�z�2�2�H� ��;�b�g�o�o�h�7�7�;�;� � � � � � ��� � �H���� ������������������ �Y� '� '�F�"�K���L�)�)�6�6���G�L�L��u�5�5� � �&� &� &��*�6�6�6��'�/�/�&�*A�B�B�K��y��b�g�.�.� ���D�K�D�D�D����+����� �)�)��{�I�*������W�^�^�I� &� &� 6��'�,�,�y�%�8�8�K� � � �i�� 5� 5� 5���� �G�L�L������3�3�]� C� C� �G�L�L������2�2�M� B� B� � � �D���/�t�/�/�I�I�6�3H�I�I� � ��$��_�_���������������������� � � � � � � � � � � ���� � � � �� � "� "� "��H� :�"� :� :� :��� � �����sZ� D*�*D.�1D.� F-�-F1�4F1�4N*�N� N*�N �N*�N �N*�*N. �1N. �head�message� Optional[str]r �sql�splice� branch_label�Optional[_RevIdType]� version_path�rev_id� depends_on�process_revision_directives�$Optional[ProcessRevisionDirectiveFn]�/Union[Optional[Script], List[Optional[Script]]]c �\��tj|��} t||||||||| �� � } tj|| | | ����t j|�d����} |rd} |rt jd����fd�}n| r�fd�}n|rt jd���| rFt|| ||�j �� ��5| � ��d d d ��n #1swxYwYd ��� ��D��}t|��d kr|d S|S)a�Create a new revision file. :param config: a :class:`.Config` object. :param message: string message to apply to the revision; this is the ``-m`` option to ``alembic revision``. :param autogenerate: whether or not to autogenerate the script from the database; this is the ``--autogenerate`` option to ``alembic revision``. :param sql: whether to dump the script out as a SQL string; when specified, the script is dumped to stdout. This is the ``--sql`` option to ``alembic revision``. :param head: head revision to build the new revision upon as a parent; this is the ``--head`` option to ``alembic revision``. :param splice: whether or not the new revision should be made into a new head of its own; is required when the given ``head`` is not itself a head. This is the ``--splice`` option to ``alembic revision``. :param branch_label: string label to apply to the branch; this is the ``--branch-label`` option to ``alembic revision``. :param version_path: string symbol identifying a specific version path from the configuration; this is the ``--version-path`` option to ``alembic revision``. :param rev_id: optional revision identifier to use instead of having one generated; this is the ``--rev-id`` option to ``alembic revision``. :param depends_on: optional list of "depends on" identifiers; this is the ``--depends-on`` option to ``alembic revision``. :param process_revision_directives: this is a callable that takes the same form as the callable described at :paramref:`.EnvironmentContext.configure.process_revision_directives`; will be applied to the structure generated by the revision process where it can be altered programmatically. Note that unlike all the other parameters, this option is only available via programmatic use of :func:`.command.revision`. � rBr rDrArErFrHrIrJ)rK�revision_environmentTz7Using --sql with --autogenerate does not make any sensec�4����||��gS�N��run_autogenerate��rev�context�revision_contexts �r"�retrieve_migrationsz%revision.<locals>.retrieve_migrations�s��� � -� -�c�7� ;� ;� ;��I�c�4����||��gSrR)�run_no_autogeneraterUs �r"rYz%revision.<locals>.retrieve_migrations�s��� � 0� 0��g� >� >� >��IrZziUsing --sql with the revision command when revision_environment is not configured does not make any sense��fn�as_sql� template_argsrXNc��g|]}|��S�rb)�.0r;s r"� <listcomp>zrevision.<locals>.<listcomp>�s��H�H�H�&�v�H�H�HrZrr)r � from_config�dict�autogen�RevisionContextr �asbool�get_main_optionr0r r`�run_env�generate_scripts�len)rrBr rDrArErFrHrIrJrK�script_directory� command_args� environmentrY�scriptsrXs @r"�revisionrr{s���t'�2�6�:�:����!� � ��!�!��� � � �L��.����$?� �����+�f�4�4�5K�L�L�M�M�K�� �� � � ��#�I��� � � � � � � � �  � � � � � � � � ��� M� � � � � '� � � �"��*�8�-�  � � � '� '� � $� $� &� &� &� '� '� '� '� '� '� '� '� '� '� '���� '� '� '� '�I�H�$4�$E�$E�$G�$G�H�H�H�G� �7�|�|�q����q�z���s�C(�(C,�/C,�'Config'c ����tj|��}tddddddddd�� � }tj|||����fd�}t |||d�j����5|���ddd��n #1swxYwY�jd}g}|j D])}|� |� �����*|rtj d |�����|�d ��dS) z�Check if revision command with autogenerate has pending upgrade ops. :param config: a :class:`.Config` object. .. versionadded:: 1.9.0 NTFrArOc�4����||��gSrRrSrUs �r"rYz"check.<locals>.retrieve_migrationss����)�)�#�w�7�7�7�� rZr]�����z!New upgrade operations detected: z#No new upgrade operations detected.)r rerfrgrhr r`rk�generated_revisions�upgrade_ops_list�extend�as_diffsr �AutogenerateDiffsDetectedr)rrnrorY�migration_script�diffs� upgrade_opsrXs @r"�checkr�s����'�2�6�:�:����� � ������ � � �L��.������� ����� ��� ��&�4�)�  � � �#�#� � � �"�"�"�#�#�#�#�#�#�#�#�#�#�#����#�#�#�#�(�;�B�?�� �E�'�8�-�-� � � � �[�)�)�+�+�,�,�,�,� �C��,� 7�� 7� 7� � � � ���A�B�B�B�B�Bs�#B�B� B� revisionsr�Optional[Script]c�V�tj|��}d|i}tj|�d����}|rCd�}t |||d|���5|���ddd��n #1swxYwY|j|ptj��|fd||d�|��S) a�Merge two revisions together. Creates a new migration file. :param config: a :class:`.Config` instance :param revisions: The revisions to merge. :param message: string message to apply to the revision. :param branch_label: string label name to apply to the new revision. :param rev_id: hardcoded revision identifier instead of generating a new one. .. seealso:: :ref:`branches` rrPc��gSrRrb�rVrWs r"�nothingzmerge.<locals>.nothingWs���IrZF)r^r_r`NT)�refreshrA� branch_labels) r rer rirjr rk�generate_revisionrI) rr�rBrFrIr;r`rpr�s r"�merger�3s-��4� (�� 0� 0�F��&��M� �+�f�4�4�5K�L�L�M�M�K�� � � � � � � ���'�  � � � � � �N�N� � � � � � � � � � � � � � ���� � � � � $�6� #���$�+�-�-�� �� �"�  � � �  � �s�A:�:A>�A>rr�tagc �.���tj|���d}d�vr/|stjd�����dd��\}���fd�}t |�|||�|���5����ddd��dS#1swxYwYdS)a�Upgrade to a later version. :param config: a :class:`.Config` instance. :param revision: string revision target or range for --sql mode. May be ``"heads"`` to target the most recent revision(s). :param sql: if True, use ``--sql`` mode. :param tag: an arbitrary "tag" that can be intercepted by custom ``env.py`` scripts via the :meth:`.EnvironmentContext.get_tag_argument` method. N�:�Range revision not allowed�c�0�����|��SrR)� _upgrade_revs�rVrWrrr;s ��r"�upgradezupgrade.<locals>.upgrade�s����#�#�H�c�2�2�2rZ�r^r_� starting_rev�destination_revr��r rer r0�splitr rk)rrrrDr�r�r�r;s ` @r"r�r�ms����*� (�� 0� 0�F��L� �h���� B��#�$@�A�A� A�!)����Q�!7�!7�� �h�3�3�3�3�3�3� ��� ��!� � � � � � � � ������ � � � � � � � � � � � ���� � � � � � s�(B � B�Bc �\���tj|���d}d�vr0|stjd�����dd��\}�n|rtjd�����fd�}t |�|||�|���5����ddd��dS#1swxYwYdS)a�Revert to a previous version. :param config: a :class:`.Config` instance. :param revision: string revision target or range for --sql mode. May be ``"base"`` to target the first revision. :param sql: if True, use ``--sql`` mode. :param tag: an arbitrary "tag" that can be intercepted by custom ``env.py`` scripts via the :meth:`.EnvironmentContext.get_tag_argument` method. Nr�r�r�z/downgrade with --sql requires <fromrev>:<torev>c�0�����|��SrR)�_downgrade_revsr�s ��r"� downgradezdowngrade.<locals>.downgrade�s����%�%�h��4�4�4rZr�r�)rrrrDr�r�r�r;s ` @r"r�r��s9����*� (�� 0� 0�F��L� �h���� B��#�$@�A�A� A�!)����Q�!7�!7�� �h�h� � ��� =� � � �5�5�5�5�5�5� ��� ��!� � � � � � � � ������ � � � � � � � � � � � ���� � � � � � s�?B!�!B%�(B%rVc�0���tj����|dkrG��fd�}t��|���5����ddd��dS#1swxYwYdS��|��D]}��|j���dS)z�Show the revision(s) denoted by the given symbol. :param config: a :class:`.Config` instance. :param rev: string revision target. May be ``"current"`` to show the revision(s) currently applied in the database. �currentc�l����|��D]}��|j���gSrR)� get_revisionsr� log_entry)rVrW�scrr;s ��r"� show_currentzshow.<locals>.show_current�s>����*�*�3�/�/� 2� 2���#�#�B�L�1�1�1�1��IrZ�r^N)r rer rkr�rr�)rrVr�r�r;s` @r"�showr��s ����� (�� 0� 0�F� �i��� � � � � � �  ���<� @� @� @� � � �N�N� � � � � � � � � � � � � � � ���� � � � � � ��&�&�s�+�+� .� .�B� � � �� � -� -� -� -� .� .s�A�A�A� rev_range�verbose�indicate_currentc���� �tj|��}|�Cd|vrtjd���|����d��\}}ndx}}tj|�d����p�}d ��fd� � � fd�}|dks|dks|r|||||��dS� ||||��dS) z�List changeset scripts in chronological order. :param config: a :class:`.Config` instance. :param rev_range: string revision range. :param verbose: output in verbose mode. :param indicate_current: indicate current revision. Nr�z9History range requires [start]:[end], [start]:, or :[end]rPrbc ���|�|pd|pd���D]>}�r|j|v|_|�|��ddd������?dS)N�base�heads)r�rAT)r��include_branches� include_doc�include_parents)�walk_revisionsrr�_db_current_indicatorr� cmd_format)rr;r�rA�currentsr�r�r�s ��r"�_display_historyz!history.<locals>._display_historys�����'�'����d�o�g�(� � � � �B� � C�+-�;�(�+B��(� � � �� � �#�%)� $�$(� ��� � � � � � rZc������������fd�}t��|���5����ddd��dS#1swxYwYdS)Nc�~���dkr����||��n%�dkr���|�|��n�����|��gS)Nr�rb)rVrWr�r�rrAr;s �����r"�_display_current_historyzMhistory.<locals>._display_history_w_current.<locals>._display_current_historyso����y� � � � ����s�C�@�@�@�@���"�"� � ����d�C�@�@�@�@� � ����t�S�A�A�A��IrZr�)r rk)rr;r�rAr�r�s```` �r"�_display_history_w_currentz+history.<locals>._display_history_w_currents�������� � � � � � � � � � ���3K� L� L� L� � � �N�N� � � � � � � � � � � � � � � ���� � � � � � s�A�A� Ar�)rb)r rer r0�stripr�rirj) rr�r�r�r;r�rArpr�r�s `` @r"�historyr��s,�����&� (�� 0� 0�F��� �i� � ��#�N��� ��_�_�&�&�,�,�S�1�1� ��d�d����t� � �F�*�*�+A�B�B�C�C� � �� ������� � � � � � �y���D�I�-�-��-�"�"�6�6�4��>�>�>�>�>������t�4�4�4�4�4rZ�resolve_dependenciesc� �tj|��}|r|�d��}n'|�|�����}|D]-}|�|�|dd������.dS)z�Show current available heads in the script directory. :param config: a :class:`.Config` instance. :param verbose: output in verbose mode. :param resolve_dependencies: treat dependency version as down revisions. r�TF)r��tree_indicatorsN)r rer�� get_headsrr�)rr�r�r;r�rVs r"r�r�'s���� (�� 0� 0�F��9��$�$�W�-�-����$�$�V�%5�%5�%7�%7�8�8��� � ����� �N�N��$�� � � � � � � � � rZc �*����tj|�������D]f��jr]|�d���d���d���fd��fd��jD��D�������gdS)zShow current branch points. :param config: a :class:`.Config` instance. :param verbose: output in verbose mode. z%s %s T)r�� c3��K�|]C}dtt�j����z�d|�dd������V��DdS)� z -> FT)r�r�N)rmr&rrr�)rc�rev_objr�r�s ��r"� <genexpr>zbranches.<locals>.<genexpr>Ps����� � � � �c�#�b�k�"2�"2�3�3�3�3�3��*�*�!�D�g�+����� � � � � � rZc3�B�K�|]}��|��V��dSrR)� get_revision)rcrVr;s �r"r�zbranches.<locals>.<genexpr>XsB�����$�$�58��+�+�C�0�0�$�$�$�$�$�$rZN)r rer��is_branch_pointrr�r�nextrev)rr�r�r;s `@@r"�branchesr�Bs������� (�� 0� 0�F��#�#�%�%���� � � � � � ��� � �g�� �=�=�� � � � � � � �$�$�$�$�<>�J�$�$�$� � � � � � � � ���rZc������tj�������fd�}t��|d���5����ddd��dS#1swxYwYdS)z�Display the current revision for a database. :param config: a :class:`.Config` instance. :param verbose: output in verbose mode. c�����r7��dtj|jjj������|��D]*}��|�������+gS)NzCurrent revision(s) for %s:)rr �obfuscate_url_pw� connection�engine�url�get_all_currentr�)rVrWrr;r�s ���r"�display_versionz current.<locals>.display_versionjs���� � � � � �-��%�g�&8�&?�&C�D�D� � � ��)�)�#�.�.� 9� 9�C� � � ����w� 7� 7� 8� 8� 8� 8�� rZT)r^� dont_mutateN�r rer rk)rr�r�r;s`` @r"r�r�_s������� (�� 0� 0�F� � � � � � � � ���?�� � � ��� ��������������������������s�A�A�A�purgec ��� � �tj|��� |rmg� d}tj|��D]S}d|vr8|�dd��\}}||kr|�|}ntjd���� �|���Tntj|��� � � fd�}t|� |||r|ndtj� ��||���5� � ��ddd��dS#1swxYwYdS)a�'stamp' the revision table with the given revision; don't run any migrations. :param config: a :class:`.Config` instance. :param revision: target revision or list of revisions. May be a list to indicate stamping of multiple branch heads; may be ``"base"`` to remove all revisions from the table or ``"heads"`` to stamp the most recent revision(s). .. note:: this parameter is called "revisions" in the command line interface. :param sql: use ``--sql`` mode :param tag: an arbitrary "tag" that can be intercepted by custom ``env.py`` scripts via the :class:`.EnvironmentContext.get_tag_argument` method. :param purge: delete all entries in the version table before stamping. Nr�r�zMStamp operation with --sql only supports a single starting revision at a timec�T����tj���|��SrR)� _stamp_revsr �to_tuple)rVrW�destination_revsr;s ��r"�do_stampzstamp.<locals>.do_stamp�s$����!�!�$�-�0@�"A�"A�3�G�G�GrZ)r^r_r�r�r�r�) r rer �to_listr�r0�appendr r�rk) rrrrDr�r�r�� _revision�srevr�r�r;s @@r"�stampr�{s�����<� (�� 0� 0�F� �2���� ���h�/�/� /� /�I��i���"+�/�/�#�q�"9�"9���i��4�'�'�#�+�'+� � �"�/�A���� � #� #�I� .� .� .� .� /� �<��1�1��H�H�H�H�H�H� ��� ��%(�2�\�\�d�� �&6�7�7� �� � � � � � ������ � � � � � � � � � � � ���� � � � � � s� C/�/C3�6C3c�h��tj|���|dkrF�fd�}t|�|���5����ddd��dS#1swxYwYdS��|��}|st jd|z���|D]}|sJ�t j|j��� dS)zEdit revision script(s) using $EDITOR. :param config: a :class:`.Config` instance. :param rev: target revision. r�c���|stjd�����|��D]}tj|j���gS)NzNo current revisions)r r0r��open_in_editorr)rVrWr�r;s �r"� edit_currentzedit.<locals>.edit_current�sV���� @��'�(>�?�?�?��*�*�3�/�/� -� -���#�B�G�,�,�,�,��IrZr�Nz*No revision files indicated by symbol '%s') r rer rkr�r r0r�r)rrVr��revsr�r;s @r"�editr��s8���� (�� 0� 0�F� �i��� � � � � � ���<� @� @� @� � � �N�N� � � � � � � � � � � � � � � ���� � � � � � ��#�#�C�(�(��� ��#�<�s�B��� �� )� )�B��I�I�2� � ��� (� (� (� (� )� )s�A�A�Ac��tj|��}d�}t||||���5|���ddd��dS#1swxYwYdS)z�Create the alembic version table if it doesn't exist already . :param config: a :class:`.Config` instance. :param sql: use ``--sql`` mode. .. versionadded:: 1.7.6 c�.�|���gSrR)�_ensure_version_tabler�s r"�do_ensure_versionz)ensure_version.<locals>.do_ensure_version�s���%�%�'�'�'�� rZ)r^r_Nr�)rrDr;r�s r"�ensure_versionr��s���� (�� 0� 0�F���� ��� ��  � � ��� ������ ��������������������s�A � A�A)rr rr)r$F) rr r%r&r'r&r(r)rr) NFFrAFNNNNN)rr rBrCr r)rDr)rAr&rEr)rFrGrHrCrIrCrJrCrKrLrrM)rrsrr)NNN) rr r�rrBrCrFrGrIrCrr�)FN) rr rrr&rDr)r�rCrr)rr rVr&rr)NFF) rr r�rCr�r)r�r)rr)FF)rr r�r)r�r)rr)F)rr r�r)rr)FNF) rr rrrrDr)r�rCr�r)rr)rr rDr)rr)&� __future__rr�typingrrrr�r rgr �runtime.environmentr r;r �alembic.configr �alembic.script.baser�alembic.script.revisionrrr#r@rrrr�r�r�r�r�r�r�r�r�r�r�rbrZr"�<module>r�s���#�"�"�"�"�"� � � � ������������� � � � � � �������%�%�%�%�%�%�������3�3�3�3�3�3�#�#�#�#�#�#��@�%�%�%�%�%�%�*�*�*�*�*�*�2�2�2�2�2�2�?�?�?�?�?�?�I�I�I�I�,�� N�N�N�N�N�f"�����)-�"&� � $�HL�|�|�|�|�|�~6C�6C�6C�6C�x"�)-� � 7�7�7�7�7�z�� )�)�)�)�)�^�� ,�,�,�,�,�^.�.�.�.�8 $��"� B5�B5�B5�B5�B5�LIN� � � � � �6�����:�����>��� @�@�@�@�@�F)�)�)�)�B������rZ
Memory