forked from pulp/pulp_rpm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow two modules with same NSVCA but different snippet content.
closes pulp#3241 It no longer holds true to rely on NSVCA module's uniqueness, add the hash of the document snippet to it.
- Loading branch information
Showing
4 changed files
with
62 additions
and
4 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 @@ | ||
Adjust modules uniqueness to allow two modules with same NSVCA but different snippet content. |
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,51 @@ | ||
# Generated by Django 4.2.4 on 2023-09-04 14:06 | ||
|
||
from django.db import migrations, models | ||
import hashlib | ||
|
||
|
||
def add_snippet_hash(apps, schema_editor): | ||
"""Calculate and add digest hash of the snippet.""" | ||
|
||
Modulemd = apps.get_model("rpm", "Modulemd") | ||
modules_to_update = [] | ||
|
||
for mmd in Modulemd.objects.all().only("snippet").iterator(): | ||
digest = hashlib.sha256(mmd.snippet.encode()).hexdigest() | ||
modules_to_update.append(mmd) | ||
Modulemd.objects.bulk_update(modules_to_update, fields=["digest"]) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("rpm", "0051_alter_distributiontree_unique_together_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="modulemd", | ||
name="digest", | ||
field=models.TextField(default=""), | ||
), | ||
migrations.RunPython( | ||
code=add_snippet_hash, | ||
reverse_code=migrations.RunPython.noop, | ||
elidable=True, | ||
), | ||
migrations.AlterUniqueTogether( | ||
name="modulemd", | ||
unique_together=set(), | ||
), | ||
migrations.AlterField( | ||
model_name="modulemd", | ||
name="digest", | ||
field=models.TextField(), | ||
), | ||
migrations.AlterUniqueTogether( | ||
name="modulemd", | ||
unique_together={ | ||
("_pulp_domain", "name", "stream", "version", "context", "arch", "digest") | ||
}, | ||
), | ||
] |
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