From 9e69ce8e7de7f779b522202bfe405b7fe84edae7 Mon Sep 17 00:00:00 2001 From: Eve Martin Date: Tue, 30 Jul 2024 15:10:54 +0000 Subject: [PATCH 1/9] add migration to clean class data --- .../common/migrations/0053_clean_class_data.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 cfl_common/common/migrations/0053_clean_class_data.py diff --git a/cfl_common/common/migrations/0053_clean_class_data.py b/cfl_common/common/migrations/0053_clean_class_data.py new file mode 100644 index 000000000..475ddfa89 --- /dev/null +++ b/cfl_common/common/migrations/0053_clean_class_data.py @@ -0,0 +1,17 @@ +from django.db import migrations, models + +def clean_dirty_data(apps: Apps, *args): + Class = apps.get_model("common", "Class") + + Class.objects.filter( + creation_time.year = 2015 + ).update(creation_time = null) + +class Migration(migrations.Migration): + dependencies = [("common", "0052_add_cse_fields")], + operations = [ + migrations.RunPython( + code=clean_dirty_data, + reverse_code=migrations.RunPython.noop, + ), + ] \ No newline at end of file From f5d0448ff3fa0cbaff9b79f9bbe07d564e90c157 Mon Sep 17 00:00:00 2001 From: Eve Martin Date: Tue, 30 Jul 2024 15:14:54 +0000 Subject: [PATCH 2/9] update django syntax --- cfl_common/common/migrations/0053_clean_class_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cfl_common/common/migrations/0053_clean_class_data.py b/cfl_common/common/migrations/0053_clean_class_data.py index 475ddfa89..95d7d283d 100644 --- a/cfl_common/common/migrations/0053_clean_class_data.py +++ b/cfl_common/common/migrations/0053_clean_class_data.py @@ -4,7 +4,7 @@ def clean_dirty_data(apps: Apps, *args): Class = apps.get_model("common", "Class") Class.objects.filter( - creation_time.year = 2015 + creation_time__year=2015 ).update(creation_time = null) class Migration(migrations.Migration): From 5ff6102f790fff13cddfe09d54f22fc4305d46a7 Mon Sep 17 00:00:00 2001 From: Eve Martin Date: Tue, 30 Jul 2024 15:19:55 +0000 Subject: [PATCH 3/9] add missing import --- cfl_common/common/migrations/0053_clean_class_data.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cfl_common/common/migrations/0053_clean_class_data.py b/cfl_common/common/migrations/0053_clean_class_data.py index 95d7d283d..41c775a70 100644 --- a/cfl_common/common/migrations/0053_clean_class_data.py +++ b/cfl_common/common/migrations/0053_clean_class_data.py @@ -1,3 +1,4 @@ +from django.apps.registry import Apps from django.db import migrations, models def clean_dirty_data(apps: Apps, *args): From 76b13880bbd1d26c45222a5091aa035af5d9ee04 Mon Sep 17 00:00:00 2001 From: Eve Martin Date: Tue, 30 Jul 2024 15:39:29 +0000 Subject: [PATCH 4/9] get rid of stray comma --- cfl_common/common/migrations/0053_clean_class_data.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cfl_common/common/migrations/0053_clean_class_data.py b/cfl_common/common/migrations/0053_clean_class_data.py index 41c775a70..59200ee2d 100644 --- a/cfl_common/common/migrations/0053_clean_class_data.py +++ b/cfl_common/common/migrations/0053_clean_class_data.py @@ -9,7 +9,11 @@ def clean_dirty_data(apps: Apps, *args): ).update(creation_time = null) class Migration(migrations.Migration): - dependencies = [("common", "0052_add_cse_fields")], + + dependencies = [ + ("common", "0052_add_cse_fields") + ] + operations = [ migrations.RunPython( code=clean_dirty_data, From f81e6cd1d96c0ab40da276c6900e4801893ee184 Mon Sep 17 00:00:00 2001 From: Eve Martin Date: Tue, 30 Jul 2024 15:43:42 +0000 Subject: [PATCH 5/9] fix syntax error --- cfl_common/common/migrations/0053_clean_class_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cfl_common/common/migrations/0053_clean_class_data.py b/cfl_common/common/migrations/0053_clean_class_data.py index 59200ee2d..7e025b923 100644 --- a/cfl_common/common/migrations/0053_clean_class_data.py +++ b/cfl_common/common/migrations/0053_clean_class_data.py @@ -6,7 +6,7 @@ def clean_dirty_data(apps: Apps, *args): Class.objects.filter( creation_time__year=2015 - ).update(creation_time = null) + ).update(creation_time = None) class Migration(migrations.Migration): From c5c1d9c36e660a82889040428dc5ed0375809588 Mon Sep 17 00:00:00 2001 From: Eve Martin Date: Wed, 31 Jul 2024 11:05:20 +0000 Subject: [PATCH 6/9] address PR comments --- cfl_common/common/migrations/0053_clean_class_data.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cfl_common/common/migrations/0053_clean_class_data.py b/cfl_common/common/migrations/0053_clean_class_data.py index 7e025b923..22f5ac248 100644 --- a/cfl_common/common/migrations/0053_clean_class_data.py +++ b/cfl_common/common/migrations/0053_clean_class_data.py @@ -1,11 +1,11 @@ from django.apps.registry import Apps from django.db import migrations, models -def clean_dirty_data(apps: Apps, *args): +def clean_early_class_data(apps: Apps, *args): Class = apps.get_model("common", "Class") Class.objects.filter( - creation_time__year=2015 + creation_time__date__gt = datetime.date(2021, 10, 15) ).update(creation_time = None) class Migration(migrations.Migration): @@ -16,7 +16,7 @@ class Migration(migrations.Migration): operations = [ migrations.RunPython( - code=clean_dirty_data, + code=clean_early_class_data, reverse_code=migrations.RunPython.noop, ), ] \ No newline at end of file From ce619cdd85787dbadf0cfcc167e2db87a3bf87a3 Mon Sep 17 00:00:00 2001 From: Eve Martin Date: Wed, 31 Jul 2024 12:08:01 +0000 Subject: [PATCH 7/9] address PR comment --- cfl_common/common/migrations/0053_clean_class_data.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cfl_common/common/migrations/0053_clean_class_data.py b/cfl_common/common/migrations/0053_clean_class_data.py index 22f5ac248..c9553607b 100644 --- a/cfl_common/common/migrations/0053_clean_class_data.py +++ b/cfl_common/common/migrations/0053_clean_class_data.py @@ -1,11 +1,13 @@ from django.apps.registry import Apps from django.db import migrations, models +from datetime import datetime + def clean_early_class_data(apps: Apps, *args): Class = apps.get_model("common", "Class") Class.objects.filter( - creation_time__date__gt = datetime.date(2021, 10, 15) + creation_time__date__lt = datetime.date(2021, 10, 15) ).update(creation_time = None) class Migration(migrations.Migration): From ec079b907bb461288730c6374d3545f63bd98306 Mon Sep 17 00:00:00 2001 From: Eve Martin Date: Wed, 31 Jul 2024 12:12:36 +0000 Subject: [PATCH 8/9] fix import --- cfl_common/common/migrations/0053_clean_class_data.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cfl_common/common/migrations/0053_clean_class_data.py b/cfl_common/common/migrations/0053_clean_class_data.py index c9553607b..9e447d5ba 100644 --- a/cfl_common/common/migrations/0053_clean_class_data.py +++ b/cfl_common/common/migrations/0053_clean_class_data.py @@ -1,13 +1,13 @@ from django.apps.registry import Apps from django.db import migrations, models -from datetime import datetime +from datetime import date def clean_early_class_data(apps: Apps, *args): Class = apps.get_model("common", "Class") Class.objects.filter( - creation_time__date__lt = datetime.date(2021, 10, 15) + creation_time__date__lt = date(2021, 10, 15) ).update(creation_time = None) class Migration(migrations.Migration): From 299c36a137baa7ac4b14f043ba9d4b12910d5845 Mon Sep 17 00:00:00 2001 From: Eve Martin Date: Wed, 31 Jul 2024 12:33:39 +0000 Subject: [PATCH 9/9] address PR comments --- cfl_common/common/migrations/0053_clean_class_data.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cfl_common/common/migrations/0053_clean_class_data.py b/cfl_common/common/migrations/0053_clean_class_data.py index 9e447d5ba..b5ea637ab 100644 --- a/cfl_common/common/migrations/0053_clean_class_data.py +++ b/cfl_common/common/migrations/0053_clean_class_data.py @@ -1,8 +1,8 @@ +from datetime import date + from django.apps.registry import Apps from django.db import migrations, models -from datetime import date - def clean_early_class_data(apps: Apps, *args): Class = apps.get_model("common", "Class")