Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Step one of adding internal support for RPKI roots to rpkid: split
Parent model into base Turtle model and derived Parent model. svn path=/branches/tk705/; revision=6367
- Loading branch information
Showing
6 changed files
with
143 additions
and
10 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('rpkidb', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Turtle', | ||
fields=[ | ||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), | ||
('parent_handle', models.SlugField(max_length=255)), | ||
('repository', models.ForeignKey(related_name='parents', to='rpkidb.Repository')), | ||
('tenant', models.ForeignKey(related_name='parents', to='rpkidb.Tenant')), | ||
], | ||
), | ||
migrations.AlterUniqueTogether( | ||
name='parent', | ||
unique_together=set([]), | ||
), | ||
migrations.RemoveField( | ||
model_name='parent', | ||
name='id', | ||
), | ||
migrations.RenameField( | ||
model_name='parent', | ||
old_name='parent_handle', | ||
new_name='old_parent_handle', | ||
), | ||
migrations.RenameField( | ||
model_name='parent', | ||
old_name='repository', | ||
new_name='old_repository', | ||
), | ||
migrations.RenameField( | ||
model_name='parent', | ||
old_name='tenant', | ||
new_name='old_tenant', | ||
), | ||
migrations.AddField( | ||
model_name='parent', | ||
name='turtle_ptr', | ||
field=models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, default=0, serialize=False, to='rpkidb.Turtle'), | ||
preserve_default=False, | ||
), | ||
migrations.AlterUniqueTogether( | ||
name='turtle', | ||
unique_together=set([('tenant', 'parent_handle')]), | ||
), | ||
] |
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,41 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
def turtle_forward(apps, schema_editor): | ||
Turtle = apps.get_model("rpkidb", "Turtle") | ||
Parent = apps.get_model("rpkidb", "Parent") | ||
db_alias = schema_editor.connection.alias | ||
for parent in Parent.objects.using(db_alias).all(): | ||
turtle = Turtle.objects.using(db_alias).create( | ||
parent_handle = parent.old_parent_handle, | ||
tenant = parent.old_tenant, | ||
repository = parent.old_repository) | ||
parent.turtle_ptr = turtle | ||
parent.save() | ||
|
||
|
||
def turtle_reverse(apps, schema_editor): | ||
Turtle = apps.get_model("rpkidb", "Turtle") | ||
Parent = apps.get_model("rpkidb", "Parent") | ||
db_alias = schema_editor.connection.alias | ||
for parent in Parent.objects.using(db_alias).all(): | ||
parent.old_parent_handle = parent.turtle_ptr.parent_handle | ||
parent.old_tenant = parent.turtle_ptr.tenant | ||
parent.old_repository = parent.turtle_ptr.repository | ||
parent.turtle_ptr = None | ||
parent.save() | ||
Turtle.objects.using(db_alias).all().delete() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('rpkidb', '0002_add_turtle'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(turtle_forward, turtle_reverse) | ||
] |
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,26 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('rpkidb', '0003_turtle_data'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='parent', | ||
name='old_parent_handle', | ||
), | ||
migrations.RemoveField( | ||
model_name='parent', | ||
name='old_repository', | ||
), | ||
migrations.RemoveField( | ||
model_name='parent', | ||
name='old_tenant', | ||
), | ||
] |
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