-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
36 additions
and
35 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
36 changes: 36 additions & 0 deletions
36
milestones/migrations/0002_data__seed_relationship_types.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,36 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
from milestones.data import fetch_milestone_relationship_types | ||
|
||
|
||
def seed_relationship_types(apps, schema_editor): | ||
"""Seed the relationship types.""" | ||
MilestoneRelationshipType = apps.get_model("milestones", "MilestoneRelationshipType") | ||
db_alias = schema_editor.connection.alias | ||
for name in fetch_milestone_relationship_types().values(): | ||
MilestoneRelationshipType.objects.using(db_alias).get_or_create( | ||
name=name, | ||
description='Autogenerated milestone relationship type "{}"'.format(name), | ||
) | ||
|
||
|
||
def delete_relationship_types(apps, schema_editor): | ||
"""Clean up any relationships we made.""" | ||
MilestoneRelationshipType = apps.get_model("milestones", "MilestoneRelationshipType") | ||
db_alias = schema_editor.connection.alias | ||
for name in fetch_milestone_relationship_types().values(): | ||
MilestoneRelationshipType.objects.using(db_alias).filter(name=name).delete() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('milestones', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(seed_relationship_types, delete_relationship_types), | ||
] |