-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Work around PostgreSQL index issue Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
- Loading branch information
Showing
5 changed files
with
527 additions
and
3 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
vulnerabilities/migrations/0004_advisory_unique_content_id.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,19 @@ | ||
# Generated by Django 4.0.2 on 2022-03-28 19:29 | ||
|
||
from django.db import migrations | ||
from django.db import models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("vulnerabilities", "0003_alter_advisory_created_by"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="advisory", | ||
name="unique_content_id", | ||
field=models.CharField(blank=True, max_length=32), | ||
), | ||
] |
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,37 @@ | ||
# Generated by Django 4.0.2 on 2022-03-28 19:29 | ||
|
||
import hashlib | ||
import json | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
def md5hash(apps, schema_editor): | ||
Advisory = apps.get_model("vulnerabilities", "Advisory") | ||
for advisory in Advisory.objects.all(): | ||
hash = "" | ||
if advisory.summary: | ||
hash = hashlib.md5(advisory.summary.encode("utf-8")).hexdigest() | ||
json_fields = [advisory.affected_packages, advisory.references] | ||
# Case 1: a ="Hello" and b="World" | ||
# Case 2: a ="HelloWo" and b="rld" | ||
# hash(a) + hash(b) for both the cases will give same result | ||
# hash( hash(a) + hash(b) ) is better than hash(a + b) | ||
for json_field in json_fields: | ||
if json_field: | ||
hash = hashlib.md5( | ||
( | ||
hash + hashlib.md5(json.dumps(json_field).encode("utf-8")).hexdigest() | ||
).encode("utf-8") | ||
).hexdigest() | ||
advisory.unique_content_id = hash | ||
advisory.save() | ||
|
||
dependencies = [ | ||
("vulnerabilities", "0004_advisory_unique_content_id"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(md5hash), | ||
] |
17 changes: 17 additions & 0 deletions
17
vulnerabilities/migrations/0006_alter_advisory_unique_together.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,17 @@ | ||
# Generated by Django 4.0.2 on 2022-03-28 19:34 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("vulnerabilities", "0005_auto_20220328_1929"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterUniqueTogether( | ||
name="advisory", | ||
unique_together={("aliases", "unique_content_id", "date_published")}, | ||
), | ||
] |
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
Oops, something went wrong.