-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switches FileDistribution
use Distribution
#484
Merged
bmbouter
merged 1 commit into
pulp:master
from
bmbouter:switch-pulp-file-distribution-to-use-new-mastermodel
Apr 1, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should really have the reverse_code here. I can do that in a follow up pr if you prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mdellweg I'm not able to put it together due to time constraints, but I think it would be great if you'd be willing to post-merge. Like we talked about at the pulpcore meeting, doing it prior to the 3.12 release would be ideal because this migration is about to get replicated across almost all plugins very soon.