o a @sRddlmZddlmZmZddlmZddlmZddl m Z GdddZ d S) )Apps) DatabaseErrormodels) classproperty)now)MigrationSchemaMissingc@sdeZdZdZdZeddZddZeddZ d d Z d d Z d dZ ddZ ddZddZdS)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. NcCs(|jdurGdddtj}||_|jS)zl Lazy load to avoid AppRegistryNotReady if installed apps import MigrationRecorder. Nc@sFeZdZejddZejddZejedZ GdddZ ddZ dS) z.MigrationRecorder.Migration..Migration) max_length)defaultc@seZdZeZdZdZdS)z3MigrationRecorder.Migration..Migration.Meta migrationsdjango_migrationsN)__name__ __module__ __qualname__rapps app_labeldb_tablerr?/usr/lib/python3/dist-packages/django/db/migrations/recorder.pyMeta#srcSsd|j|jfS)NzMigration %s for %s)nameappselfrrr__str__(sz6MigrationRecorder.Migration..Migration.__str__N) rrrr CharFieldrr DateTimeFieldrappliedrrrrrr Migrations     r )_migration_classrModel)clsr rrrr s  zMigrationRecorder.MigrationcCs ||_dSN) connection)rr%rrr__init__.s zMigrationRecorder.__init__cCs|jj|jjSr$)r objectsusingr%aliasrrrr migration_qs1zMigrationRecorder.migration_qscCsF|j}|jj|}Wdn1swY|jjj|vS)z2Return True if the django_migrations table exists.N)r%cursor introspection table_namesr _metar)rr,tablesrrr has_table5s zMigrationRecorder.has_tablec Csr|rdSz |j}||jWdWdS1swYWdSty8}ztd|d}~ww)z3Ensure the table exists and has the correct schema.Nz1Unable to create the django_migrations table (%s))r1r% schema_editor create_modelr rr)reditorexcrrr ensure_schema;s & zMigrationRecorder.ensure_schemacCs|r dd|jDSiS)z} Return a dict mapping (app_name, migration_name) to Migration instances for all applied migrations. cSsi|] }|j|jf|qSrrr).0 migrationrrr Nsz8MigrationRecorder.applied_migrations..)r1r*rrrrapplied_migrationsHsz$MigrationRecorder.applied_migrationscCs||jj||ddS)z$Record that a migration was applied.r7N)r6r*createrrrrrrrecord_appliedTsz MigrationRecorder.record_appliedcCs ||jj||ddS)z&Record that a migration was unapplied.r7N)r6r*filterdeleter=rrrrecord_unappliedYsz"MigrationRecorder.record_unappliedcCs|jdS)zrArCrrrrr s      r N) django.apps.registryr django.dbrrdjango.utils.functionalrdjango.utils.timezoner exceptionsrr rrrrs