This commit is contained in:
2026-05-11 03:27:21 +03:30
parent cf7cbb937c
commit d0e68a1a56
854 changed files with 102985 additions and 76 deletions
@@ -0,0 +1,32 @@
"""
Management command: اجرای یک‌بار rename اپ label از soil_data به location_data در DB.
این دستور را یک بار قبل از اجرای migrate اجرا کنید:
python manage.py rename_soil_data_label
python manage.py migrate
"""
from django.core.management.base import BaseCommand
from django.db import connection
class Command(BaseCommand):
help = "Rename app label from soil_data to location_data in django_migrations and django_content_type"
def handle(self, *args, **options):
with connection.cursor() as cursor:
cursor.execute(
"UPDATE django_migrations SET app = %s WHERE app = %s",
["location_data", "soil_data"],
)
migrations_updated = cursor.rowcount
cursor.execute(
"UPDATE django_content_type SET app_label = %s WHERE app_label = %s",
["location_data", "soil_data"],
)
content_types_updated = cursor.rowcount
self.stdout.write(
self.style.SUCCESS(
f"Done. django_migrations rows updated: {migrations_updated}, "
f"django_content_type rows updated: {content_types_updated}"
)
)
@@ -0,0 +1,35 @@
from django.core.management.base import BaseCommand
from django.db import connection
class Command(BaseCommand):
help = "Rename legacy soil_data tables to location_data tables when needed"
def handle(self, *args, **options):
table_map = {
"soil_data_soillocation": "location_data_soillocation",
"soil_data_soildepthdata": "location_data_soildepthdata",
}
existing_tables = set(connection.introspection.table_names())
renamed: list[str] = []
with connection.cursor() as cursor:
for old_name, new_name in table_map.items():
if new_name in existing_tables:
continue
if old_name not in existing_tables:
continue
cursor.execute(f"RENAME TABLE `{old_name}` TO `{new_name}`")
renamed.append(f"{old_name} -> {new_name}")
existing_tables.discard(old_name)
existing_tables.add(new_name)
if renamed:
self.stdout.write(
self.style.SUCCESS("Renamed legacy tables: " + ", ".join(renamed))
)
return
self.stdout.write("No legacy location_data tables needed repair.")