-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switches
FileDistribution
use Distribution
pulpcore==3.12 introduces a new MasterModel named `Distribution` designed to replace the `BaseDistribution` MasterModel. This PR switches the `FileDistribution` to use `Distribution`. It also ships a migration which moves the data from the `BaseDistribution` table to the `Distribution` field. Required PR: pulp/pulpcore#1198 closes #8387
- Loading branch information
Showing
5 changed files
with
94 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Switches ``FileDistribution`` to inherit from ``Distribution`` instead of ``BaseDistribution``. | ||
Additionally ship a migration which moves the data from ``BaseDistribution`` to ``Distribution``. |
76 changes: 76 additions & 0 deletions
76
pulp_file/app/migrations/0009_move_data_to_new_master_distribution_model.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,76 @@ | ||
# Generated by Django 2.2.19 on 2021-03-19 17:42 | ||
|
||
from django.db import connection, migrations, models, transaction | ||
import django.db.models.deletion | ||
|
||
|
||
pks_to_delete = [] | ||
|
||
|
||
def migrate_data_from_old_master_model_to_new_master_model(apps, schema_editor): | ||
FileDistribution = apps.get_model('file', 'FileDistribution') | ||
CoreDistribution = apps.get_model('core', 'Distribution') | ||
for old_file_distribution in FileDistribution.objects.all(): | ||
with transaction.atomic(): | ||
new_master_model_entry = CoreDistribution( | ||
pulp_id=old_file_distribution.pulp_id, | ||
pulp_created=old_file_distribution.pulp_created, | ||
pulp_last_updated=old_file_distribution.pulp_last_updated, | ||
pulp_type=old_file_distribution.pulp_type, | ||
name=old_file_distribution.name, | ||
base_path=old_file_distribution.base_path, | ||
content_guard=old_file_distribution.content_guard, | ||
remote=old_file_distribution.remote, | ||
publication=old_file_distribution.publication, | ||
) | ||
new_master_model_entry.save() | ||
old_file_distribution.distribution_ptr = new_master_model_entry | ||
old_file_distribution.save() | ||
pks_to_delete.append(old_file_distribution.pulp_id) | ||
|
||
|
||
def delete_remaining_old_master_model_entries(apps, schema_editor): | ||
with connection.cursor() as cursor: | ||
for pk in pks_to_delete: | ||
cursor.execute("DELETE from core_basedistribution WHERE pulp_id = %s", [pk]) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0062_add_new_distribution_mastermodel'), | ||
('file', '0008_add_manifest_field'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='filedistribution', | ||
name='distribution_ptr', | ||
field=models.OneToOneField(auto_created=True, null=True, default=None, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
parent_link=True, primary_key=False, | ||
related_name='file_filedistribution', serialize=False, | ||
to='core.Distribution'), | ||
preserve_default=False, | ||
), | ||
migrations.RunPython(migrate_data_from_old_master_model_to_new_master_model), | ||
migrations.RemoveField( | ||
model_name='filedistribution', | ||
name='basedistribution_ptr', | ||
), | ||
migrations.AlterField( | ||
model_name='filedistribution', | ||
name='distribution_ptr', | ||
field=models.OneToOneField(auto_created=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
parent_link=True, primary_key=True, | ||
related_name='file_filedistribution', serialize=False, | ||
to='core.Distribution'), | ||
preserve_default=False, | ||
), | ||
migrations.RemoveField( | ||
model_name='filedistribution', | ||
name='publication', | ||
), | ||
migrations.RunPython(delete_remaining_old_master_model_entries), | ||
] |
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