diff --git a/lms/djangoapps/courseware/migrations/0011_csm_id_bigint.py b/lms/djangoapps/courseware/migrations/0011_csm_id_bigint.py new file mode 100644 index 0000000000..dfe8b38c69 --- /dev/null +++ b/lms/djangoapps/courseware/migrations/0011_csm_id_bigint.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.23 on 2019-08-28 15:50 +from __future__ import unicode_literals + +import courseware.fields +from django.db import migrations +from django.db.migrations import AlterField + +class CsmBigInt(AlterField): + ''' + Subclass AlterField migration class to split SQL between two different databases + We can't use the normal AlterField migration operation because Django generate and routes migrations at the model + level and the coursewarehistoryextended_studentmodulehistoryextended table is in a different database + ''' + def database_forwards(self, app_label, schema_editor, from_state, to_state): + to_model = to_state.apps.get_model(app_label, self.model_name) + if schema_editor.connection.alias == 'student_module_history': + schema_editor.execute("ALTER TABLE `coursewarehistoryextended_studentmodulehistoryextended` MODIFY `student_module_id` bigint UNSIGNED NOT NULL;") + elif self.allow_migrate_model(schema_editor.connection.alias, to_model): + schema_editor.execute("ALTER TABLE `courseware_studentmodule` MODIFY `id` bigint UNSIGNED AUTO_INCREMENT NOT NULL;") + + def database_backwards(self, app_label, schema_editor, from_state, to_state): + # Make backwards migration a no-op, app will still work if column is wider than expected + pass + +class Migration(migrations.Migration): + + dependencies = [ + ('courseware', '0010_auto_20190709_1559'), + ] + + operations = [ + CsmBigInt( + model_name='studentmodule', + name='id', + field=courseware.fields.UnsignedBigIntAutoField(primary_key=True, serialize=False), + ) + ] diff --git a/lms/djangoapps/courseware/models.py b/lms/djangoapps/courseware/models.py index cbf99df437..17bccea488 100644 --- a/lms/djangoapps/courseware/models.py +++ b/lms/djangoapps/courseware/models.py @@ -26,6 +26,7 @@ from django.db.models.signals import post_save from django.utils.translation import ugettext_lazy as _ from model_utils.models import TimeStampedModel from opaque_keys.edx.django.models import BlockTypeKeyField, CourseKeyField, UsageKeyField +from courseware.fields import UnsignedBigIntAutoField from six import text_type from six.moves import range @@ -95,6 +96,8 @@ class StudentModule(models.Model): ('sequential', 'Subsection'), ('library_content', 'Library Content')) + id = UnsignedBigIntAutoField(primary_key=True) # pylint: disable=invalid-name + ## These three are the key for the object module_type = models.CharField(max_length=32, choices=MODULE_TYPES, default='problem', db_index=True)