-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Continued simplification of Taxonomy model, squashed migrations [FC-0030] #33438
Changes from 2 commits
1ec1985
ece987a
95a4e60
8215a5e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,54 @@ | ||||||
# Generated by Django 3.2.21 on 2023-10-09 23:12 | ||||||
|
||||||
from django.db import migrations, models | ||||||
import django.db.models.deletion | ||||||
|
||||||
|
||||||
class Migration(migrations.Migration): | ||||||
|
||||||
replaces = [ | ||||||
('content_tagging', '0001_initial'), | ||||||
('content_tagging', '0002_system_defined_taxonomies'), | ||||||
('content_tagging', '0003_system_defined_fixture'), | ||||||
('content_tagging', '0004_system_defined_org'), | ||||||
('content_tagging', '0005_auto_20230830_1517'), | ||||||
('content_tagging', '0006_simplify_models'), | ||||||
] | ||||||
|
||||||
initial = True | ||||||
|
||||||
dependencies = [ | ||||||
("oel_tagging", "0012_language_taxonomy"), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ach.. I'm afraid this line caused an issue when I was testing openedx/openedx-learning#95 :( Changing it to this fixes the issue, but means we need to merge/tag openedx/openedx-learning#95 first:
Suggested change
Here's the steps I took:
1 I always get errors about the named indexes ( |
||||||
('organizations', '0003_historicalorganizationcourse'), | ||||||
] | ||||||
|
||||||
operations = [ | ||||||
migrations.CreateModel( | ||||||
name='ContentObjectTag', | ||||||
fields=[ | ||||||
], | ||||||
options={ | ||||||
'proxy': True, | ||||||
'indexes': [], | ||||||
'constraints': [], | ||||||
}, | ||||||
bases=('oel_tagging.objecttag',), | ||||||
), | ||||||
migrations.CreateModel( | ||||||
name='TaxonomyOrg', | ||||||
fields=[ | ||||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||||||
('rel_type', models.CharField(choices=[('OWN', 'owner')], default='OWN', max_length=3)), | ||||||
('org', models.ForeignKey(default=None, help_text='Organization that is related to this taxonomy.If None, then this taxonomy is related to all organizations.', null=True, on_delete=django.db.models.deletion.CASCADE, to='organizations.organization')), | ||||||
('taxonomy', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='oel_tagging.taxonomy')), | ||||||
], | ||||||
), | ||||||
migrations.AddIndex( | ||||||
model_name='taxonomyorg', | ||||||
index=models.Index(fields=['taxonomy', 'rel_type'], name='content_tag_taxonom_b04dd1_idx'), | ||||||
), | ||||||
migrations.AddIndex( | ||||||
model_name='taxonomyorg', | ||||||
index=models.Index(fields=['taxonomy', 'rel_type', 'org'], name='content_tag_taxonom_70d60b_idx'), | ||||||
), | ||||||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,12 +38,6 @@ def load_system_defined_taxonomies(apps, schema_editor): | |
org_taxonomy.taxonomy_class = ContentOrganizationTaxonomy | ||
org_taxonomy.save() | ||
|
||
# Adding taxonomy class to the language taxonomy | ||
language_taxonomy = Taxonomy.objects.get(id=-1) | ||
ContentLanguageTaxonomy = apps.get_model("content_tagging", "ContentLanguageTaxonomy") | ||
language_taxonomy.taxonomy_class = ContentLanguageTaxonomy | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm confused.. The |
||
language_taxonomy.save() | ||
|
||
|
||
def revert_system_defined_taxonomies(apps, schema_editor): | ||
""" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from django.db import migrations | ||
|
||
|
||
def mark_language_taxonomy_as_all_orgs(apps, _schema_editor): | ||
""" | ||
Associates the system defined taxonomy Language (id=-1) to all orgs. | ||
""" | ||
TaxonomyOrg = apps.get_model("content_tagging", "TaxonomyOrg") | ||
TaxonomyOrg.objects.create(taxonomy_id=-1, org=None) | ||
bradenmacdonald marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def revert_mark_language_taxonomy_as_all_orgs(apps, _schema_editor): | ||
""" | ||
Deletes association of system defined taxonomy Language (id=-1) to all orgs. | ||
""" | ||
TaxonomyOrg = apps.get_model("content_tagging", "TaxonomyOrg") | ||
TaxonomyOrg.objects.get(taxonomy_id=-1, org=None).delete() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
('content_tagging', '0001_squashed'), | ||
("oel_tagging", "0012_language_taxonomy"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(mark_language_taxonomy_as_all_orgs, revert_mark_language_taxonomy_as_all_orgs), | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We were starting to get problems with some of these migrations, referring to models that have been deleted or depending on migrations which depended on fixtures, which were later changed or deleted (note to self: migrations should never reference fixtures). So I've squashed the migrations here which makes it much simpler and more robust. I'd really like to get the squashed version into Quince. If possible, I'd like to squash the migrations in oel_tagging too but that would be a separate PR.