File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed
vulnerabilities/migrations Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -12,9 +12,17 @@ class Migration(migrations.Migration):
1212
1313 def save_vulnerability_id (apps , schema_editor ):
1414 Vulnerabilities = apps .get_model ("vulnerabilities" , "Vulnerability" )
15+ updatables = []
1516 for vulnerability in Vulnerabilities .objects .filter (~ Q (vulnerability_id__startswith = "VCID-" )):
1617 vulnerability .vulnerability_id = build_vcid ()
17- vulnerability .save ()
18+ updatables .append (vulnerability )
19+ # update in bulk, 500 at a time
20+ updated = Vulnerabilities .objects .bulk_update (
21+ objs = updatables ,
22+ fields = ["vulnerability_id" ],
23+ batch_size = 500 ,
24+ )
25+ print (f"Migrated { updated } vulnerabilities to new VCID" )
1826
1927 operations = [
2028 migrations .RunPython (save_vulnerability_id , migrations .RunPython .noop )
You can’t perform that action at this time.
0 commit comments