Commit 04c619e4 authored by Joren Vrancken's avatar Joren Vrancken
Browse files

Merge branch 'fix/wikinamespace-migration' into 'master'

Fix #699

Closes #699

See merge request !940
parents bb340dc1 7db2095d
...@@ -11,9 +11,17 @@ def migrate_to(apps, schema_editor): ...@@ -11,9 +11,17 @@ def migrate_to(apps, schema_editor):
for board in boards: for board in boards:
TemporaryBoard.objects.create(parent=board.committee_ptr_id) TemporaryBoard.objects.create(parent=board.committee_ptr_id)
def migrate_back(apps, schema_editor): def migrate_back(apps, schema_editor):
# Reverse is not imported, objects will be deleted TemporaryBoard = apps.get_model("activemembers", "TemporaryBoard")
pass
boards = TemporaryBoard.objects.all()
for temp_board in boards:
schema_editor.execute(
'INSERT INTO activemembers_board (committee_ptr_id, is_board)'
' VALUES ({}, 1);'
.format(temp_board.parent))
class Migration(migrations.Migration): class Migration(migrations.Migration):
......
...@@ -18,21 +18,28 @@ def migrate_to(apps, schema_editor): ...@@ -18,21 +18,28 @@ def migrate_to(apps, schema_editor):
if not TemporaryBoard.objects.filter(parent=group.pk).exists(): if not TemporaryBoard.objects.filter(parent=group.pk).exists():
schema_editor.execute( schema_editor.execute(
'INSERT INTO activemembers_committee ' 'INSERT INTO activemembers_committee '
'(membergroup_ptr_id, wiki_namespace) VALUES ({}, {});' '(membergroup_ptr_id, wiki_namespace) VALUES ({}, \'{}\');'
.format(group.pk, group.wiki_namespace_old if group.wiki_namespace_old else 'NULL')) .format(group.pk, group.wiki_namespace_old if group.wiki_namespace_old else 'NULL'))
def migrate_back(apps, schema_editor): def migrate_back(apps, schema_editor):
schema_editor.execute('DELETE FROM activemembers_board;')
Committee = apps.get_model("activemembers", "Committee") Committee = apps.get_model("activemembers", "Committee")
committees = Committee.objects.all() committees = Committee.objects.all()
for committee in committees: for committee in committees:
schema_editor.execute( schema_editor.execute(
'UPDATE activemembers_membergroup ' 'UPDATE activemembers_membergroup '
'SET wiki_namespace_old={} WHERE id={}' 'SET wiki_namespace_old=\'{}\' WHERE id={}'
.format(committee.wiki_namespace if committee.wiki_namespace else 'NULL', committee.membergroup_ptr_id)) .format(committee.wiki_namespace if committee.wiki_namespace else 'NULL', committee.membergroup_ptr_id))
schema_editor.execute('DELETE FROM activemembers_committee;') schema_editor.execute('DELETE FROM activemembers_committee;')
Board = apps.get_model("activemembers", "Board")
TemporaryBoard = apps.get_model("activemembers", "TemporaryBoard")
boards = Board.objects.all()
for board in boards:
TemporaryBoard.objects.create(parent=board.membergroup_ptr_id)
schema_editor.execute('DELETE FROM activemembers_board;')
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment