Commit d7ab348d by Braden MacDonald

Merge pull request #18 from open-craft/hotfix-oc-639

Hotfix for OC-639: Database conflict between mentoring and problem_builder
parents b3cab3a6 7bb7d2b9
...@@ -29,10 +29,11 @@ class Answer(models.Model): ...@@ -29,10 +29,11 @@ class Answer(models.Model):
""" """
Django model used to store AnswerBlock data that need to be shared Django model used to store AnswerBlock data that need to be shared
and queried accross XBlock instances (workaround). and queried accross XBlock instances (workaround).
TODO: Deprecate this and move to edx-submissions
""" """
class Meta: class Meta:
db_table = 'mentoring_answer'
unique_together = (('student_id', 'course_id', 'name'),) unique_together = (('student_id', 'course_id', 'name'),)
name = models.CharField(max_length=50, db_index=True) name = models.CharField(max_length=50, db_index=True)
......
# -*- coding: utf-8 -*-
from south.db import db
from south.v2 import SchemaMigration
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding model 'Answer'
db.create_table('problem_builder_answer', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('name', self.gf('django.db.models.fields.CharField')(max_length=50, db_index=True)),
('student_id', self.gf('django.db.models.fields.CharField')(max_length=32, db_index=True)),
('course_id', self.gf('django.db.models.fields.CharField')(max_length=50, db_index=True)),
('student_input', self.gf('django.db.models.fields.TextField')(default='', blank=True)),
('created_on', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)),
('modified_on', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, blank=True)),
))
db.send_create_signal('problem_builder', ['Answer'])
# Adding unique constraint on 'Answer', fields ['student_id', 'course_id', 'name']
db.create_unique('problem_builder_answer', ['student_id', 'course_id', 'name'])
def backwards(self, orm):
# Removing unique constraint on 'Answer', fields ['student_id', 'course_id', 'name']
db.delete_unique('problem_builder_answer', ['student_id', 'course_id', 'name'])
# Deleting model 'Answer'
db.delete_table('problem_builder_answer')
models = {
'problem_builder.answer': {
'Meta': {'unique_together': "(('student_id', 'course_id', 'name'),)", 'object_name': 'Answer'},
'course_id': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}),
'created_on': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'modified_on': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}),
'student_id': ('django.db.models.fields.CharField', [], {'max_length': '32', 'db_index': 'True'}),
'student_input': ('django.db.models.fields.TextField', [], {'default': "''", 'blank': 'True'})
}
}
complete_apps = ['problem_builder']
# -*- coding: utf-8 -*-
from django.db.utils import DatabaseError
from south.db import db
from south.v2 import DataMigration
class Migration(DataMigration):
def forwards(self, orm):
"""
Copy student data from old table to the new one.
Problem Builder stores student answers in 'problem_builder_answer'.
However earlier versions [may have] used 'mentoring_answer'.
If a 'mentoring' app is currently installed on this instance, copy the student data over
to the new table in case it is being used.
"""
try:
db.execute(
'INSERT INTO problem_builder_answer ('
'name, student_id, course_id, student_input, created_on, modified_on '
') SELECT '
'name, student_id, course_id, student_input, created_on, modified_on '
'FROM mentoring_answer'
)
except DatabaseError: # Would like to just catch 'Table does not exist' but can't do that in a db-agnostic way
print(" - Seems like mentoring_answer does not exist. No data migration needed.")
def backwards(self, orm):
raise RuntimeError("Cannot safely reverse this migration.")
models = {
'problem_builder.answer': {
'Meta': {'unique_together': "(('student_id', 'course_id', 'name'),)", 'object_name': 'Answer'},
'course_id': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}),
'created_on': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'modified_on': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}),
'student_id': ('django.db.models.fields.CharField', [], {'max_length': '32', 'db_index': 'True'}),
'student_input': ('django.db.models.fields.TextField', [], {'default': "''", 'blank': 'True'})
}
}
complete_apps = ['problem_builder']
symmetrical = True
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment