Skip to content

Commit a8bfdc7

Browse files
committed
re-activate legacy-db - we need to fix and re-import missing data
1 parent 93febb6 commit a8bfdc7

File tree

3 files changed

+44
-18
lines changed

3 files changed

+44
-18
lines changed

apps/legacydb/management/commands/migrate_classrooms.py

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@ class Command(BaseCommand):
1414
help = "Migrate classrooms "
1515

1616
def handle(self, **options):
17-
migrate_classrooms()
18-
with connection.cursor() as cursor:
19-
cursor.execute(
20-
"SELECT setval(pg_get_serial_sequence('classrooms_group', 'id'), (select max(id) from classrooms_group) + 1);"
21-
)
22-
migrate_members()
23-
with connection.cursor() as cursor:
24-
cursor.execute(
25-
"SELECT setval(pg_get_serial_sequence('classrooms_membership', 'id'), (select max(id) from classrooms_membership) + 1);"
26-
)
27-
migrate_units()
28-
with connection.cursor() as cursor:
29-
cursor.execute(
30-
"SELECT setval(pg_get_serial_sequence('classrooms_unit', 'id'), (select max(id) from classrooms_unit) + 1);"
31-
)
17+
# migrate_classrooms()
18+
# with connection.cursor() as cursor:
19+
# cursor.execute(
20+
# "SELECT setval(pg_get_serial_sequence('classrooms_group', 'id'), (select max(id) from classrooms_group) + 1);"
21+
# )
22+
# migrate_members()
23+
# with connection.cursor() as cursor:
24+
# cursor.execute(
25+
# "SELECT setval(pg_get_serial_sequence('classrooms_membership', 'id'), (select max(id) from classrooms_membership) + 1);"
26+
# )
27+
# migrate_units()
28+
# with connection.cursor() as cursor:
29+
# cursor.execute(
30+
# "SELECT setval(pg_get_serial_sequence('classrooms_unit', 'id'), (select max(id) from classrooms_unit) + 1);"
31+
# )
3232
migrate_projects()
3333
with connection.cursor() as cursor:
3434
cursor.execute(
@@ -154,7 +154,7 @@ def migrate_projects():
154154
unit = Unit.objects.get(id=old_object.unit)
155155
except Unit.DoesNotExist:
156156
unit = None
157-
continue
157+
pass
158158
new_object, created = ProjectSelection.objects.get_or_create(
159159
id=old_object.id,
160160
project_id=old_object.project_id,
@@ -168,7 +168,20 @@ def migrate_projects():
168168
new_object.date_modified = old_object.updated_at or timezone.now()
169169
new_object.save()
170170
except IntegrityError:
171-
print("error: duplicate entry?")
171+
print("error: duplicate entry? id alreay exists.")
172+
print("trying without id")
173+
try:
174+
new_object, created = ProjectSelection.objects.get_or_create(
175+
# id=old_object.id,
176+
project_id=old_object.project_id,
177+
is_starter=old_object.is_starter,
178+
group=Group.objects.get(id=old_object.classroom_id)
179+
if old_object.classroom_id
180+
else None,
181+
unit=unit,
182+
)
183+
except IntegrityError:
184+
print("error: duplicate entry? failed again")
172185
except Group.DoesNotExist:
173186
print("error: group does not exist")
174187
except Unit.DoesNotExist:

docker-compose.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,16 @@ services:
6464
depends_on:
6565
- db
6666

67+
legacy-db:
68+
image: postgres:16
69+
env_file:
70+
- '.env'
71+
volumes:
72+
- ${APP_DATA_DIR?./app-data}/postgres-legacy-data:/var/lib/postgresql/data/
73+
- ${APP_DATA_DIR?./app-data}/postgres-init:/docker-entrypoint-initdb.d/
74+
healthcheck:
75+
test: pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}
76+
interval: 30s
77+
retries: 10
78+
start_period: 20s
79+
restart: unless-stopped

turtlenest/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989

9090
"apps.wp_blog",
9191

92-
#"apps.legacydb",
92+
"apps.legacydb",
9393
# only needed for migrating or looking into the legacy database
9494

9595
#"django_browser_reload",

0 commit comments

Comments
 (0)