forked from aboutcode-org/vulnerablecode
-
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.
Migrate qualifiers to plain charfield step 2
Copy qualifiers to qualifiers_temp Reference: aboutcode-org#1327 Signed-off-by: Philippe Ombredanne <[email protected]>
- Loading branch information
1 parent
ce49cc2
commit f796919
Showing
2 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
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) | ||
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), | ||
] |
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