Skip to content

Commit

Permalink
Add data migration to uppercase all article slugs
Browse files Browse the repository at this point in the history
We currently assume that all article slugs are uppercase. However, prior
to this commit, it was possible to create articles with lowercase slugs
using the UI, which means that databases could at the point of this data
contain invalid data, i.e. lowercased slugs. This commit introduces a
data migration that uppercases all slugs, ensuring that the database is
returned to a valid state.
  • Loading branch information
sigvef committed Mar 1, 2016
1 parent 5549d9a commit 5923478
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions wikipendium/wiki/migrations/0003_auto_20160301_1703.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations


def uppercase_all_article_slugs(apps, schema_editor):
Article = apps.get_model("wikipendium__wiki", "Article")
articles = Article.objects.all()
for article in articles:
if article.slug:
article.slug = article.slug.upper()
article.save()


class Migration(migrations.Migration):

dependencies = [
('wikipendium__wiki', '0002_article_tags'),
]

operations = [
migrations.RunPython(uppercase_all_article_slugs),
]

0 comments on commit 5923478

Please sign in to comment.