-
Notifications
You must be signed in to change notification settings - Fork 202
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 npm and pypa advisory
- Update the created_by field on old advisory to new pipeline_id Signed-off-by: Keshav Priyadarshi <git@keshav.space>
- Loading branch information
1 parent
c606c73
commit 759a090
Showing
4 changed files
with
122 additions
and
3 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
vulnerabilities/migrations/0063_update_npm_pypa_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,46 @@ | ||
# Generated by Django 4.2.15 on 2024-09-12 12:56 | ||
|
||
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.npm_importer import NpmImporterPipeline | ||
from vulnerabilities.pipelines.pypa_importer import PyPaImporterPipeline | ||
|
||
Advisory = apps.get_model("vulnerabilities", "Advisory") | ||
Advisory.objects.filter(created_by="vulnerabilities.importers.npm.NpmImporter").update( | ||
created_by=NpmImporterPipeline.pipeline_id | ||
) | ||
Advisory.objects.filter(created_by="vulnerabilities.importers.pypa.PyPaImporter").update( | ||
created_by=PyPaImporterPipeline.pipeline_id | ||
) | ||
|
||
|
||
|
||
def reverse_update_created_by(apps, schema_editor): | ||
from vulnerabilities.pipelines.npm_importer import NpmImporterPipeline | ||
from vulnerabilities.pipelines.pypa_importer import PyPaImporterPipeline | ||
|
||
Advisory = apps.get_model("vulnerabilities", "Advisory") | ||
Advisory.objects.filter(created_by=NpmImporterPipeline.pipeline_id).update( | ||
created_by="vulnerabilities.importers.npm.NpmImporter" | ||
) | ||
Advisory.objects.filter(created_by=PyPaImporterPipeline.pipeline_id).update( | ||
created_by="vulnerabilities.importers.pypa.PyPaImporter" | ||
) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("vulnerabilities", "0062_package_is_ghost"), | ||
] | ||
|
||
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
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