
    h                     X    S SK Jr  S SKJrJr  S SKJr  S SKJr  SSK	J
r
   " S S5      rg	)
    )Apps)DatabaseErrormodels)classproperty)now   )MigrationSchemaMissingc                   f    \ rS rSrSrSr\S 5       rS r\	S 5       r
S rS rS	 rS
 rS rS rSrg)MigrationRecorder	   a  
Deal with storing migration records in the database.

Because this table is actually itself used for dealing with model
creation, it's the one thing we can't do normally via migrations.
We manually handle table creation/schema updating (using schema backend)
and then have a floating model to do queries with.

If a migration is unapplied its row is removed from the table. Having
a row in the table always means a migration is applied.
Nc                 r    U R                   c   " S S[        R                  5      nXl         U R                   $ )zT
Lazy load to avoid AppRegistryNotReady if installed apps import
MigrationRecorder.
c                       \ rS rSr\R
                  " SS9r\R
                  " SS9r\R                  " \	S9r
 " S S5      rS rSrg	)
.MigrationRecorder.Migration.<locals>.Migration       )
max_length)defaultc                   *    \ rS rSr\" 5       rSrSrSrg)3MigrationRecorder.Migration.<locals>.Migration.Meta%   
migrationsdjango_migrations N)	__name__
__module____qualname____firstlineno__r   apps	app_labeldb_table__static_attributes__r       O/var/www/html/env/lib/python3.13/site-packages/django/db/migrations/recorder.pyMetar   %   s    6D ,I2Hr"   r$   c                 >    SU R                   < SU R                  < 3$ )Nz
Migration z for )nameappselfs    r#   __str__6MigrationRecorder.Migration.<locals>.Migration.__str__*   s    48IItxxHHr"   r   N)r   r   r   r   r   	CharFieldr'   r&   DateTimeFieldr   appliedr$   r*   r!   r   r"   r#   	Migrationr       sB    &&#6''37 ..s;3 3
Ir"   r/   )_migration_classr   Model)clsr/   s     r#   r/   MigrationRecorder.Migration   s6     'IFLL I $- ###r"   c                     Xl         SU l        g )NF)
connection
_has_table)r)   r5   s     r#   __init__MigrationRecorder.__init__0   s    $r"   c                 t    U R                   R                  R                  U R                  R                  5      $ )N)r/   objectsusingr5   aliasr(   s    r#   migration_qsMigrationRecorder.migration_qs4   s'    ~~%%++DOO,A,ABBr"   c                 @   U R                   (       a  gU R                  R                  5        nU R                  R                  R	                  U5      nSSS5        U R
                  R                  R                  W;   U l         U R                   $ ! , (       d  f       NB= f)z2Return True if the django_migrations table exists.TN)r6   r5   cursorintrospectiontable_namesr/   _metar    )r)   r@   tabless      r#   	has_tableMigrationRecorder.has_table8   sp     ??__##%__22>>vFF & ....776A	 &%s   &B
Bc                    U R                  5       (       a  g U R                  R                  5        nUR                  U R                  5        SSS5        g! , (       d  f       g= f! [
         a  n[        SU-  5      eSnAff = f)z3Ensure the table exists and has the correct schema.Nz1Unable to create the django_migrations table (%s))rE   r5   schema_editorcreate_modelr/   r   r	   )r)   editorexcs      r#   ensure_schemaMigrationRecorder.ensure_schemaE   sm     >>	..0F##DNN3 100 	(CcI 	s4   A( AA( 
A%!A( %A( (
B2B  Bc                     U R                  5       (       a4  U R                   Vs0 s H  nUR                  UR                  4U_M     sn$ 0 $ s  snf )ze
Return a dict mapping (app_name, migration_name) to Migration instances
for all applied migrations.
)rE   r=   r'   r&   )r)   	migrations     r#   applied_migrations$MigrationRecorder.applied_migrationsT   sW    
 >> "&!2!2!2I 	/:!2  Is   #Ac                 V    U R                  5         U R                  R                  XS9  g)z$Record that a migration was applied.r'   r&   N)rL   r=   creater)   r'   r&   s      r#   record_applied MigrationRecorder.record_appliedc   s%      S 4r"   c                 r    U R                  5         U R                  R                  XS9R                  5         g)z&Record that a migration was unapplied.rS   N)rL   r=   filterdeleterU   s      r#   record_unapplied"MigrationRecorder.record_unappliedh   s.      S 4;;=r"   c                 T    U R                   R                  5       R                  5         g)z<Delete all migration records. Useful for testing migrations.N)r=   allrZ   r(   s    r#   flushMigrationRecorder.flushm   s    &&(r"   )r6   r5   )r   r   r   r   __doc__r0   r   r/   r7   propertyr=   rE   rL   rP   rV   r[   r_   r!   r   r"   r#   r   r   	   sZ    
 $ $.  C C5
>
)r"   r   N)django.apps.registryr   	django.dbr   r   django.utils.functionalr   django.utils.timezoner   
exceptionsr	   r   r   r"   r#   <module>rh      s     % + 1 % .f) f)r"   