Skip to content

Commit

Permalink
Migrate qualifiers to plain charfield step 2
Browse files Browse the repository at this point in the history
Copy qualifiers to qualifiers_temp

Reference: aboutcode-org#1327
Signed-off-by: Philippe Ombredanne <[email protected]>
  • Loading branch information
pombredanne authored and TG1999 committed Dec 26, 2023
1 parent 420dfc9 commit 39d52c8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
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", "0044_package_qualifiers_temp"),
]

operations = [
migrations.RunPython(copy_qualifiers, reverse_code=migrations.RunPython.noop),
]
2 changes: 1 addition & 1 deletion vulnerabilities/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ class Package(PackageURLMixin):
"""
"""
- X schema migration: create qualifiers_temp
- data migration copy as string the normalized qualifiers to qualifiers_temp
- X data migration copy as string the normalized qualifiers to qualifiers_temp
- schema migration: add qualifiers_temp to unique together
- schema migration: remove qualifiers override and from unique together
- data migration copy as string the normalized qualifiers_temp to qualifiers
Expand Down

0 comments on commit 39d52c8

Please sign in to comment.