Skip to content

Commit c65863e

Browse files
kdmccormickclaude
andcommitted
fix(squash): squash component migrations into single migration
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent afca28f commit c65863e

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
"""
2+
Rename Component.local_key -> Component.component_code and change from key_field to code_field.
3+
"""
4+
import re
5+
6+
import django.core.validators
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', '0008_rename_collection_key_to_collection_code'),
16+
]
17+
18+
operations = [
19+
# Drop old constraint and index (reference the old field name).
20+
migrations.RemoveConstraint(
21+
model_name='component',
22+
name='oel_component_uniq_lc_ct_lk',
23+
),
24+
migrations.RemoveIndex(
25+
model_name='component',
26+
name='oel_component_idx_ct_lk',
27+
),
28+
# Rename the column.
29+
migrations.RenameField(
30+
model_name='component',
31+
old_name='local_key',
32+
new_name='component_code',
33+
),
34+
# Change from key_field (max_length=500, no validator) to code_field
35+
# (max_length=255, with regex validator).
36+
migrations.AlterField(
37+
model_name='component',
38+
name='component_code',
39+
field=openedx_django_lib.fields.MultiCollationCharField(
40+
db_collations={'mysql': 'utf8mb4_bin', 'sqlite': 'BINARY'},
41+
max_length=255,
42+
validators=[
43+
django.core.validators.RegexValidator(
44+
re.compile('^[a-zA-Z0-9_.-]+\\Z'),
45+
'Enter a valid "code name" consisting of letters, numbers, underscores, hyphens, or periods.',
46+
'invalid',
47+
),
48+
],
49+
),
50+
),
51+
# Re-add constraint and index with the new field name.
52+
migrations.AddConstraint(
53+
model_name='component',
54+
constraint=models.UniqueConstraint(
55+
fields=('learning_package', 'component_type', 'component_code'),
56+
name='oel_component_uniq_lc_ct_lk',
57+
),
58+
),
59+
migrations.AddIndex(
60+
model_name='component',
61+
index=models.Index(
62+
fields=['component_type', 'component_code'],
63+
name='oel_component_idx_ct_lk',
64+
),
65+
),
66+
]

0 commit comments

Comments
 (0)