|
| 1 | +""" |
| 2 | +Rename ComponentVersionMedia.key -> ComponentVersionMedia.path. |
| 3 | +
|
| 4 | +The field previously had db_column='_key'; this migration also renames the |
| 5 | +underlying DB column to match the new field name. |
| 6 | +""" |
| 7 | +from django.db import migrations, models |
| 8 | + |
| 9 | +import openedx_django_lib.fields |
| 10 | + |
| 11 | + |
| 12 | +class Migration(migrations.Migration): |
| 13 | + |
| 14 | + dependencies = [ |
| 15 | + ('openedx_content', '0011_rename_entity_key_and_package_key_to_refs'), |
| 16 | + ] |
| 17 | + |
| 18 | + operations = [ |
| 19 | + migrations.RemoveConstraint( |
| 20 | + model_name='componentversionmedia', |
| 21 | + name='oel_cvcontent_uniq_cv_key', |
| 22 | + ), |
| 23 | + migrations.RenameField( |
| 24 | + model_name='componentversionmedia', |
| 25 | + old_name='key', |
| 26 | + new_name='path', |
| 27 | + ), |
| 28 | + # RenameField only changes the Django field name; the DB column is still |
| 29 | + # '_key' (set via db_column). Use SeparateDatabaseAndState to rename the |
| 30 | + # actual column and drop the db_column override from state. |
| 31 | + migrations.SeparateDatabaseAndState( |
| 32 | + state_operations=[ |
| 33 | + migrations.AlterField( |
| 34 | + model_name='componentversionmedia', |
| 35 | + name='path', |
| 36 | + field=openedx_django_lib.fields.MultiCollationCharField( |
| 37 | + db_collations={'mysql': 'utf8mb4_bin', 'sqlite': 'BINARY'}, |
| 38 | + max_length=500, |
| 39 | + ), |
| 40 | + ), |
| 41 | + ], |
| 42 | + database_operations=[ |
| 43 | + migrations.RunSQL( |
| 44 | + sql='ALTER TABLE openedx_content_componentversionmedia RENAME COLUMN _key TO path', |
| 45 | + reverse_sql='ALTER TABLE openedx_content_componentversionmedia RENAME COLUMN path TO _key', |
| 46 | + ), |
| 47 | + ], |
| 48 | + ), |
| 49 | + migrations.AddConstraint( |
| 50 | + model_name='componentversionmedia', |
| 51 | + constraint=models.UniqueConstraint( |
| 52 | + fields=['component_version', 'path'], |
| 53 | + name='oel_cvcontent_uniq_cv_key', |
| 54 | + ), |
| 55 | + ), |
| 56 | + ] |
0 commit comments