-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: making pathway status non-nullable (#2712)
* feat: making pathway status non-nullable It gets rid of so many problems if we just do a data migration on old pathway status, and don't make any assumptions that it might be null or blank.
- Loading branch information
Showing
6 changed files
with
51 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
credentials/apps/catalog/migrations/0017_pathway_status_never_empty.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Generated by Django 4.2.19 on 2025-02-28 16:28 | ||
|
||
from django.db import migrations, models | ||
from django.db.models import Q | ||
|
||
|
||
def populate_pathway_status(apps, schema_editor): | ||
Pathway = apps.get_model("catalog", "Pathway") | ||
for pathway in Pathway.objects.filter(Q(status__isnull=True) | Q(status__exact="")): | ||
pathway.status = "published" | ||
pathway.save() | ||
|
||
|
||
def unpopulate_pathway_status(apps, schema_editor): | ||
""" | ||
We must specify a backwards migration even if it is empty, or else django will raise an | ||
exception if we try to rollback this migration. | ||
We don't want to nullify everything that's published, because we don't know | ||
that's correct. | ||
""" | ||
pass | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("catalog", "0016_pathway_status"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(populate_pathway_status, unpopulate_pathway_status), | ||
migrations.AlterField( | ||
model_name="pathway", | ||
name="status", | ||
field=models.CharField( | ||
choices=[("retired", "retired"), ("unpublished", "unpublished"), ("published", "published")], | ||
default="published", | ||
max_length=24, | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters