Skip to content

Commit 440ab24

Browse files
authored
Merge pull request #255 from PROCOLLAB-github/fix/programs-data-migration
remove junky fields from partner_program_data
2 parents 4cbc396 + 0b77c03 commit 440ab24

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Generated by Django 4.2.3 on 2023-12-29 21:02
2+
3+
from django.db import migrations
4+
5+
6+
FIELDS_TO_DELETE = [
7+
'password',
8+
'formid',
9+
'tranid',
10+
'COOKIES',
11+
'utm_term',
12+
'utm_medium',
13+
'utm_source',
14+
'utm_content',
15+
'utm_campaign',
16+
]
17+
18+
19+
def normalize_profiles_data(apps, schema_editor):
20+
PartnerProgramUserProfile = apps.get_model("partner_programs", "PartnerProgramUserProfile")
21+
for profile in PartnerProgramUserProfile.objects.all():
22+
program_data = profile.partner_program_data
23+
if any(field in program_data for field in FIELDS_TO_DELETE):
24+
program_data['tilda'] = True
25+
26+
for field in FIELDS_TO_DELETE:
27+
if field in program_data:
28+
program_data.pop(field)
29+
profile.partner_program_data = program_data
30+
profile.save()
31+
32+
33+
def do_nothing(apps, schema_editor):
34+
pass
35+
36+
37+
class Migration(migrations.Migration):
38+
dependencies = [
39+
("partner_programs", "0003_partnerprogramuserprofile_project_and_more"),
40+
]
41+
42+
operations = [
43+
migrations.RunPython(normalize_profiles_data, reverse_code=do_nothing),
44+
]

0 commit comments

Comments
 (0)