Revert "migrations: Replace special chars in stream & user names with space."

This reverts commit acebd3a5e, as well as a subsequent fixup commit
0975bebac "quick fix: Fix migrations to be linear."

These changes need more work and thought before they're ready to
deploy on any large established Zulip server, such as zulipchat.com.
See discussion on #6534.

In place of the removed migration, leave behind a placeholder so
`manage.py migrate` doesn't get confused on installs where it was
already applied.
This commit is contained in:
Greg Price 2017-12-19 16:06:09 -08:00
parent 9a75a10d48
commit 0b3a414be1
1 changed files with 5 additions and 37 deletions

View File

@ -1,39 +1,5 @@
# -*- coding: utf-8 -*-
from django.db import models, migrations
from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor
from django.db.migrations.state import StateApps
from typing import Text
def remove_special_chars_from_streamname(apps, schema_editor):
# type: (StateApps, DatabaseSchemaEditor) -> None
Stream = apps.get_model('zerver', 'Stream')
NAME_INVALID_CHARS = ['*', '@', '`', '#']
for stream in Stream.objects.all():
if (set(stream.name).intersection(NAME_INVALID_CHARS)):
for char in NAME_INVALID_CHARS:
stream.name = stream.name.replace(char, ' ').strip()
while Stream.objects.filter(name__iexact=stream.name, realm=stream.realm).exists():
stream.name = stream.name + '^'
if len(stream.name) > 60:
# extremely unlikely, so just do something valid
stream.name = stream.name[-60:]
stream.save(update_fields=['name'])
def remove_special_chars_from_username(apps, schema_editor):
# type: (StateApps, DatabaseSchemaEditor) -> None
UserProfile = apps.get_model('zerver', 'UserProfile')
NAME_INVALID_CHARS = ['*', '`', '>', '"', '@', '#']
for userprofile in UserProfile.objects.all():
if (set(userprofile.full_name).intersection(NAME_INVALID_CHARS)):
for char in NAME_INVALID_CHARS:
userprofile.full_name = userprofile.full_name.replace(char, ' ').strip()
userprofile.save(update_fields=['full_name'])
if (set(userprofile.short_name).intersection(NAME_INVALID_CHARS)):
for char in NAME_INVALID_CHARS:
userprofile.short_name = userprofile.short_name.replace(char, ' ').strip()
userprofile.save(update_fields=['short_name'])
from django.db import migrations
class Migration(migrations.Migration):
@ -42,6 +8,8 @@ class Migration(migrations.Migration):
]
operations = [
migrations.RunPython(remove_special_chars_from_streamname),
migrations.RunPython(remove_special_chars_from_username),
# There was a migration here, which wasn't ready for wide deployment
# and was backed out. This placeholder is left behind to avoid
# confusing the migration engine on any installs that applied the
# migration. (Fortunately no reverse migration is needed.)
]