Skip to content

Removes project_id from Corpus table

What does this MR do and why?

  1. Removing the project_id field as the field is not required.
  2. The Corpus table is behind the feature flag and empty so removing the column should not cause downtime.

Migration

Up:

== 20211110112949 RemoveProjectForeignKeyFromCorpus: migrating ================
-- transaction_open?()
   -> 0.0000s
-- foreign_keys(:coverage_fuzzing_corpuses)
   -> 0.0048s
-- remove_foreign_key(:coverage_fuzzing_corpuses, {:column=>:project_id})
   -> 0.0048s
== 20211110112949 RemoveProjectForeignKeyFromCorpus: migrated (0.0358s) =======

== 20211110113119 RemoveProjectIdFromCorpus: migrating ========================
-- execute("DELETE FROM coverage_fuzzing_corpuses")
   -> 0.0021s
-- column_exists?(:coverage_fuzzing_corpuses, :project_id)
   -> 0.0028s
-- remove_column(:coverage_fuzzing_corpuses, :project_id)
   -> 0.0010s
== 20211110113119 RemoveProjectIdFromCorpus: migrated (0.0060s) ===============

Down:

╰─>$ rails db:migrate:down VERSION=20211110113119 && rails db:migrate:down VERSION=20211110112949
== 20211110113119 RemoveProjectIdFromCorpus: reverting ========================
-- column_exists?(:coverage_fuzzing_corpuses, :project_id)
   -> 0.0020s
-- add_column(:coverage_fuzzing_corpuses, :project_id, :bigint, {:null=>false})
   -> 0.0012s
== 20211110113119 RemoveProjectIdFromCorpus: reverted (0.0033s) ===============

== 20211110112949 RemoveProjectForeignKeyFromCorpus: reverting ================
-- transaction_open?()
   -> 0.0000s
-- foreign_keys(:coverage_fuzzing_corpuses)
   -> 0.0040s
-- transaction_open?()
   -> 0.0000s
-- execute("ALTER TABLE coverage_fuzzing_corpuses\nADD CONSTRAINT fk_204d40056a\nFOREIGN KEY (project_id)\nREFERENCES projects (id)\nON DELETE CASCADE\nNOT VALID;\n")
   -> 0.0025s
-- execute("SET statement_timeout TO 0")
   -> 0.0006s
-- execute("ALTER TABLE coverage_fuzzing_corpuses VALIDATE CONSTRAINT fk_204d40056a;")
   -> 0.0087s
-- execute("RESET statement_timeout")
   -> 0.0005s
== 20211110112949 RemoveProjectForeignKeyFromCorpus: reverted (0.0416s) =======

How to set up and validate locally

  1. Pull the branch and run rails db:migrate.
  2. You can try creating a corpus using AppSec::Fuzzing::Coverage::Corpus.create(package_id: any_package_id)

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #343971

Edited by Aditya Tiwari

Merge request reports