From 4d506016e7eab6c5707579b0e6888874e34c6504 Mon Sep 17 00:00:00 2001 From: Adam Palay Date: Wed, 4 Dec 2013 10:23:04 -0500 Subject: [PATCH 1/3] Add a backwards migration to delete the archive table --- .../0030_auto__chg_field_anonymoususerid_anonymous_user_id.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/common/djangoapps/student/migrations/0030_auto__chg_field_anonymoususerid_anonymous_user_id.py b/common/djangoapps/student/migrations/0030_auto__chg_field_anonymoususerid_anonymous_user_id.py index 3a7d53c47c..b096a9c322 100644 --- a/common/djangoapps/student/migrations/0030_auto__chg_field_anonymoususerid_anonymous_user_id.py +++ b/common/djangoapps/student/migrations/0030_auto__chg_field_anonymoususerid_anonymous_user_id.py @@ -27,6 +27,8 @@ class Migration(SchemaMigration): # Changing field 'AnonymousUserId.anonymous_user_id' db.alter_column('student_anonymoususerid', 'anonymous_user_id', self.gf('django.db.models.fields.CharField')(max_length=16, unique=True)) + db.execute("DROP TABLE student_anonymoususerid_temp_archive") + models = { 'auth.group': { 'Meta': {'object_name': 'Group'}, From e561c1354d2f9a550f2b27bb88d8e4d0f3f76203 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Wed, 4 Dec 2013 15:11:54 -0500 Subject: [PATCH 2/3] Add managemant command to generate sql to clean up tp truncated student ids in ORA db --- .../recover_truncated_anonymous_ids.py | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 common/djangoapps/student/management/commands/recover_truncated_anonymous_ids.py diff --git a/common/djangoapps/student/management/commands/recover_truncated_anonymous_ids.py b/common/djangoapps/student/management/commands/recover_truncated_anonymous_ids.py new file mode 100644 index 0000000000..09c5edce7a --- /dev/null +++ b/common/djangoapps/student/management/commands/recover_truncated_anonymous_ids.py @@ -0,0 +1,69 @@ +""" +Generate sql commands to fix truncated anonymous student ids in the ORA database +""" +import sys + +from django.core.management.base import NoArgsCommand + +from student.models import AnonymousUserId, anonymous_id_for_user + + +class Command(NoArgsCommand): + help = __doc__ + + def handle_noargs(self, **options): + """ + Reads a list of ids (newline separated) from stdin, and + dumps sql queries to run on the ORA database to fix those ids + from their truncated form to the full 32 character change. + + The following query will generate the list of ids needed to be fixed + from the ORA database: + + SELECT student_id FROM peer_grading_calibrationhistory WHERE LENGTH(student_id) = 16 + UNION SELECT student_id FROM controller_submission WHERE LENGTH(student_id) = 16 + UNION SELECT student_id FROM metrics_timing WHERE LENGTH(student_id) = 16 + UNION SELECT student_id FROM metrics_studentcourseprofile WHERE LENGTH(student_id) = 16 + UNION SELECT student_id FROM metrics_studentprofile WHERE LENGTH(student_id) = 16; + """ + + ids = [line.strip() for line in sys.stdin] + + old_ids = AnonymousUserId.objects.raw( + """ + SELECT * + FROM student_anonymoususerid_temp_archive + WHERE anonymous_user_id IN ({}) + """.format(','.join(['%s']*len(ids))), + ids + ) + + for old_id in old_ids: + new_id = anonymous_id_for_user(old_id.user, old_id.course_id) + + for table in ('peer_grading_calibrationhistory', 'controller_submission', 'metrics_timing'): + self.stdout.write( + "UPDATE {} " + "SET student_id = '{}' " + "WHERE student_id = '{}';\n".format( + table, + new_id, + old_id.anonymous_user_id, + ) + ) + + self.stdout.write( + "DELETE FROM metrics_studentcourseprofile " + "WHERE student_id = '{}' " + "AND problems_attempted = 0;\n".format(old_id.anonymous_user_id) + ) + + self.stdout.write( + "DELETE FROM metrics_studentprofile " + "WHERE student_id = '{}' " + "AND messages_sent = 0 " + "AND messages_received = 0 " + "AND average_message_feedback_length = 0 " + "AND student_is_staff_banned = 0 " + "AND student_cannot_submit_more_for_peer_grading = 0;\n".format(old_id.anonymous_user_id) + ) From b9926a2fd3d02c0a706ee329c781f30a949dfa75 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Wed, 4 Dec 2013 16:42:57 -0500 Subject: [PATCH 3/3] Add message explaining partial recovery --- lms/templates/instructor/staff_grading.html | 7 +++++++ .../open_ended_problems/combined_notifications.html | 7 +++++++ .../open_ended_problems/open_ended_flagged_problems.html | 7 +++++++ lms/templates/open_ended_problems/open_ended_problems.html | 7 +++++++ lms/templates/peer_grading/peer_grading.html | 7 +++++++ 5 files changed, 35 insertions(+) diff --git a/lms/templates/instructor/staff_grading.html b/lms/templates/instructor/staff_grading.html index c1710e7b89..0b37ff545b 100644 --- a/lms/templates/instructor/staff_grading.html +++ b/lms/templates/instructor/staff_grading.html @@ -30,6 +30,13 @@ "to restore their visibility. Rest assured, no student " "data has been lost.")} +
+ + ${_("We have recovered the majority of student responses. " + "Those responses submitted while the issue was active are " + "temporarily unavailable, but we are working on restoring " + "them, and they should be visible again shortly.")} +

diff --git a/lms/templates/open_ended_problems/combined_notifications.html b/lms/templates/open_ended_problems/combined_notifications.html index 12776b8759..675dd77567 100644 --- a/lms/templates/open_ended_problems/combined_notifications.html +++ b/lms/templates/open_ended_problems/combined_notifications.html @@ -24,6 +24,13 @@ "to restore their visibility. Rest assured, no student " "data has been lost.")} +
+ + ${_("We have recovered the majority of student responses. " + "Those responses submitted while the issue was active are " + "temporarily unavailable, but we are working on restoring " + "them, and they should be visible again shortly.")} +

diff --git a/lms/templates/open_ended_problems/open_ended_flagged_problems.html b/lms/templates/open_ended_problems/open_ended_flagged_problems.html index 4e77c2651c..7cc2cfefbe 100644 --- a/lms/templates/open_ended_problems/open_ended_flagged_problems.html +++ b/lms/templates/open_ended_problems/open_ended_flagged_problems.html @@ -27,6 +27,13 @@ "to restore their visibility. Rest assured, no student " "data has been lost.")} +
+ + ${_("We have recovered the majority of student responses. " + "Those responses submitted while the issue was active are " + "temporarily unavailable, but we are working on restoring " + "them, and they should be visible again shortly.")} +

diff --git a/lms/templates/open_ended_problems/open_ended_problems.html b/lms/templates/open_ended_problems/open_ended_problems.html index 2167e31ce8..893dbb57fa 100644 --- a/lms/templates/open_ended_problems/open_ended_problems.html +++ b/lms/templates/open_ended_problems/open_ended_problems.html @@ -24,6 +24,13 @@ "to restore their visibility. Rest assured, no student " "data has been lost.")} +
+ + ${_("We have recovered the majority of student responses. " + "Those responses submitted while the issue was active are " + "temporarily unavailable, but we are working on restoring " + "them, and they should be visible again shortly.")} +

diff --git a/lms/templates/peer_grading/peer_grading.html b/lms/templates/peer_grading/peer_grading.html index 3e2a421fcb..a04b2fc9a3 100644 --- a/lms/templates/peer_grading/peer_grading.html +++ b/lms/templates/peer_grading/peer_grading.html @@ -23,6 +23,13 @@ criteria.{end_li_tag} "to restore their visibility. Rest assured, no student " "data has been lost.")} +
+ + ${_("We have recovered the majority of student responses. " + "Those responses submitted while the issue was active are " + "temporarily unavailable, but we are working on restoring " + "them, and they should be visible again shortly.")} +