First step of mitigation migration
Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
18
pkg/coredata/migrations/20250327T122105Z.sql
Normal file
18
pkg/coredata/migrations/20250327T122105Z.sql
Normal file
@@ -0,0 +1,18 @@
|
||||
-- Add organization_id column to mitigations table
|
||||
ALTER TABLE mitigations ADD COLUMN organization_id TEXT;
|
||||
|
||||
-- Update mitigations to set organization_id based on framework's organization_id
|
||||
UPDATE mitigations m
|
||||
SET organization_id = f.organization_id
|
||||
FROM frameworks f
|
||||
WHERE m.framework_id = f.id;
|
||||
|
||||
-- Make organization_id NOT NULL after update
|
||||
ALTER TABLE mitigations ALTER COLUMN organization_id SET NOT NULL;
|
||||
|
||||
-- Add foreign key constraint
|
||||
ALTER TABLE mitigations ADD CONSTRAINT fk_mitigations_organization_id
|
||||
FOREIGN KEY (organization_id) REFERENCES organizations(id) ON DELETE CASCADE;
|
||||
|
||||
-- Add index for performance
|
||||
CREATE INDEX idx_mitigations_organization_id ON mitigations(organization_id);
|
||||
8
pkg/coredata/migrations/20250327T122609Z.sql
Normal file
8
pkg/coredata/migrations/20250327T122609Z.sql
Normal file
@@ -0,0 +1,8 @@
|
||||
-- Drop the foreign key constraint first
|
||||
ALTER TABLE mitigations DROP CONSTRAINT IF EXISTS fk_mitigations_framework_id;
|
||||
|
||||
-- Drop any indices on framework_id
|
||||
DROP INDEX IF EXISTS idx_mitigations_framework_id;
|
||||
|
||||
-- Remove the framework_id column
|
||||
ALTER TABLE mitigations DROP COLUMN framework_id;
|
||||
1
pkg/coredata/migrations/20250327T210900Z.sql
Normal file
1
pkg/coredata/migrations/20250327T210900Z.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE frameworks ADD COLUMN reference_id TEXT;
|
||||
2
pkg/coredata/migrations/20250327T212900Z.sql
Normal file
2
pkg/coredata/migrations/20250327T212900Z.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE controls ADD COLUMN reference_id TEXT NOT NULL DEFAULT '';
|
||||
ALTER TABLE controls ALTER COLUMN reference_id DROP DEFAULT;
|
||||
1
pkg/coredata/migrations/20250327T220600Z.sql
Normal file
1
pkg/coredata/migrations/20250327T220600Z.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE frameworks DROP COLUMN content_ref;
|
||||
1
pkg/coredata/migrations/20250327T220601Z.sql
Normal file
1
pkg/coredata/migrations/20250327T220601Z.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE frameworks DROP COLUMN version;
|
||||
19
pkg/coredata/migrations/20250607T120000Z.sql
Normal file
19
pkg/coredata/migrations/20250607T120000Z.sql
Normal file
@@ -0,0 +1,19 @@
|
||||
-- Create a new table for controls with string IDs
|
||||
CREATE TABLE controls (
|
||||
id TEXT PRIMARY KEY,
|
||||
tenant_id TEXT NOT NULL,
|
||||
framework_id TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
description TEXT NOT NULL,
|
||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
updated_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
version INTEGER NOT NULL DEFAULT 0
|
||||
);
|
||||
|
||||
CREATE TABLE controls_mitigations (
|
||||
control_id TEXT NOT NULL,
|
||||
mitigation_id TEXT NOT NULL,
|
||||
tenant_id TEXT NOT NULL,
|
||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
PRIMARY KEY (control_id, mitigation_id)
|
||||
);
|
||||
Reference in New Issue
Block a user