
    g                     X    d dl mZ d dlmZmZ d dlmZ d dlmZ ddl	m
Z
  G d d      Zy	)
    )Apps)DatabaseErrormodels)classproperty)now   )MigrationSchemaMissingc                   ^    e Zd ZdZdZed        Zd Zed        Z	d Z
d Zd Zd	 Zd
 Zd Zy)MigrationRecordera  
    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    | j                     G d dt        j                        }|| _         | j                   S )zl
        Lazy load to avoid AppRegistryNotReady if installed apps import
        MigrationRecorder.
        c                       e Zd Z ej                  d      Z ej                  d      Z ej                  e      Z	 G d d      Z
d Zy).MigrationRecorder.Migration.<locals>.Migration   )
max_length)defaultc                   "    e Zd Z e       ZdZdZy)3MigrationRecorder.Migration.<locals>.Migration.Meta
migrationsdjango_migrationsN)__name__
__module____qualname__r   apps	app_labeldb_table     u/var/www/python.vincentserveurtest.ovh/public_html/venv/lib/python3.12/site-packages/django/db/migrations/recorder.pyMetar   %   s    6D ,I2Hr   r   c                 :    d| j                   d| j                  S )Nz
Migration z for )nameappselfs    r   __str__z6MigrationRecorder.Migration.<locals>.Migration.__str__*   s    48IItxxHHr   N)r   r   r   r   	CharFieldr"   r!   DateTimeFieldr   appliedr   r%   r   r   r   	Migrationr       sH    &f&&#6'v''37.&..s;3 3
Ir   r)   )_migration_classr   Model)clsr)   s     r   r)   zMigrationRecorder.Migration   s8     'IFLL I $-C ###r   c                      || _         d| _        y )NF)
connection
_has_table)r$   r.   s     r   __init__zMigrationRecorder.__init__0   s    $r   c                 t    | j                   j                  j                  | j                  j                        S )N)r)   objectsusingr.   aliasr#   s    r   migration_qszMigrationRecorder.migration_qs4   s'    ~~%%++DOO,A,ABBr   c                 *   | j                   ry| j                  j                         5 }| j                  j                  j	                  |      }ddd       | j
                  j                  j                  v | _         | j                   S # 1 sw Y   <xY w)z2Return True if the django_migrations table exists.TN)r/   r.   cursorintrospectiontable_namesr)   _metar   )r$   r7   tabless      r   	has_tablezMigrationRecorder.has_table8   sp     ??__##%__22>>vFF & ....776A	 &%s   &B		Bc                     | j                         ry	 | j                  j                         5 }|j                  | j                         ddd       y# 1 sw Y   yxY w# t
        $ r}t        d|z        d}~ww xY w)z3Ensure the table exists and has the correct schema.Nz1Unable to create the django_migrations table (%s))r<   r.   schema_editorcreate_modelr)   r   r	   )r$   editorexcs      r   ensure_schemazMigrationRecorder.ensure_schemaE   sj     >>	..0F##DNN3 100 	(CcI 	s4   A A	A AA A 	A:'A55A:c                     | j                         r1| j                  D ci c]  }|j                  |j                  f| c}S i S c c}w )z}
        Return a dict mapping (app_name, migration_name) to Migration instances
        for all applied migrations.
        )r<   r5   r"   r!   )r$   	migrations     r   applied_migrationsz$MigrationRecorder.applied_migrationsT   sT    
 >> "&!2!2!2I 	/:!2  Is    Ac                 ^    | j                          | j                  j                  ||       y)z$Record that a migration was applied.r"   r!   N)rB   r5   creater$   r"   r!   s      r   record_appliedz MigrationRecorder.record_appliedc   s'      St 4r   c                 z    | j                          | j                  j                  ||      j                          y)z&Record that a migration was unapplied.rG   N)rB   r5   filterdeleterI   s      r   record_unappliedz"MigrationRecorder.record_unappliedh   s0      St 4;;=r   c                 T    | j                   j                         j                          y)z<Delete all migration records. Useful for testing migrations.N)r5   allrM   r#   s    r   flushzMigrationRecorder.flushm   s    &&(r   )r   r   r   __doc__r*   r   r)   r0   propertyr5   r<   rB   rE   rJ   rN   rQ   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>rY      s     % + 1 % .f) f)r   