Files
app-store-optimization/skills/loki-mode/benchmarks/results/2026-01-05-10-37-54/swebench-loki-patches/django__django-15252.patch

59 lines
2.2 KiB
Diff

# django__django-15252
# Loki Mode Multi-Agent Patch
# Attempts: 1
--- a/django/db/migrations/recorder.py
+++ b/django/db/migrations/recorder.py
@@ -1,5 +1,6 @@
from django.apps.registry import Apps
from django.db import DatabaseError, models
+from django.db import router
from django.utils.functional import classproperty
from django.utils.timezone import now
@@ -62,20 +63,29 @@ class MigrationRecorder:
return self.Migration._default_manager.using(self.connection.alias)
def has_table(self):
+ if not router.allow_migrate(self.connection.alias, self.Migration):
+ return False
with self.connection.cursor() as cursor:
tables = self.connection.introspection.table_names(cursor)
return self.Migration._meta.db_table in tables
def ensure_schema(self):
"""Ensure the table exists and has the correct schema."""
+ if not router.allow_migrate(self.connection.alias, self.Migration):
+ return
if self.has_table():
return
with self.connection.schema_editor() as editor:
editor.create_model(self.Migration)
def applied_migrations(self):
- """Return a set of (app, name) of applied migrations."""
- self.ensure_schema()
+ """
+ Return a dict mapping (app_name, migration_name) to Migration instances
+ for all applied migrations.
+ """
+ if not router.allow_migrate(self.connection.alias, self.Migration):
+ return {}
if self.has_table():
return {(migration.app, migration.name): migration for migration in self.migration_qs}
else:
@@ -84,10 +94,14 @@ class MigrationRecorder:
def record_applied(self, app, name):
"""Record that a migration was applied."""
+ if not router.allow_migrate(self.connection.alias, self.Migration):
+ return
self.ensure_schema()
self.migration_qs.create(app=app, name=name)
def record_unapplied(self, app, name):
"""Record that a migration was unapplied."""
+ if not router.allow_migrate(self.connection.alias, self.Migration):
+ return
self.ensure_schema()
self.migration_qs.filter(app=app, name=name).delete()