-
Notifications
You must be signed in to change notification settings - Fork 30
/
0040_auto_20221122_0613.py
39 lines (29 loc) · 1.27 KB
/
0040_auto_20221122_0613.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Generated by Django 4.1.1 on 2022-11-22 06:13
from django.db import migrations, connection
def populate_concept_id_in_localized_texts(apps, schema_editor):
import time
start = time.time()
"""
1. Populates concept_id in localized_texts table using concepts_names (many-to-many).
2. After this migration:
- localized_texts table will have concept_id for each name
- localized_texts without any concept_id can be deleted, as they are all descriptions which were migrated earlier
"""
with connection.cursor() as cursor:
cursor.execute("select concept_id, localizedtext_id from concepts_names;")
names = cursor.fetchall()
statement = f"update localized_texts as l set concept_id = n.concept_id from (values"
for name in names:
statement += f'{name},'
if statement.endswith(','):
statement = statement[:-1]
statement += ') as n(concept_id, localizedtext_id) where n.localizedtext_id = l.id;'
cursor.execute(statement)
print('Time: ', time.time() - start)
class Migration(migrations.Migration):
dependencies = [
('concepts', '0039_auto_20221122_0552'),
]
operations = [
migrations.RunPython(populate_concept_id_in_localized_texts)
]