From 5ecf3da6b81c2f043e8d722a14dedf567e46817d Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Thu, 29 May 2025 17:08:31 +0700 Subject: [PATCH 1/2] Add a `jsonb` column to `vulnerability_exports` table Context ------------------ We are building a PDF reporting feature in tandem with the new vulnerability dashboard. We are adding many different data visualizations to the web. You can adjust the data with various filters, such as time range. We want to show those same visualization, with the same filter states, in the PDF. To do this without having two maintain 2 separate UI component libraries (web and PDF), and keeping them in sync, we are going to send the SVGs in the body of the PDF export request, and render them in the PDF. This change ------------------ During a [spike][0], where we tested out the feasibility of this approach, we realized we would need to store the SVG data until the PDF export worker is running.[^1] Some notes about the exports: - exports are scheduled for deletion after the file is generated, so this change should not result in too much DB pressure - This jsonb data does not need to be queried or indexed [0]:https://gitlab.com/gitlab-org/gitlab/-/merge_requests/192439#note_2527778255 [^1]: You can see a recording of demo of using the SVGs to create the PDF report in [this thread][0] on the spike issue. --- epic: https://gitlab.com/groups/gitlab-org/-/epics/16989 resolve: https://gitlab.com/gitlab-org/gitlab/-/issues/546360 Changelog: added EE: true --- ...529100339_add_report_data_to_vulnerability_exports.rb | 9 +++++++++ db/schema_migrations/20250529100339 | 1 + db/structure.sql | 3 ++- 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20250529100339_add_report_data_to_vulnerability_exports.rb create mode 100644 db/schema_migrations/20250529100339 diff --git a/db/migrate/20250529100339_add_report_data_to_vulnerability_exports.rb b/db/migrate/20250529100339_add_report_data_to_vulnerability_exports.rb new file mode 100644 index 00000000000000..fe25a7040a0c91 --- /dev/null +++ b/db/migrate/20250529100339_add_report_data_to_vulnerability_exports.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddReportDataToVulnerabilityExports < Gitlab::Database::Migration[2.3] + milestone '18.1' + + def change + add_column :vulnerability_exports, :report_data, :jsonb, default: {} + end +end diff --git a/db/schema_migrations/20250529100339 b/db/schema_migrations/20250529100339 new file mode 100644 index 00000000000000..233190c2a6aadf --- /dev/null +++ b/db/schema_migrations/20250529100339 @@ -0,0 +1 @@ +a17e6be3b77107307b0103590c8601025af0b404ccbacb388f3ef56c86e25cd7 \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 6588f1ca9bdf95..fd09d321e1e0ea 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -24985,7 +24985,8 @@ CREATE TABLE vulnerability_exports ( group_id bigint, organization_id bigint NOT NULL, expires_at timestamp with time zone, - send_email boolean DEFAULT false NOT NULL + send_email boolean DEFAULT false NOT NULL, + report_data jsonb DEFAULT '{}'::jsonb ); CREATE SEQUENCE vulnerability_exports_id_seq -- GitLab From fae5f421df281256480c843bf2e285b99cf85fb6 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Tue, 3 Jun 2025 13:55:53 +0700 Subject: [PATCH 2/2] MR feedback: make column non-null --- .../20250529100339_add_report_data_to_vulnerability_exports.rb | 2 +- db/structure.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/db/migrate/20250529100339_add_report_data_to_vulnerability_exports.rb b/db/migrate/20250529100339_add_report_data_to_vulnerability_exports.rb index fe25a7040a0c91..2bae826c44dafa 100644 --- a/db/migrate/20250529100339_add_report_data_to_vulnerability_exports.rb +++ b/db/migrate/20250529100339_add_report_data_to_vulnerability_exports.rb @@ -4,6 +4,6 @@ class AddReportDataToVulnerabilityExports < Gitlab::Database::Migration[2.3] milestone '18.1' def change - add_column :vulnerability_exports, :report_data, :jsonb, default: {} + add_column :vulnerability_exports, :report_data, :jsonb, default: {}, null: false end end diff --git a/db/structure.sql b/db/structure.sql index fd09d321e1e0ea..9bedb85e12c32c 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -24986,7 +24986,7 @@ CREATE TABLE vulnerability_exports ( organization_id bigint NOT NULL, expires_at timestamp with time zone, send_email boolean DEFAULT false NOT NULL, - report_data jsonb DEFAULT '{}'::jsonb + report_data jsonb DEFAULT '{}'::jsonb NOT NULL ); CREATE SEQUENCE vulnerability_exports_id_seq -- GitLab