-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add data migration for old nvd advisory
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
- Loading branch information
1 parent
ee3edcb
commit 2c2dfff
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
vulnerabilities/migrations/0068_update_nvd_advisory_created_by.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,38 @@ | ||
# Generated by Django 4.2.15 on 2024-09-27 19:38 | ||
|
||
from django.db import migrations | ||
|
||
""" | ||
Update the created_by field on Advisory from the old qualified_name | ||
to the new pipeline_id. | ||
""" | ||
|
||
|
||
def update_created_by(apps, schema_editor): | ||
from vulnerabilities.pipelines.nvd_importer import NVDImporterPipeline | ||
|
||
Advisory = apps.get_model("vulnerabilities", "Advisory") | ||
Advisory.objects.filter(created_by="vulnerabilities.importers.nvd.NVDImporter").update( | ||
created_by=NVDImporterPipeline.pipeline_id | ||
) | ||
|
||
|
||
|
||
def reverse_update_created_by(apps, schema_editor): | ||
from vulnerabilities.pipelines.nvd_importer import NVDImporterPipeline | ||
|
||
Advisory = apps.get_model("vulnerabilities", "Advisory") | ||
Advisory.objects.filter(created_by=NVDImporterPipeline.pipeline_id).update( | ||
created_by="vulnerabilities.importers.nvd.NVDImporter" | ||
) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("vulnerabilities", "0067_update_github_advisory_created_by"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(update_created_by, reverse_code=reverse_update_created_by), | ||
] |
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