Skip to content

Commit 01a4091

Browse files
kdmccormickclaude
andcommitted
chore: rename ComponentVersionMedia DB column _key -> path
Renames the underlying database column for ComponentVersionMedia.path from the legacy '_key' name to 'path'. Uses SeparateDatabaseAndState with RunSQL (RENAME COLUMN) for SQLite/MySQL compatibility. Part of: #322 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 9972303 commit 01a4091

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

src/openedx_content/applets/components/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ class ComponentVersionMedia(models.Model):
243243
media = models.ForeignKey(Media, on_delete=models.RESTRICT)
244244

245245
# path is a local file-path-like identifier for the media within a
246-
# ComponentVersion. The DB column is still named "_key" (renamed later).
247-
path = ref_field(db_column="_key")
246+
# ComponentVersion.
247+
path = ref_field()
248248

249249
class Meta:
250250
constraints = [
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from django.db import migrations
2+
3+
import openedx_django_lib.fields
4+
5+
6+
class Migration(migrations.Migration):
7+
"""
8+
Rename the underlying DB column for ComponentVersionMedia.path from
9+
'_key' to 'path'. Uses SeparateDatabaseAndState with RunSQL for
10+
SQLite/MySQL compatibility. The table is named
11+
'openedx_content_componentversionmedia' (Django default).
12+
"""
13+
14+
dependencies = [
15+
('openedx_content', '0016_rename_componentversionmedia_key_to_path'),
16+
]
17+
18+
operations = [
19+
migrations.SeparateDatabaseAndState(
20+
state_operations=[
21+
migrations.AlterField(
22+
model_name='componentversionmedia',
23+
name='path',
24+
field=openedx_django_lib.fields.MultiCollationCharField(
25+
db_collations={'mysql': 'utf8mb4_bin', 'sqlite': 'BINARY'},
26+
max_length=500,
27+
),
28+
),
29+
],
30+
database_operations=[
31+
migrations.RunSQL(
32+
sql='ALTER TABLE openedx_content_componentversionmedia RENAME COLUMN _key TO path',
33+
reverse_sql='ALTER TABLE openedx_content_componentversionmedia RENAME COLUMN path TO _key',
34+
),
35+
],
36+
),
37+
]

0 commit comments

Comments
 (0)