Migration Copy Scripts

This commit is contained in:
st01765
2026-02-06 13:09:14 +11:00
parent b695dd8054
commit 3583731231
12 changed files with 368 additions and 17 deletions
+19 -17
View File
@@ -1,24 +1,26 @@
import os
import sys
import django
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# Setup Django environment
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "busManager.settings")
django.setup()
from setup_django import *
from coord.models import Suburb as OldSuburb
from common.models import Suburb as NewSuburb
created = 0
skipped = 0
for old in OldSuburb.objects.all():
NewSuburb.objects.create(
id=old.id, # preserve PK
name=old.name,
state=old.state,
postcode=old.postcode,
distance=old.distance
obj, was_created = NewSuburb.objects.get_or_create(
id=old.id,
defaults={
"name": old.name,
"state": old.state,
"postcode": old.postcode,
"distance": old.distance,
}
)
print(f"Copied {OldSuburb.objects.count()} suburbs to common_suburb")
if was_created:
created += 1
else:
skipped += 1
print(f"Created: {created}, Skipped: {skipped}")