-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add missing migration for vulnerability.status Signed-off-by: Philippe Ombredanne <[email protected]> * Migrate qualifiers to plain charfield step 1 Create qualifiers_temp temp field Reference: #1327 Signed-off-by: Philippe Ombredanne <[email protected]> * Migrate qualifiers to plain charfield step 2 Copy qualifiers to qualifiers_temp Reference: #1327 Signed-off-by: Philippe Ombredanne <[email protected]> * Add qualifiers_temp in unique_together step 3 Signed-off-by: Tushar Goel <[email protected]> * Remove qualifiers from qunique_together step 4 Signed-off-by: Tushar Goel <[email protected]> * Copy qualifiers_temp to qualifiers step 5 Signed-off-by: Tushar Goel <[email protected]> * Add qualifiers in unique_together step 6 Signed-off-by: Tushar Goel <[email protected]> * Delete qualifiers_temp and remove it from unique_togther step 7 Signed-off-by: Tushar Goel <[email protected]> * Formatting changes Signed-off-by: Tushar Goel <[email protected]> * Correct the 0045 migration Signed-off-by: Tushar Goel <[email protected]> * Migrate qualifiers to plain charfield step 1 Create qualifiers_temp temp field Reference: #1327 Signed-off-by: Philippe Ombredanne <[email protected]> * Migrate qualifiers to plain charfield step 2 Copy qualifiers to qualifiers_temp Reference: #1327 Signed-off-by: Philippe Ombredanne <[email protected]> * Add qualifiers_temp in unique_together step 3 Reference: #1327 Signed-off-by: Tushar Goel <[email protected]> Signed-off-by: Philippe Ombredanne <[email protected]> * Remove qualifiers from unique_together step 4 Reference: #1327 Signed-off-by: Tushar Goel <[email protected]> Signed-off-by: Philippe Ombredanne <[email protected]> * Copy qualifiers_temp to qualifiers step 5 Reference: #1327 Signed-off-by: Tushar Goel <[email protected]> Signed-off-by: Philippe Ombredanne <[email protected]> * Add qualifiers in unique_together step 6 Reference: #1327 Signed-off-by: Tushar Goel <[email protected]> Signed-off-by: Philippe Ombredanne <[email protected]> * Delete qualifiers_temp field and unique_togther step 7 Reference: #1327 Signed-off-by: Tushar Goel <[email protected]> Signed-off-by: Philippe Ombredanne <[email protected]> * Format models.py Signed-off-by: Tushar Goel <[email protected]> * Remove dupe Packages from qualifiers Signed-off-by: Philippe Ombredanne <[email protected]> * Remove dupe Packages from ns/name Signed-off-by: Philippe Ombredanne <[email protected]> * Correct migrations and add tests Signed-off-by: Tushar Goel <[email protected]> * Fix tests Signed-off-by: Tushar Goel <[email protected]> * Update tests Signed-off-by: Tushar Goel <[email protected]> * Fix tests Signed-off-by: Tushar Goel <[email protected]> * Remove tests for warts Signed-off-by: Tushar Goel <[email protected]> * Add changelog Signed-off-by: Tushar Goel <[email protected]> * Update PR according to recent changes Signed-off-by: Tushar Goel <[email protected]> * Update tests Signed-off-by: Tushar Goel <[email protected]> * Address review comments Signed-off-by: Tushar Goel <[email protected]> --------- Signed-off-by: Philippe Ombredanne <[email protected]> Signed-off-by: Tushar Goel <[email protected]> Co-authored-by: Philippe Ombredanne <[email protected]>
- Loading branch information
1 parent
e2b60c9
commit 5932722
Showing
83 changed files
with
8,168 additions
and
8,065 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
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
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
48 changes: 48 additions & 0 deletions
48
vulnerabilities/migrations/0045_remove_duplicated_purls_with_same_qualifiers.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,48 @@ | ||
# Generated by Django 4.1.13 on 2023-12-05 14:54 | ||
|
||
from itertools import groupby | ||
|
||
from django.db import migrations | ||
from django.db.models import Count | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
def remove_dupes(apps, schema_editor): | ||
""" | ||
Remove duplicated Package with the same purl and the same "serialized" | ||
qualifiers. Some qualifiers have been stored in the JSON field as | ||
dicts/objects and some have been seralized as query strings/normalized | ||
qualifiers and then just stored as a JSON string. | ||
We are keeping the JSON dict over the string variant. | ||
""" | ||
Package = apps.get_model("vulnerabilities", "Package") | ||
|
||
duplicates = ( | ||
Package.objects | ||
.exclude(qualifiers__in=("", None, {})) | ||
.values_list("package_url") | ||
.order_by("package_url") | ||
.annotate(count_id=Count("id")) | ||
.filter(count_id__gt=1) | ||
) | ||
to_delete = [] | ||
# Get all rows with the same purl, | ||
# delete the qualifier(s) that are a string | ||
# and keep the others | ||
for purl, _cid in duplicates: | ||
for package in Package.objects.filter(package_url=purl): | ||
if isinstance(package.qualifiers, str): | ||
to_delete.append(package.id) | ||
|
||
deleted, _ = Package.objects.filter(id__in=to_delete).delete() | ||
print(f"Deleted {deleted} duplicated Packages") | ||
|
||
dependencies = [ | ||
("vulnerabilities", "0044_alter_packagechangelog_options_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(remove_dupes, reverse_code=migrations.RunPython.noop), | ||
] |
18 changes: 18 additions & 0 deletions
18
vulnerabilities/migrations/0046_package_qualifiers_temp.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,18 @@ | ||
# Generated by Django 4.1.13 on 2023-12-05 11:40 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("vulnerabilities", "0045_remove_duplicated_purls_with_same_qualifiers"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="package", | ||
name="qualifiers_temp", | ||
field=models.CharField(blank=True, max_length=1024), | ||
), | ||
] |
36 changes: 36 additions & 0 deletions
36
vulnerabilities/migrations/0047_copy_qualifiers_to_qualifiers_temp.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,36 @@ | ||
# Generated by Django 4.1.13 on 2023-12-05 11:42 | ||
|
||
from django.db import migrations | ||
from packageurl import normalize_qualifiers | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
def copy_qualifiers(apps, schema_editor): | ||
""" | ||
Bulk update qualifiers_temp from the legacy JSON field | ||
""" | ||
Package = apps.get_model("vulnerabilities", "Package") | ||
updatables = [] | ||
for package in Package.objects.all(): | ||
qualifiers = package.qualifiers | ||
normalized_string = normalize_qualifiers(qualifiers, encode=True) or "" | ||
package.qualifiers_temp = normalized_string | ||
updatables.append(package) | ||
|
||
updated = Package.objects.bulk_update( | ||
objs = updatables, | ||
fields=["qualifiers_temp",], | ||
batch_size=500, | ||
) | ||
print(f"Copied {updated} qualifiers to qualifiers_temp") | ||
|
||
|
||
|
||
dependencies = [ | ||
("vulnerabilities", "0046_package_qualifiers_temp"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(copy_qualifiers, reverse_code=migrations.RunPython.noop), | ||
] |
19 changes: 19 additions & 0 deletions
19
vulnerabilities/migrations/0048_alter_package_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,19 @@ | ||
# Generated by Django 4.1.7 on 2023-12-05 13:42 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("vulnerabilities", "0047_copy_qualifiers_to_qualifiers_temp"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterUniqueTogether( | ||
name="package", | ||
unique_together={ | ||
("type", "namespace", "name", "version", "qualifiers", "subpath", "qualifiers_temp") | ||
}, | ||
), | ||
] |
28 changes: 28 additions & 0 deletions
28
vulnerabilities/migrations/0049_alter_package_unique_together_and_more.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,28 @@ | ||
# Generated by Django 4.1.7 on 2023-12-05 13:43 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("vulnerabilities", "0048_alter_package_unique_together"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterUniqueTogether( | ||
name="package", | ||
unique_together={ | ||
("type", "namespace", "name", "version", "subpath", "qualifiers_temp") | ||
}, | ||
), | ||
migrations.AlterField( | ||
model_name="package", | ||
name="qualifiers", | ||
field=models.CharField( | ||
blank=True, | ||
help_text="Extra qualifying data for a package such as the name of an OS, architecture, distro, etc.", | ||
max_length=1024, | ||
), | ||
), | ||
] |
35 changes: 35 additions & 0 deletions
35
vulnerabilities/migrations/0050_copy_qualifiers_temp_back_to_qualifiers.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,35 @@ | ||
# Generated by Django 4.1.13 on 2023-12-05 11:42 | ||
|
||
from django.db import migrations | ||
from packageurl import normalize_qualifiers | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
def copy_qualifiers_temp(apps, schema_editor): | ||
""" | ||
Bulk update qualifiers_temp from the legacy JSON field | ||
""" | ||
Package = apps.get_model("vulnerabilities", "Package") | ||
updatables = [] | ||
for package in Package.objects.all(): | ||
qualifiers_temp = package.qualifiers_temp | ||
package.qualifiers = qualifiers_temp | ||
updatables.append(package) | ||
|
||
updated = Package.objects.bulk_update( | ||
objs = updatables, | ||
fields=["qualifiers",], | ||
batch_size=500, | ||
) | ||
print(f"Copied {updated} qualifiers_temp to qualifiers") | ||
|
||
|
||
|
||
dependencies = [ | ||
("vulnerabilities", "0049_alter_package_unique_together_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(copy_qualifiers_temp, reverse_code=migrations.RunPython.noop), | ||
] |
21 changes: 21 additions & 0 deletions
21
vulnerabilities/migrations/0051_alter_package_unique_together_and_more.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,21 @@ | ||
# Generated by Django 4.1.13 on 2023-12-19 09:21 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("vulnerabilities", "0050_copy_qualifiers_temp_back_to_qualifiers"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterUniqueTogether( | ||
name="package", | ||
unique_together={("type", "namespace", "name", "version", "qualifiers", "subpath")}, | ||
), | ||
migrations.RemoveField( | ||
model_name="package", | ||
name="qualifiers_temp", | ||
), | ||
] |
Oops, something went wrong.