RPOS \ddlmZddlZddlmZddlmZddlmZddlmZddlm Z dd lm Z dd l m Z dd lmZerdd lmZdd lmZddl mZd@dZ dAdBdZ dCdDd)ZdEd+Z dFdGd.Z dHdId1Z dHdId2Zd3Z dJdKd7ZdLd8ZdMd9ZdMdNd:Z dOdPd<Z!dQd>Z"dMdRd?Z#dS)S) annotationsN)List)Optional) TYPE_CHECKING)Union) autogenerate)util)EnvironmentContext)ScriptDirectory)Config)Script)ProcessRevisionDirectiveFnconfigr c|dtj|D]}t tj||d5}t|}dddn #1swxYwY|d|||d|ddS)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_stdoutoslistdirget_template_directoryopenpathjoinnextrstrip)rtempnamereadmesynopsiss /srv/buildsys-work-dir/castor/build_node/builder-2/WGSG1/unpkd_srcs/cloudlinux-venv-1.0.6/venv/lib/python3.11/site-packages/alembic/command.pylist_templatesr s& 0111Jv<<>>??;;  GLL6688(H M M   - F||**,,H - - - - - - - - - - - - - - - Ix:::: LMMM GHHHHHs>"B,,B0 3B0 genericF directorystrtemplatepackageboolreturnNonectj|tjr+tj|rt jd|ztj||}tj|tjst jd|ztj|tjsct j dtj |fi|j 5tj |dddn #1swxYwYtj|d}t j dtj |fi|j 5tj |dddn #1swxYwYt|}d}tj|D]}tj||} |dkr|jJtj |j}tj|tjrt jd|dfi|j || || tj| r6tj||} || | |rtjtj |d tjtj |d fD]Y} t j di|j 5t'| d 5 dddn #1swxYwYdddn #1swxYwYZ|Jt jd |dfi|j dS)aInitialize 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. .. versionadded:: 1.2 z,Directory %s already exists and is not emptyzNo such template %rzCreating directory Nversionszalembic.ini.makozFile z already exists, skipping)script_locationz __init__.pyAdding {path!r}wz9Please edit configuration/connection/logging settings in z before proceeding.)r,)raccessF_OKrr CommandErrorrrrstatusabspathmessaging_optsmakedirsr config_file_namemsg_generate_templateisfile _copy_filer) rr"r$r% template_dirr*script config_filefile_ file_path output_filers rinitr@'s. yBG$$ I)>)>  :Y F   7<< = = ? ?JJL 9\27 + +B 5 @AAA 9Y ( (# [ @"'//)"<"< @ @  #   # # K " " "  # # # # # # # # # # # # # # # w||Iz22H ;bgooh77;;       H  Y ' 'F"KL))66GLLu55 & & &*666'//&*ABBKybg.. DKDDD+ )){I*W^^I & & 6',,y%88K   i 5 5 5 GLL33] C C GLL22M B B   DHH&2GHH  $__                 " " "H :" : : :  sZ D**D.1D. F--F14F10N&N N&N N&N N&&N* -N* headmessage Optional[str]r sqlsplice branch_label version_pathrev_id depends_onprocess_revision_directives$Optional[ProcessRevisionDirectiveFn]/Union[Optional[Script], List[Optional[Script]]]c \tj|} t|||||||||  } tj|| | | t j|d} |rd} |rt jdfd}n| rfd}n|rt jd| rFt|| ||j  5| d d d n #1swxYwYd  D}t|d kr|d S|S)aCreate 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 rDrArErFrGrHrI)rJrevision_environmentTz7Using --sql with --autogenerate does not make any sensec4||gSNrun_autogeneraterevcontextrevision_contexts rretrieve_migrationsz%revision..retrieve_migrationss  - -c7 ; ; ;Ic4||gSrQ)run_no_autogeneraterTs rrXz%revision..retrieve_migrationss  0 0g > > >IrYziUsing --sql with the revision command when revision_environment is not configured does not make any sensefnas_sql template_argsrWNcg|]}|Sra).0r;s r zrevision..sHHH&vHHHrYrr)r from_configdictautogenRevisionContextr asboolget_main_optionr0r r_run_envgenerate_scriptslen)rrBr rDrArErFrGrHrIrJscript_directory command_args environmentrXscriptsrWs @rrevisionrq{st'26::!  !!   L.$? +f445KLLMMK   #I                   M    '   "*8-     ' '  $ $ & & & ' ' ' ' ' ' ' ' ' ' ' ' ' ' 'IH$4$E$E$G$GHHHG 7||qqzsC((C,/C,'Config'c tj|}tddddddddd }tj|||fd}t |||dj5|dddn #1swxYwYjd}|j }|rtj d || d dS) zCheck if revision command with autogenerate has pending upgrade ops. :param config: a :class:`.Config` object. .. versionadded:: 1.9.0 NTFrArNc4||gSrQrRrTs rrXz"check..retrieve_migrationss))#w777 rYr\z!New upgrade operations detected: z#No new upgrade operations detected.)r rdrerfrgr r_rjgenerated_revisions upgrade_opsas_diffsr AutogenerateDiffsDetectedr)rrmrnrXmigration_scriptdiffsrWs @rcheckr|s{'26::     L.   &4)    ##   """###############(;B?  ( 1 1 3 3E C, 7 7 7    ABBBBBs#BB B revisionsOptional[Script]c~tj|}d|i}|j|ptj|fd||d|S)a{Merge two revisions together. Creates a new migration file. :param config: a :class:`.Config` instance :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` rT)refreshrA branch_labels)r rdgenerate_revisionr rH)rr}rBrFrHr;r_s rmerger2si0 ( 0 0F&M $6 #$+--  "       rYrqtagc .tj|d}dvr/|stjddd\}fd}t |||||5ddddS#1swxYwYdS)adUpgrade to a later version. :param config: a :class:`.Config` instance. :param revision: string revision target or range for --sql mode :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 allowedc0|SrQ) _upgrade_revsrUrVrqr;s rupgradezupgrade..upgradeus##Hc222rYr]r^ starting_revdestination_revrr rdr r0splitr rj)rrqrDrrrr;s ` @rrrYs( ( 0 0FL h B#$@AA A!)Q!7!7 h333333  !                         s(B  BBc \tj|d}dvr0|stjddd\}n|rtjdfd}t |||||5ddddS#1swxYwYdS)afRevert to a previous version. :param config: a :class:`.Config` instance. :param revision: string revision target or range for --sql mode :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. Nrrrz/downgrade with --sql requires :c0|SrQ)_downgrade_revsrs r downgradezdowngrade..downgrades%%h444rYrr)rrqrDrrrr;s ` @rrrs9( ( 0 0FL h B#$@AA A!)Q!7!7 hh   =   555555  !                         s?B!!B%(B%c0tj|dkrGfd}t|5ddddS#1swxYwYdS|D]}|jdS)zShow the revision(s) denoted by the given symbol. :param config: a :class:`.Config` instance. :param revision: string revision target currentcl|D]}|jgSrQ) get_revisionsr log_entry)rUrVscrr;s r show_currentzshow..show_currents>**3// 2 2##BL1111IrYr]N)r rdr rjrrr)rrUrrr;s` @rshowrs  ( 0 0F i        < @ @ @   NN                     &&s++ . .B    - - - - . .sAAA rev_rangeverboseindicate_currentc tj|}|Cd|vrtjd|d\}}ndx}}tj|dp}d fd fd}|dks|dks|r|||||dS ||||dS) zList 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. Nrz9History range requires [start]:[end], [start]:, or :[end]rOrac ||pd|pdD]>}r|j|v|_||ddd?dS)Nbaseheads)rrAT)rinclude_branches include_docinclude_parents)walk_revisionsrq_db_current_indicatorr cmd_format)rr;rrAcurrentsrrrs r_display_historyz!history.._display_historys''dog(    B  C+-;(+B(    #%) $$(       rYcfd}t|5ddddS#1swxYwYdS)Nc~dkr||n%dkr||n|gS)Nrra)rUrVrrrrAr;s r_display_current_historyzMhistory.._display_history_w_current.._display_current_historysoy    sC@@@@""  dC@@@@  tSAAAIrYr)r rj)rr;rrArrs```` r_display_history_w_currentz+history.._display_history_w_currents          3K L L L   NN                     sAA Ar)ra)r rdr r0striprrhri) rrrrr;rrArorrs `` @rhistoryrs,& ( 0 0F i  #N __&&,,S11 ddt F**+ABBCC   "      yDI---""664>>>>>t44444rYc tj|}|r|d}n'||}|D]-}|||dd.dS)zShow 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. rTF)rtree_indicatorsN)r rdr get_headsrr)rrresolve_dependenciesr;rrUs rrrs ( 0 0F9$$W--$$V%5%5%7%788   NN$         rYc *tj|D]fjr]|dddfdfdjDDgdS)zShow current branch points. :param config: a :class:`.Config` instance. :param verbose: output in verbose mode. z%s %s T)r c3K|]C}dttjzd|ddVDdS) z -> FT)rrN)rlr#rqr)rbrev_objrrs r zbranches..8s   c#bk"2"233333**!Dg+      rYc3BK|]}|VdSrQ) get_revision)rbrUr;s rrzbranches..@sB$$58++C00$$$$$$rYN)r rdris_branch_pointrrrnextrev)rrrr;s `@@rbranchesr*s ( 0 0F##%%      g ==     $$$$<>J$$$        rYctjfd}t|d5ddddS#1swxYwYdS)zDisplay the current revision for a database. :param config: a :class:`.Config` instance. :param verbose: output in verbose mode. cr7dtj|jjj|D]*}|+gS)NzCurrent revision(s) for %s:)rr obfuscate_url_pw connectionengineurlget_all_currentr)rUrVrr;rs rdisplay_versionz current..display_versionRs     -%g&8&?&CDD   ))#.. 9 9C   w 7 7 8 8 8 8 rYT)r] dont_mutateNr rdr rj)rrrr;s`` @rrrGs ( 0 0F        ?    sAAApurgec  tj| |rmg d}tj|D]S}d|vr8|dd\}}||kr||}ntjd |Tntj| fd}t| |||r|ndtj ||5 ddddS#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. .. note:: this parameter is called "revisions" in the command line interface. .. versionchanged:: 1.2 The revision may be a single revision or list of revisions when stamping multiple branch heads. :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. .. versionadded:: 1.2 NrrzMStamp operation with --sql only supports a single starting revision at a timecTtj|SrQ) _stamp_revsr to_tuple)rUrVdestination_revsr;s rdo_stampzstamp..do_stamps$!!$-0@"A"A3GGGrY)r]r^rrrr) r rdr to_listrr0appendr rrj) rrqrDrrr _revisionsrevrrr;s @@rstamprcsB ( 0 0F 2 h// / /Ii"+//#q"9"9i4''#+'+ "/A  # #I . . . . / <11HHHHHH  %(2\\d &677                         s C//C36C3rUchtj||dkrFfd}t||5ddddS#1swxYwYdS|}|st jd|z|D]}|sJt j|j dS)zEdit revision script(s) using $EDITOR. :param config: a :class:`.Config` instance. :param rev: target revision. rc|stjd|D]}tj|jgS)NzNo current revisions)r r0ropen_in_editorr)rUrVrr;s r edit_currentzedit..edit_currentsV @'(>???**3// - -#BG,,,,IrYrNz*No revision files indicated by symbol '%s') r rdr rjrr r0rr)rrUrrevsrr;s @reditrs8 ( 0 0F i      < @ @ @   NN                     ##C(( #.do_ensure_versions%%''' rY)r]r^Nr)rrDr;rs rensure_versionrs ( 0 0F        sA  AA)rr )r!F) rr r"r#r$r#r%r&r'r() NFFrAFNNNNN)rr rBrCr r&rDr&rAr#rEr&rFrCrGrCrHrCrIrCrJrKr'rL)rrrr'r()NNN) rr r}r#rBrCrFrCrHrCr'r~)FN) rr rqr#rDr&rrCr'r()NFF) rr rrCrr&rr&r'r()FF)F)rr rr&r'r()FNF) rr rqr#rDr&rrCrr&r'r()rr rUr#r'r()rr rDr&r'r()$ __future__rrtypingrrrrr rfr runtime.environmentr r;r alembic.configr alembic.script.baserrr r@rqr|rrrrrrrrrrrrarYrrs""""""  %%%%%%333333######@%%%%%%******??????IIII, QQQQQl""&"& $HL|||||~5C5C5C5Cv""& $$$$$T (((((\ +++++\...6 $" C5C5C5C5C5L    2:> CCCCCL))))BrY