
    g                       S SK Jr  S SKJr  S SKJr  S SKrS SKrS SKJr  S SKJ	r	  S SKJ
r
  S SKJr  S S	KJr  S S
KJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  SSKJ r   SSKJ!r!  SSK!J"r"  SSK#J$r$  SSK%J&r&  \(       aN  S SKJ'r'  S SKJ(r(  S S K)J*r*  S S!K)J+r+  S S"K,J-r-  S S#K.J/r/  S$S%K0J1r1  SS&K2J3r3  SS'K4J5r5  SS(K4J6r6  SS)K7J8r8  SS*K7J9r9  SS+K7J:r:  \Rv                  " \<5      r= " S, S-5      r> " S. S/5      r? " S0 S15      r@ " S2 S35      rA " S4 S55      rB " S6 S7\B5      rC " S8 S9\B5      rDg):    )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                  Z    \ rS rSrS
S jr\SS j5       rSS jrSS jrSS jr	SS jr
Srg	)_ProxyTransaction8   c                    Xl         g Nmigration_context)selfr3   s     a/Users/Alptekin/Desktop/izin_takip/venv/lib/python3.13/site-packages/alembic/runtime/migration.py__init___ProxyTransaction.__init__9   s    !2    c                .    U R                   R                  $ r1   )r3   _transactionr4   s    r5   _proxied_transaction&_ProxyTransaction._proxied_transaction<   s    %%222r8   c                h    U R                   nUc   eUR                  5         S U R                  l        g r1   )r<   rollbackr3   r:   r4   ts     r5   r?   _ProxyTransaction.rollback@   s.    %%}}	

.2+r8   c                h    U R                   nUc   eUR                  5         S U R                  l        g r1   )r<   commitr3   r:   r@   s     r5   rD   _ProxyTransaction.commitF   s.    %%}}	
.2+r8   c                    U $ r1    r;   s    r5   	__enter___ProxyTransaction.__enter__L   s    r8   c                z    U R                   b.  U R                   R                  XU5        S U R                  l        g g r1   )r<   __exit__r3   r:   )r4   type_value	tracebacks       r5   rK   _ProxyTransaction.__exit__O   s7    $$0%%..uYG26D""/ 1r8   r2   N)r3   MigrationContextreturnNone)rQ   zOptional[Transaction])rQ   rR   )rQ   r.   )rL   r   rM   r   rN   r   rQ   rR   )__name__
__module____qualname____firstlineno__r6   propertyr<   r?   rD   rH   rK   __static_attributes__rG   r8   r5   r.   r.   8   s/    3 3 3337r8   r.   c                  z   \ rS rSrSr S         SS jjr\       S               SS jj5       r\SS j5       r	 S   SS jjr
SS jrSS	 jrSSS
 jjrS S jrS!S jrS"S jrS S jr S     S#S jjr    S$S jr\S%S j5       r\S&S j5       r      S'S jr          S(S jrSrg))rP   U   a  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)

Nc                   X@l         X0l        Xl        UR                  S5      U l        UR                  SS5      nUR                  S5      nUR                  SS5      U l        UR                  SS5      U l        S U l        U(       a>  [        [        S   U R                  U5      5      U l        U R                  c   eSU l        O!X l        [        R                  " U5      U l        UR                  S	5      U l        XPl        UR                  S
S5      U l        SU;   a;  [%        UR                  S5      =(       d    [&        R(                  US   5      U l        O%UR                  S[&        R(                  5      U l        UR                  SS5      U l        UR                  SS5      U l        UR                  SS5      =U l        nUR                  SS 5      =U l        nUR                  S5      U l        [6        R8                  R;                  U5      " UU R                  U R                   UU R*                  U5      U l        U R<                  R?                  UUUR                  SS5      S9U l         [B        RE                  SU R<                  RF                  RH                  5        U R                   (       a  [B        RE                  S5        [B        RE                  SU R<                  RJ                  (       a  S5        g S5        g )Nscriptas_sqlFtransactional_ddltransaction_per_migrationon_version_applyrG   r!   fnpurgeoutput_encodingoutput_buffercompare_typeTcompare_server_defaultversion_tablealembic_versionversion_table_schemastarting_revversion_table_pk)rg   ri   rk   zContext impl %s.zGenerating static SQLzWill assume %s DDL.transactionalznon-transactional)&environment_contextoptsdialectgetr\   _transaction_per_migrationon_version_apply_callbacksr:   r   r   _stdout_connection
connection_in_external_transactionr   _get_connection_in_transaction_migrations_fnr]   rb   r   sysstdoutrd   _user_compare_type_user_compare_server_defaultrg   ri   _start_from_revr   DefaultImplget_by_dialectimplversion_table_impl_versionloginfo	__class__rS   r^   )	r4   ro   rt   rn   rm   r]   r^   rg   ri   s	            r5   r6   MigrationContext.__init__   s    $7 	15(1Cxx%0 HH%89*.(('+
' +/((3Er*J'37"&(?(?
(KDO ??...,1D)(O:::F ) HHTN 	 XXgu-
$!*) ::&'"D "&/3::!FD"&((>4"@,0HH$e-
) .2XX..
 	
] <@88"D<
 	
!$8 /3hh~.FOO227;OOKK
	 		44'!5!XX&8$? 5 
 	#TYY%8%8%A%AB;;HH,-! 99..  	

 )	
r8   c                   Uc  0 nUc  0 nU(       a;  [        U[        5      (       a  [        R                  " SU-  5      eUR                  nO}U(       a-  [
        R                  " U5      nUR                  5       " S0 UD6nOIU(       a0  [
        R                  " SU-  5      nUR                  5       " S0 UD6nOU(       d  [        S5      eUc   e[        XAXu5      $ )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.

zf'connection' argument to configure() is expected to be a sqlalchemy.engine.Connection instance, got %rz%s://z-Connection, url, or dialect_name is required.rG   )

isinstancer   r   CommandErrorro   sqla_urlmake_urlget_dialect	ExceptionrP   )	clsrt   r   dialect_namero   rm   dialect_optsrn   url_objs	            r5   	configureMigrationContext.configure   s    > <DL*f--'')*  !((G'',G))+;l;G'',(>?G))+;l;GKLL"""TOOr8   c              #    #    U R                  5       nU R                  R                  (       a,  U R                  (       a  U R                  R	                  5         O7U(       a0  U R
                  c   eU R
                  R                  5         SU l        U R                  (       du  U R                  c   eU R                  R                  5       nU R                  nUR                  SS9=U l        U R                  l        U R                  R                  5       nOSn Sv   U R                  (       dS  U R                  c   eUb  UR                  5         U R                  R                  WS9  W=U l        U R                  l        U R                  R                  (       a,  U R                  (       a  U R                  R                  5         gU(       a/  U R                  c   eU R                  R                  5       U l        gg! U R                  (       dS  U R                  c   eUb  UR                  5         U R                  R                  WS9  W=U l        U R                  l        U R                  R                  (       a,  U R                  (       a  U R                  R                  5         f U(       a/  U R                  c   eU R                  R                  5       U l        f f = f7f)aD  Enter 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_transactionr   r^   r]   emit_commitr:   rD   rt   get_isolation_levelexecution_optionsbegin
emit_begin)r4   r   current_levelbase_connection
fake_transs        r5   autocommit_block!MigrationContext.autocommit_block  s6    Z &*%D%D%F"99&&4;;II!!#'$$000$$& $D{{??... OO??AM"ooO  11,1ODOdii2 150E0E0GJJ	<;;222)%%'11$1 2  :IH$))"6yy**t{{		$$&+222$(OO$9$9$;! , ;;222)%%'11$1 2  :IH$))"6yy**t{{		$$&+222$(OO$9$9$;! ,s    DK&H  C"K& C#K##K&c                  ^  T R                   (       a
  [        5       $ T R                  R                  (       a  UT R                  :H  nOUSL nU(       d
  [        5       $ T R                  R                  (       d  U(       d   eT R
                  (       a
  [        5       $ T R                  SLnU(       a
  [        5       $ T R                  c   e[        R                  " T R                  5      T l        [        T 5      $ T R
                  (       a  [        U 4S j5       nU" 5       $ T R                  c   e[        R                  " T R                  5      T l        [        T 5      $ )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`

TNc               3  ~   >#    T R                   R                  5         S v   T R                   R                  5         g 7fr1   )r   r   r   r;   s   r5   begin_commit8MigrationContext.begin_transaction.<locals>.begin_commit  s)     		$$&		%%'s   :=)ru   r   r   r^   rq   r]   r:   rt   r   "_safe_begin_connection_transactionr.   r   )r4   _per_migrationtransaction_nowin_transactionr   s   `    r5   begin_transaction"MigrationContext.begin_transactionq  s   X ((= 99&&,0O0OOO,4O= ,,!!>{{"}$ "&!2!2$!>!&=(??666#FF OO %
 -T22[[( (
  >!??... + N N!D %T**r8   c                    U R                  5       n[        U5      S:X  a  g[        U5      S:  a#  [        R                  " SU R                  -  5      eUS   $ )af  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.

r   Nr%   zQVersion table '%s' has more than one head present; please use get_current_heads())get_current_headslenr   r   rg   r4   headss     r5   get_current_revision%MigrationContext.get_current_revision  s]      &&(u:?Z!^##1373E3EF 
 8Or8   c                   U R                   (       a  U R                  nUS:X  a  SnOeUbb  U R                  (       aQ  [        R                  " U5       Vs/ s H0  nUS;  d  M  U R                  R                  U5      R                  PM2     nn[        R                  " USS9$ U R                  (       a  [        R                  " S5      eU R                  5       (       d  gU R                  c   e[        S U R                  R                  [        U R                  R                  R                   5      5       5       5      $ s  snf )aw  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.

baseN)Nr   rG   defaultzECan't specify current_rev to context when using a database connectionc              3  ,   #    U  H
  nUS    v   M     g7f)r   NrG   ).0rows     r5   	<genexpr>5MigrationContext.get_current_heads.<locals>.<genexpr>  s      
 Fs   )r]   r|   r\   r   to_listget_revisionrevisionto_tupler   _has_version_tablert   tupleexecuter   r   cversion_num)r4   start_from_revsfrs      r5   r   "MigrationContext.get_current_heads  s   $ ;;"&"6"6N'!%+  $||N;";.0 ;DKK,,S1::;  "
 ==<<##''7  **,,*** 
..334
 
 	
"s   
D?!)D?c                p   [         R                  " U R                  5         U R                  c   eU R                  R	                  U R                  SS9  U(       aB  U R                  c   eU R                  R                  U R                  R                  5       5        S S S 5        g ! , (       d  f       g = f)NT)
checkfirst)r   _ensure_scope_for_ddlrt   r   creater   delete)r4   rb   s     r5   _ensure_version_table&MigrationContext._ensure_version_table  s~    ..t???...MM  T B222''(<(<(>? @??s   A=B''
B5c                    U R                   c   e[        R                  " U R                   U R                  U R                  5      $ r1   )rt   r   _connectable_has_tablerg   ri   r;   s    r5   r   #MigrationContext._has_version_table%  s<    ***11OOT//1J1J
 	
r8   c                    U R                  5       nU R                  (       d  U(       d  U R                  5         [        X5      nUR	                  X#5       H  nUR                  U5        M     g)a4  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   r]   r   HeadMaintainer_stamp_revsupdate_to_step)r4   script_directoryr   r   head_maintainersteps         r5   stampMigrationContext.stamp+  sU     &&({{5&&((5$00AD**40 Br8   c           
        U R                   R                  5         U R                  (       a9  U R                  (       a  [        R
                  " S5      eU R                  SS9  SnO[U R                  5       nU R                  R                  SS5      nU R                  (       d  U(       d  U(       d  U R                  5         [        X5      nU R                  c   eU R                  X 5       GH  nU R                  SS9   U R                  (       aE  UR                  (       d4  U R                  c   eU R                  R!                  U R                  5        ["        R%                  S	U5        U R                  (       a)  U R                   R'                  S
UR(                  < 35        UR*                  " S0 UD6  UR-                  U5        U R.                   H)  nU" U UR$                  [1        UR                  5      US9  M+     SSS5        GM!     U R                  (       aG  UR                  (       d5  U R                  c   eU R                  R3                  U R                  5        ggg! , (       d  f       GM  = f)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)rb   rG   dont_mutateFN)r   z
Running %sz-- Running )ctxr   r   run_args)r   start_migrationsrb   r]   r   r   r   r   rn   rp   r   rw   r   r   rt   r   r   r   r   static_output	short_logmigration_fnr   rr   setdrop)r4   kwr   r   r   r   callbacks          r5   run_migrationsMigrationContext.run_migrations;  s   * 			""$ ::{{''(KLL&&T&2E**,E))--u=K;;u[**,(5""...''4D''t'<;;'<'<  ??666MM((9t,;;II+++/>>; !!'B'  ..t4 $ ? ?H !YY!/"7"78!#	 !@' =< 58 ;;44??...MMt/  5;7 =<s   >DI''
I7	c                ^     U R                   R                  nU" 5       $ ! [         a     gf = fNF)rt   r   AttributeError)r4   meths     r5   r   +MigrationContext._in_connection_transaction  s3    	??11D 6M  		s    
,,c                :    U R                   R                  X5        g)zExecute 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r   _exec)r4   sqlr   s      r5   r   MigrationContext.execute  s     			/r8   c                R   ^  U 4S jn[         R                  " T R                  U5      $ )Nc                <   > TR                   R                  U 5        g r1   r   )	constructmultiparamsparamsr4   s      r5   dump1MigrationContext._stdout_connection.<locals>.dump  s    IIOOI&r8   )r   r#   ro   )r4   rt   r   s   `  r5   rs   #MigrationContext._stdout_connection  s!    	' "00tDDr8   c                    U R                   $ )aV  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.

)rt   r;   s    r5   bindMigrationContext.bind  s    & r8   c                R    U R                   (       a  U R                   R                  $ g)zDReturn the :class:`.Config` used by the current environment,
if any.N)rm   configr;   s    r5   r   MigrationContext.config  s"    
 ##++222r8   c                    U R                   SL a  g[        U R                   5      (       a.  U R                  U UUUR                  UR                  5      nUb  U$ U R                  R	                  X5      $ r   )rz   callabletyper   re   )r4   inspector_columnmetadata_column
user_values       r5   _compare_typeMigrationContext._compare_type  su     ""e+D++,,00  %%$$J %!!yy%%&6HHr8   c                    U R                   SL a  g[        U R                   5      (       a%  U R                  U UUUUR                  U5      nUb  U$ U R                  R	                  UUUU5      $ r   )r{   r  server_defaultr   rf   )r4   r  r  rendered_metadata_defaultrendered_column_defaultr  s         r5   _compare_server_default(MigrationContext._compare_server_default  s     ,,5D5566:: '..)J %!!yy//%#	
 	
r8   )ru   rw   r|   r:   rq   r{   rz   r   r]   rt   ro   rm   r   rr   rn   rd   rb   r\   rg   ri   r1   )
ro   r   rt   Optional[Connection]rn   zDict[str, Any]rm   Optional[EnvironmentContext]rQ   rR   )NNNNNNN)rt   r  r   zOptional[Union[str, URL]]r   Optional[str]ro   zOptional[Dialect]rm   r  r   zOptional[Dict[str, str]]rn   zOptional[Any]rQ   rP   )rQ   zIterator[None])F)r   boolrQ   z.Union[_ProxyTransaction, ContextManager[None]]rQ   r  rQ   Tuple[str, ...])rb   r  rQ   rR   rQ   r  )r   r)   r   strrQ   rR   r   r   rQ   rR   )r   zUnion[Executable, str]r   zOptional[Dict[str, Any]]rQ   rR   )rt   r  rQ   r#   )rQ   r  )rQ   zOptional[Config])r  Column[Any]r  r   rQ   r  )
r  r  r  r  r
  r  r  r  rQ   r  )rS   rT   rU   rV   __doc__r6   classmethodr   r   r   r   r   r   r   r   r   r   r   r   rs   rW   r   r   r  r  rX   rG   r8   r5   rP   rP   U   s   -h =AT
T
 )T
 	T

 :T
 
T
l  ,0)-&*%)<@15"5P(5P '5P $	5P
 #5P :5P /5P 5P 
5P 5Pn [< [<| &+b+"b+	7b+H6+
Z@
1 F0P 7;0#0 40 
	0E.E	E  (  I +I>DI	I&
%
 %
 $1	

 "/
 

r8   rP   c                  F    \ rS rSrS	S jrS
S jrS
S jrSS jrSS jrSr	g)r   i  c                0    Xl         [        U5      U l        g r1   )contextr   r   )r4   r  r   s      r5   r6   HeadMaintainer.__init__  s    Z
r8   c                   XR                   ;  d   eU R                   R                  U5        U R                  R                  R	                  U R                  R
                  R                  5       R                  [        SU-  5      S95        g )N'%s'r   )	r   addr  r   r   r   insertvaluesr   )r4   versions     r5   _insert_versionHeadMaintainer._insert_version  sm    jj(((

wLL!!((*11*6G+;< 2 	
r8   c           	     r   U R                   R                  U5        U R                  R                  R	                  U R                  R
                  R                  5       R                  U R                  R
                  R                  R                  [        SU-  5      :H  5      5      nU R                  R                  (       dt  U R                  R                  R                  (       aN  UbJ  UR                  S:w  a9  [        R                   " SXR                  R"                  UR                  4-  5      eg g g g )Nr   r%   zOOnline migration expected to match one row when deleting '%s' in '%s'; %d found)r   remover  r   r   r   r   wherer   r   r   r]   ro   supports_sane_rowcountrowcountr   r   rg   )r4   r%  rets      r5   _delete_versionHeadMaintainer._delete_version  s    

'"ll%%LL!!((*00%%''33!&7"234
 ##$$;;!## LL66EF  "   < $r8   c           	        X R                   ;  d   eU R                   R                  U5        U R                   R                  U5        U R                  R                  R                  U R                  R                  R                  5       R                  [        SU-  5      S9R                  U R                  R                  R                  R                  [        SU-  5      :H  5      5      nU R                  R                  (       du  U R                  R                  R                  (       aO  UbK  UR                   S:w  a:  ["        R$                  " SXU R                  R&                  UR                   4-  5      eg g g g )Nr   r!  r%   zWOnline migration expected to match one row when updating '%s' to '%s' in '%s'; %d found)r   r)  r"  r  r   r   r   updater$  r   r*  r   r   r]   ro   r+  r,  r   r   rg   )r4   from_to_r-  s       r5   _update_versionHeadMaintainer._update_version  s,   **$$$

% 

sll%%LL!!((*Vv| <V=U%%''33!&5.12
 ##$$;;!## t||993<<HI  "   < $r8   c                   UR                  U R                  5      (       a4  UR                  n[        R	                  SU5        U R                  U5        g UR                  U R                  5      (       a4  UR                  n[        R	                  SU5        U R                  U5        g UR                  U R                  5      (       ac  UR                  U R                  5      u  nnn[        R	                  SUUU5        U H  nU R                  U5        M     U R                  XE5        g UR                  U R                  5      (       ac  UR                  U R                  5      u  nnn[        R	                  SUUU5        U H  nU R                  U5        M     U R                  XE5        g UR                  U R                  5      u  p[        R	                  SX5        U R                  X5        g )Nzbranch delete %sznew branch insert %sz!merge, delete %s, update %s to %sz#unmerge, insert %s, update %s to %szupdate %s to %s)should_delete_branchr   delete_version_numr   debugr.  should_create_branchinsert_version_numr&  should_merge_branchesmerge_branch_identsr4  should_unmerge_branchesunmerge_branch_identsupdate_version_num)r4   r   versdelete_revsupdate_from_revupdate_to_revdelrevinsert_revsinsrevr2  r3  s              r5   r   HeadMaintainer.update_to_step3  s   $$TZZ00**DII($/  &&&tzz22**DII,d3  &''

33 ((4	II3	 &$$V, &  @))$**55
 **4::6	II5	 &$$V, &  @00<JEII'4  ,r8   )r  r   N)r  rP   r   r   rQ   rR   )r%  r  rQ   rR   )r2  r  r3  r  rQ   rR   )r   zUnion[RevisionStep, StampStep]rQ   rR   )
rS   rT   rU   rV   r6   r&  r.  r4  r   rX   rG   r8   r5   r   r     s     
.6+-r8   r   c                  $   \ rS rSr% SrS\S'    S\S'    S\S'    S\S	'    S\S
'    S\S'                SS jr\SS j5       r\SS j5       r	\SS j5       r
\SS j5       r\SS j5       r\SS j5       r\SS j5       r\SS j5       rSrg)MigrationInfoia  zExposes 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_mapc                    Xl         X l        X0l        [        R                  " USS9U l        U R
                  (       a  U R
                  S   U l        OS U l        [        R                  " USS9U l        g )NrG   r   r   )rP  rK  rL  r   r   rN  rM  rO  )r4   rP  rK  rL  up_revisionsdown_revisionss         r5   r6   MigrationInfo.__init__  s`     )$ #}}\2F"&"6"6q"9D
 #'D!%~r!Jr8   c                $    U R                   (       + $ )zTrue/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.
)rL  r;   s    r5   is_migrationMigrationInfo.is_migration  s     ==  r8   c                T    U R                   (       a  U R                  $ U R                  $ )z7Active revisions before this migration step is applied.)rK  rO  rN  r;   s    r5   source_revision_ids!MigrationInfo.source_revision_ids  s&     '+ooD""	
;?;O;O	
r8   c                T    U R                   (       a  U R                  $ U R                  $ )z6Active revisions after this migration step is applied.)rK  rN  rO  r;   s    r5   destination_revision_ids&MigrationInfo.destination_revision_ids  s&     %)OOD  	
9=9O9O	
r8   c                L    U R                   R                  U R                  5      $ )zEGet :attr:`~.MigrationInfo.up_revision_id` as
a :class:`.Revision`.

)rP  r   rM  r;   s    r5   up_revisionMigrationInfo.up_revision  s!       --d.A.ABBr8   c                L    U R                   R                  U R                  5      $ )zDGet :attr:`~.MigrationInfo.up_revision_ids` as a
:class:`.Revision`.)rP  get_revisionsrN  r;   s    r5   rR  MigrationInfo.up_revisions  s!       ..t/C/CDDr8   c                L    U R                   R                  U R                  5      $ )z[Get :attr:`~.MigrationInfo.down_revision_ids` as a tuple of
:class:`Revisions <.Revision>`.)rP  rb  rO  r;   s    r5   rS  MigrationInfo.down_revisions  s!       ..t/E/EFFr8   c                L    U R                   R                  U R                  5      $ )z\Get :attr:`~MigrationInfo.source_revision_ids` as a tuple of
:class:`Revisions <.Revision>`.)rP  rb  rY  r;   s    r5   source_revisionsMigrationInfo.source_revisions  s!       ..t/G/GHHr8   c                L    U R                   R                  U R                  5      $ )zaGet :attr:`~MigrationInfo.destination_revision_ids` as a tuple of
:class:`Revisions <.Revision>`.)rP  rb  r\  r;   s    r5   destination_revisions#MigrationInfo.destination_revisions  s!       ..t/L/LMMr8   )rO  rL  rK  rP  rM  rN  N)rP  r,   rK  r  rL  r  rR  Union[str, Tuple[str, ...]]rS  rl  rQ   rR   r  r  )rQ   zOptional[Revision])rQ   z%Tuple[Optional[_RevisionOrBase], ...])rS   rT   rU   rV   r  __annotations__r6   rW   rV  rY  r\  r_  rR  rS  rg  rj  rX   rG   r8   r5   rJ  rJ  a  sB     N6 "! %$ '& AK!K K 	K
 2K 4K 
K* ! ! 
 
 
 
 C C E E
 G G
 I I
 N Nr8   rJ  c                      \ rS rSr% S\S'   S\S'   S\S'   S\S'   \(       a
  \SS	 j5       r\SS
 j5       r\	      SS j5       r
\	      SS j5       r\SS j5       r\SS j5       rS rSrg)MigrationStepi  r  from_revisions_no_depsto_revisions_no_depsr  rK  r   r   c                    g r1   rG   r;   s    r5   docMigrationStep.doc  s    (+r8   c                .    U R                   R                  $ r1   )r   rS   r;   s    r5   nameMigrationStep.name  s      )))r8   c                    [        XS5      $ )NTRevisionStepr   rP  r\   s      r5   upgrade_from_script!MigrationStep.upgrade_from_script  s     L$77r8   c                    [        XS5      $ r   ry  r{  s      r5   downgrade_from_script#MigrationStep.downgrade_from_script  s     L%88r8   c                $    U R                   (       + $ r1   )rK  r;   s    r5   is_downgradeMigrationStep.is_downgrade  s    ??""r8   c                    U R                   < S[        R                  " U R                  5      < S[        R                  " U R                  5      < 3$ )N  -> )rv  r   format_as_commarp  rq  r;   s    r5   r   MigrationStep.short_log  s=     II  !<!<=  !:!:;
 	
r8   c                    U R                   (       aa  U R                  < S[        R                  " U R                  5      < S[        R                  " U R
                  5      < SU R                   < 3$ U R                  $ )Nr  r  z, )rs  rv  r   r  rp  rq  r   r;   s    r5   __str__MigrationStep.__str__  sU    88		$$T%@%@A$$T%>%>?	  >>!r8   rG   Nr  rQ   r  )rP  r,   r\   r(   rQ   rz  r  )rS   rT   rU   rV   rm  r   rW   rs  rv  r  r|  r  r  r   r  rX   rG   r8   r5   ro  ro    s    ++))	+ 
+* * 8&8068	8 8
 9&9069	9 9
 # # 
 
	"r8   ro  c                  Z   \ rS rSr        SS jrS rSS jr\SS j5       r\SS j5       r	\  SS j5       r
\SS j5       r\  SS	 j5       r\SS
 j5       rSS jr    SS jrSS jr    S S jrSS jrSS jrSS jrS!S jr\S"S j5       r\S"S j5       r\S#S j5       rSrg)$rz  i  c                    Xl         X l        X0l        U(       a  UR                  R                  U l        g UR                  R                  U l        g r1   )rP  r   rK  moduleupgrader   	downgrade)r4   rP  r   rK  s       r5   r6   RevisionStep.__init__  s;     ) $ ( 7 7D ( 9 9Dr8   c                T    SU R                   R                   < SU R                  < S3$ )NzRevisionStep(z, is_upgrade=))r   rK  r;   s    r5   __repr__RevisionStep.__repr__#  s     MM""OO
 	
r8   c                    [        U[        5      =(       a9    UR                  U R                  :H  =(       a    U R                  UR                  :H  $ r1   )r   rz  r   rK  r4   others     r5   __eq__RevisionStep.__eq__)  s=    ul+ 4$--/45#3#33	
r8   c                .    U R                   R                  $ r1   )r   rs  r;   s    r5   rs  RevisionStep.doc0  s    }}   r8   c                ~    U R                   (       a  U R                  R                  $ U R                  R                  4$ r1   rK  r   _normalized_down_revisionsr;   s    r5   from_revisionsRevisionStep.from_revisions4  s,    ??==;;;MM**,,r8   c                ~    U R                   (       a  U R                  R                  $ U R                  R                  4$ r1   rK  r   _versioned_down_revisionsr;   s    r5   rp  #RevisionStep.from_revisions_no_deps;  s.     ??==:::MM**,,r8   c                ~    U R                   (       a  U R                  R                  4$ U R                  R                  $ r1   r  r;   s    r5   to_revisionsRevisionStep.to_revisionsD  s,    ??MM**,,==;;;r8   c                ~    U R                   (       a  U R                  R                  4$ U R                  R                  $ r1   r  r;   s    r5   rq  !RevisionStep.to_revisions_no_depsK  s.     ??MM**,,==:::r8   c                F    [        U R                  R                  5      S:H  $ Nr%   )r   r   r  r;   s    r5   _has_scalar_down_revision&RevisionStep._has_scalar_down_revisionT  s    4==;;<AAr8   c                    U R                   (       d  gU R                  R                  U;  a  gU R                  R                  nU(       d  gU R                  U5      nU(       + $ )zA 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)r  r   r  _unmerge_to_revisions)r4   r   downrevsr  s       r5   r7  !RevisionStep.should_delete_branchX  sU       ==!!.==;;  55e<L###r8   c                   [        U5      R                  U R                  5      nU(       a{  U R                  R	                  U R                  R                  U5      SS9 Vs1 s H  nUR                  iM     nn[        [        U R                  5      R                  U5      5      nO[        U R                  5      n[        USS 5      US   U R                  S   4$ s  snf )NFcheckr   )	r   
differencer  rP  _get_ancestor_nodesrb  r   listr  )r4   r   other_headsr	ancestorsr  s         r5   r=   RevisionStep.merge_branch_identso  s     %j++D,?,?@ **>>%%33K@ ? A 

   "D''(33I>N "$"5"56N "%&2a 	
 	
s   !Cc           	        [        U5      R                  U R                  R                  /5      nU(       az  U R                  R	                  U R                  R                  U5      SS9 Vs1 s H  nUR                  iM     nn[        [        U R                  5      R                  U5      5      $ U R                   VVs1 s H\  nU R                  R	                  U R                  R                  U5      SS9  H!  nUR                  U:w  d  M  UR                  iM#     M^     nnn[        [        U R                  5      R                  U5      5      $ s  snf s  snnf )NFr  )r   r  r   rP  r  rb  r   r  )r4   r   r  r  r  to_revisions         r5   r  "RevisionStep._unmerge_to_revisions  sC   %j++T]]-C-C,DE **>>%%33K@ ? A 

   T../::9EFF $(#4#4#4K**>>%%33K@ ? A ::, 

 #4   T../::9EFF's   ,E AEEc                T    U R                  U5      nU R                  S   US   USS 4$ Nr   r  )r  r  )r4   r   r  s      r5   r?  "RevisionStep.unmerge_branch_idents  s@     11%8 "2	
 	
r8   c                    U R                   (       d  gU R                  R                  nU(       d  gUR                  U5      (       d  gg)NFT)rK  r   r  intersectionr4   r   r  s      r5   r:  !RevisionStep.should_create_branch  s:    ==;; %%h//r8   c                    U R                   (       d  gU R                  R                  n[        U5      S:  a  [        UR	                  U5      5      S:  a  ggNFr%   T)rK  r   r  r   r  r  s      r5   r<  "RevisionStep.should_merge_branches  sD    ==;;x=1U%7%7%A!BQ!Fr8   c                    U R                   (       d  gU R                  R                  nU R                  R                  U;   a  [        U5      S:  a  ggr  )r  r   r  r   r  s      r5   r>  $RevisionStep.should_unmerge_branches  s@      ==;;==!!U*s8}q/@r8   c                j   U R                   (       dJ  UR                  U R                  R                  5      n[	        U5      S:X  d   S5       e[        U5      S   nOU R                  R                  S   nU R                  (       a  X0R                  R                  4$ U R                  R                  U4$ )Nr%   z4Can't do an UPDATE because downrevision is ambiguousr   )r  r  r   r  r   r  rK  )r4   r   downrevdown_revisions       r5   r@  RevisionStep.update_version_num  s    --((88G G!FEF! M!,M MMDDQGM?? --"8"888==))=88r8   c                .    U R                   R                   $ r1   r   r;   s    r5   r8  RevisionStep.delete_version_num      }}%%%r8   c                .    U R                   R                   $ r1   r  r;   s    r5   r;  RevisionStep.insert_version_num  r  r8   c                    [        U R                  U R                  R                  U R                  R                  U R                  SS9$ )NFrP  rR  rS  rK  rL  )rJ  rP  r   r  rK  r;   s    r5   r   RevisionStep.info  s<    **//==CC
 	
r8   )rK  r   r   rP  N)rP  r,   r   r(   rK  r  rQ   rR   )r  objectrQ   r  r  r  r  r   Set[str]rQ   r  )r   r  rQ   zTuple[List[str], str, str])r   r  rQ   r  )r   r  rQ   z Tuple[str, str, Tuple[str, ...]]r   r  rQ   zTuple[str, str]r  rQ   rJ  )rS   rT   rU   rV   r6   r  r  rW   rs  r  rp  r  rq  r  r7  r=  r  r?  r:  r<  r>  r@  r8  r;  r   rX   rG   r8   r5   rz  rz    s@   	:'	:39	:GK	:		:

 ! ! - - -	- - < < ;	; ; B B$.

	#
2G0



	)

&		9" & & & & 
 
r8   rz  c                  @   \ rS rSr%  S           SS jjrSrS\S'   SS jrS r\	S 5       r
\	SS	 j5       r\	  SS
 j5       r\	  SS j5       r\	SS j5       r\	SS j5       rSS jr    SS jr    SS jrSS jrS S jrSS jrSS jr\	S!S j5       rSrg)"	StampStepi  Nc                    [         R                  " USS9U l        [         R                  " USS9U l        X0l        X@l        U R                  U l        XPl        g )NrG   r   )	r   r   r2  r3  rK  branch_movestamp_revisionr   rP  )r4   r2  r3  rK  r  rP  s         r5   r6   StampStep.__init__  sG     '+mmE2&F
$(MM#r$B$& //(r8   r  rs  c                    g r1   rG   )r4   r   s     r5   r  StampStep.stamp_revision  s    r8   c                "   [        U[        5      =(       ay    UR                  U R                  :H  =(       aY    UR                  U R                  :H  =(       a9    UR                  U R                  :H  =(       a    U R
                  UR
                  :H  $ r1   )r   r  r  r  r  rK  r  s     r5   r  StampStep.__eq__  sw    ui( 4$$(;(;;4""d&7&774 !!T%5%554 5#3#33	
r8   c                    U R                   $ r1   r2  r;   s    r5   r  StampStep.from_revisions  s    zzr8   c                    U R                   $ r1   r3  r;   s    r5   r  StampStep.to_revisions  s    xxr8   c                    U R                   $ r1   r  r;   s    r5   rp   StampStep.from_revisions_no_deps  s     zzr8   c                    U R                   $ r1   r  r;   s    r5   rq  StampStep.to_revisions_no_deps%  s     xxr8   c                V    [        U R                  5      S:X  d   eU R                  S   $ Nr%   r   r   r2  r;   s    r5   r8  StampStep.delete_version_num+  s&    4::!###zz!}r8   c                V    [        U R                  5      S:X  d   eU R                  S   $ r  r   r3  r;   s    r5   r;  StampStep.insert_version_num0  s&    488}!!!xx{r8   c                    [        U R                  5      S:X  d   e[        U R                  5      S:X  d   eU R                  S   U R                  S   4$ r  )r   r2  r3  r   s     r5   r@  StampStep.update_version_num5  sI    4::!###488}!!!zz!}dhhqk))r8   c                l    [        U R                  SS 5      U R                  S   U R                  S   4$ r  )r  r2  r3  r   s     r5   r=  StampStep.merge_branch_idents:  s7    
 Ab!"JJrNHHQK	
 	
r8   c                l    U R                   S   U R                  S   [        U R                  SS 5      4$ r  )r2  r3  r  r   s     r5   r?  StampStep.unmerge_branch_identsD  s6    
 JJqMHHRL!B 	
 	
r8   c                @    U R                   =(       a    U R                  $ r1   )r  r  r   s     r5   r7  StampStep.should_delete_branchN  s       5T%5%55r8   c                    U R                   =(       ab    U R                  =(       d$    [        U R                  5      R	                  U5      =(       a$    [        U R
                  5      R	                  U5      $ r1   )rK  r  r   r2  r  r3  r   s     r5   r:  StampStep.should_create_branchT  sO    OO 0!!FS_%?%?%F0DHH((/	
r8   c                2    [        U R                  5      S:  $ r  r  r   s     r5   r<  StampStep.should_merge_branches[  s    4::""r8   c                2    [        U R                  5      S:  $ r  r  r   s     r5   r>  !StampStep.should_unmerge_branches^  s    488}q  r8   c                    U R                   (       a  U R                  U R                  4OU R                  U R                  4u  pU R                  c   e[	        U R                  UUU R                   SS9$ )NTr  )rK  r3  r2  rP  rJ  )r4   updowns      r5   r   StampStep.infoa  sn      XXtzz"**dhh' 	
   ,,,**
 	
r8   )r  r2  rK  r   rP  r3  r1   )r2  %Optional[Union[str, Collection[str]]]r3  r  rK  r  r  r  rP  zOptional[RevisionMap]rQ   rR   r  r  r  r  )r   zUnion[Set[str], List[str]]rQ   z=Union[Tuple[List[Any], str, str], Tuple[List[str], str, str]])r   r  rQ   zTuple[str, str, List[str]]r  )r   r  rQ   zUnion[Set[str], bool]r  )rS   rT   rU   rV   r6   rs  rm  r  r  rW   r  r  rp  rq  r8  r;  r@  r=  r?  r7  r:  r<  r>  r   rX   rG   r8   r5   r  r    s;    /3)4) 3) 	)
 ) ,) 
) C
     	 
 	 
    *

/
	F


	#
6
#! 
 
r8   r  )E
__future__r   
contextlibr   r   loggingrx   typingr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   
sqlalchemyr   r   sqlalchemy.enginer   r   r   sqlalchemy.engine.strategiesr    r   r   r   util.compatr   util.sqla_compatr   r   r    sqlalchemy.engine.baser!   r"   sqlalchemy.engine.mockr#   sqlalchemy.sqlr$   environmentr&   r   r'   script.baser(   r)   script.revisionr*   r+   r,   	getLoggerrS   r   r.   rP   r   rJ  ro  rz  r  rG   r8   r5   <module>r     s    # % "  
     !            % $ - ;    # &)%125)/$-1*-!7 7:Z

 Z

zl- l-^@N @NF0" 0"f_
= _
Dv
 v
r8   