Move coredata outside probo service
Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
37
pkg/coredata/migrations/20250124T113100Z.sql
Normal file
37
pkg/coredata/migrations/20250124T113100Z.sql
Normal file
@@ -0,0 +1,37 @@
|
||||
CREATE TABLE organizations (
|
||||
id UUID PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
description TEXT,
|
||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
updated_at TIMESTAMP WITH TIME ZONE NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE frameworks (
|
||||
id UUID PRIMARY KEY,
|
||||
organization_id UUID REFERENCES organizations(id) NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
description TEXT NOT NULL,
|
||||
content_ref TEXT NOT NULL,
|
||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
updated_at TIMESTAMP WITH TIME ZONE NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE controls (
|
||||
id UUID PRIMARY KEY,
|
||||
framework_id UUID REFERENCES frameworks(id) NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
description TEXT NOT NULL,
|
||||
content_ref TEXT NOT NULL,
|
||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
updated_at TIMESTAMP WITH TIME ZONE NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE tasks (
|
||||
id UUID PRIMARY KEY,
|
||||
control_id UUID REFERENCES controls(id) NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
description TEXT NOT NULL,
|
||||
content_ref TEXT NOT NULL,
|
||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
updated_at TIMESTAMP WITH TIME ZONE NOT NULL
|
||||
);
|
||||
1
pkg/coredata/migrations/20250125T212400Z.sql
Normal file
1
pkg/coredata/migrations/20250125T212400Z.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE organizations DROP COLUMN description;
|
||||
31
pkg/coredata/migrations/20250125T214100Z.sql
Normal file
31
pkg/coredata/migrations/20250125T214100Z.sql
Normal file
@@ -0,0 +1,31 @@
|
||||
ALTER TABLE frameworks DROP CONSTRAINT IF EXISTS frameworks_organization_id_fkey;
|
||||
ALTER TABLE controls DROP CONSTRAINT IF EXISTS controls_framework_id_fkey;
|
||||
ALTER TABLE tasks DROP CONSTRAINT IF EXISTS tasks_control_id_fkey;
|
||||
|
||||
ALTER TABLE organizations DROP CONSTRAINT organizations_pkey;
|
||||
ALTER TABLE organizations ALTER COLUMN id TYPE TEXT USING id::text;
|
||||
ALTER TABLE organizations ADD PRIMARY KEY (id);
|
||||
|
||||
ALTER TABLE frameworks DROP CONSTRAINT frameworks_pkey;
|
||||
ALTER TABLE frameworks ALTER COLUMN id TYPE TEXT USING id::text;
|
||||
ALTER TABLE frameworks ADD PRIMARY KEY (id);
|
||||
ALTER TABLE frameworks ALTER COLUMN organization_id TYPE TEXT USING organization_id::text;
|
||||
|
||||
ALTER TABLE controls DROP CONSTRAINT controls_pkey;
|
||||
ALTER TABLE controls ALTER COLUMN id TYPE TEXT USING id::text;
|
||||
ALTER TABLE controls ADD PRIMARY KEY (id);
|
||||
ALTER TABLE controls ALTER COLUMN framework_id TYPE TEXT USING framework_id::text;
|
||||
|
||||
ALTER TABLE tasks DROP CONSTRAINT tasks_pkey;
|
||||
ALTER TABLE tasks ALTER COLUMN id TYPE TEXT USING id::text;
|
||||
ALTER TABLE tasks ADD PRIMARY KEY (id);
|
||||
ALTER TABLE tasks ALTER COLUMN control_id TYPE TEXT USING control_id::text;
|
||||
|
||||
ALTER TABLE frameworks ADD CONSTRAINT frameworks_organization_id_fkey
|
||||
FOREIGN KEY (organization_id) REFERENCES organizations(id);
|
||||
|
||||
ALTER TABLE controls ADD CONSTRAINT controls_framework_id_fkey
|
||||
FOREIGN KEY (framework_id) REFERENCES frameworks(id);
|
||||
|
||||
ALTER TABLE tasks ADD CONSTRAINT tasks_control_id_fkey
|
||||
FOREIGN KEY (control_id) REFERENCES controls(id);
|
||||
16
pkg/coredata/migrations/20250126T141600Z.sql
Normal file
16
pkg/coredata/migrations/20250126T141600Z.sql
Normal file
@@ -0,0 +1,16 @@
|
||||
CREATE TYPE control_state AS ENUM (
|
||||
'NOT_STARTED',
|
||||
'IN_PROGRESS',
|
||||
'NOT_APPLICABLE',
|
||||
'IMPLEMENTED'
|
||||
);
|
||||
|
||||
CREATE TABLE control_state_transitions (
|
||||
id TEXT PRIMARY KEY,
|
||||
control_id TEXT REFERENCES controls(id) NOT NULL,
|
||||
from_state control_state,
|
||||
to_state control_state NOT NULL,
|
||||
reason TEXT,
|
||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
updated_at TIMESTAMP WITH TIME ZONE NOT NULL
|
||||
);
|
||||
12
pkg/coredata/migrations/20250128T093900Z.sql
Normal file
12
pkg/coredata/migrations/20250128T093900Z.sql
Normal file
@@ -0,0 +1,12 @@
|
||||
ALTER TABLE tasks
|
||||
DROP CONSTRAINT tasks_control_id_fkey,
|
||||
DROP COLUMN control_id;
|
||||
|
||||
CREATE TABLE controls_tasks (
|
||||
task_id TEXT NOT NULL,
|
||||
control_id TEXT NOT NULL,
|
||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
PRIMARY KEY (task_id, control_id),
|
||||
FOREIGN KEY (task_id) REFERENCES tasks(id),
|
||||
FOREIGN KEY (control_id) REFERENCES controls(id)
|
||||
);
|
||||
7
pkg/coredata/migrations/20250128T151500Z.sql
Normal file
7
pkg/coredata/migrations/20250128T151500Z.sql
Normal file
@@ -0,0 +1,7 @@
|
||||
CREATE TABLE evidences (
|
||||
id TEXT PRIMARY KEY,
|
||||
task_id TEXT REFERENCES tasks(id) NOT NULL,
|
||||
object_key TEXT NOT NULL,
|
||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
updated_at TIMESTAMP WITH TIME ZONE NOT NULL
|
||||
);
|
||||
6
pkg/coredata/migrations/20250130T142900Z.sql
Normal file
6
pkg/coredata/migrations/20250130T142900Z.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
CREATE TABLE vendors (
|
||||
id TEXT PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
created_at TIMESTAMP WITH TIME ZONE,
|
||||
updated_at TIMESTAMP WITH TIME ZONE
|
||||
);
|
||||
9
pkg/coredata/migrations/20250130T144500Z.sql
Normal file
9
pkg/coredata/migrations/20250130T144500Z.sql
Normal file
@@ -0,0 +1,9 @@
|
||||
CREATE TABLE peoples (
|
||||
id TEXT PRIMARY KEY,
|
||||
organization_id TEXT REFERENCES organizations(id) NOT NULL,
|
||||
full_name TEXT NOT NULL,
|
||||
primary_email_address TEXT NOT NULL,
|
||||
additional_email_addresses TEXT[] NOT NULL,
|
||||
created_at TIMESTAMP WITH TIME ZONE,
|
||||
updated_at TIMESTAMP WITH TIME ZONE
|
||||
);
|
||||
6
pkg/coredata/migrations/20250130T145600Z.sql
Normal file
6
pkg/coredata/migrations/20250130T145600Z.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
CREATE TYPE task_state AS ENUM (
|
||||
'TODO',
|
||||
'DONE'
|
||||
);
|
||||
|
||||
ALTER TABLE tasks ADD COLUMN state task_state NOT NULL;
|
||||
11
pkg/coredata/migrations/20250130T154300Z.sql
Normal file
11
pkg/coredata/migrations/20250130T154300Z.sql
Normal file
@@ -0,0 +1,11 @@
|
||||
CREATE TABLE task_state_transitions (
|
||||
id TEXT PRIMARY KEY,
|
||||
task_id TEXT REFERENCES tasks(id) NOT NULL,
|
||||
from_state task_state,
|
||||
to_state task_state NOT NULL,
|
||||
reason TEXT,
|
||||
created_at TIMESTAMP WITH TIME ZONE,
|
||||
updated_at TIMESTAMP WITH TIME ZONE
|
||||
);
|
||||
|
||||
ALTER TABLE tasks DROP COLUMN state;
|
||||
3
pkg/coredata/migrations/20250130T210000Z.sql
Normal file
3
pkg/coredata/migrations/20250130T210000Z.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
ALTER TABLE evidences
|
||||
ADD COLUMN mime_type TEXT NOT NULL,
|
||||
ADD COLUMN size NUMERIC NOT NULL;
|
||||
14
pkg/coredata/migrations/20250130T211400Z.sql
Normal file
14
pkg/coredata/migrations/20250130T211400Z.sql
Normal file
@@ -0,0 +1,14 @@
|
||||
CREATE TYPE evidence_state AS ENUM (
|
||||
'VALID',
|
||||
'INVALID',
|
||||
'EXPIRED'
|
||||
);
|
||||
|
||||
CREATE TABLE evidence_state_transitions (
|
||||
id TEXT PRIMARY KEY,
|
||||
from_state evidence_state,
|
||||
to_state evidence_state NOT NULL,
|
||||
reason TEXT,
|
||||
created_at TIMESTAMP WITH TIME ZONE,
|
||||
updated_at TIMESTAMP WITH TIME ZONE
|
||||
);
|
||||
2
pkg/coredata/migrations/20250130T212000Z.sql
Normal file
2
pkg/coredata/migrations/20250130T212000Z.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE evidence_state_transitions ADD COLUMN evidence_id TEXT REFERENCES evidences(id) NOT NULL;
|
||||
ALTER TABLE evidences ALTER COLUMN size TYPE BIGINT USING size::BIGINT;
|
||||
1
pkg/coredata/migrations/20250139T143000Z.sql
Normal file
1
pkg/coredata/migrations/20250139T143000Z.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE vendors ADD COLUMN organization_id TEXT REFERENCES organizations(id) NOT NULL;
|
||||
12
pkg/coredata/migrations/20250202T110500Z.sql
Normal file
12
pkg/coredata/migrations/20250202T110500Z.sql
Normal file
@@ -0,0 +1,12 @@
|
||||
CREATE TABLE usrmgr_users (
|
||||
id TEXT PRIMARY KEY,
|
||||
created_at TIMESTAMP NOT NULL,
|
||||
updated_at TIMESTAMP NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE usrmgr_sessions (
|
||||
id TEXT PRIMARY KEY,
|
||||
user_id TEXT NOT NULL REFERENCES usrmgr_users(id),
|
||||
created_at TIMESTAMP NOT NULL,
|
||||
updated_at TIMESTAMP NOT NULL
|
||||
);
|
||||
5
pkg/coredata/migrations/20250202T141800Z.sql
Normal file
5
pkg/coredata/migrations/20250202T141800Z.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
CREATE EXTENSION citext;
|
||||
|
||||
ALTER TABLE usrmgr_users
|
||||
ADD COLUMN email_address CITEXT NOT NULL,
|
||||
ADD COLUMN hashed_password BYTEA NOT NULL;
|
||||
1
pkg/coredata/migrations/20250202T180400Z.sql
Normal file
1
pkg/coredata/migrations/20250202T180400Z.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE usrmgr_users ADD UNIQUE (email_address);
|
||||
1
pkg/coredata/migrations/20250202T201400Z.sql
Normal file
1
pkg/coredata/migrations/20250202T201400Z.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE usrmgr_sessions ADD COLUMN expired_at TIMESTAMP WITH TIME ZONE NOT NULL;
|
||||
10
pkg/coredata/migrations/20250206T121300Z.sql
Normal file
10
pkg/coredata/migrations/20250206T121300Z.sql
Normal file
@@ -0,0 +1,10 @@
|
||||
CREATE TYPE people_kind AS ENUM (
|
||||
'EMPLOYEE',
|
||||
'CONTRACTOR'
|
||||
);
|
||||
|
||||
ALTER TABLE peoples ADD COLUMN kind people_kind;
|
||||
|
||||
UPDATE peoples SET kind = 'EMPLOYEE';
|
||||
|
||||
ALTER TABLE peoples ALTER COLUMN kind SET NOT NULL;
|
||||
5
pkg/coredata/migrations/20250209T183000Z.sql
Normal file
5
pkg/coredata/migrations/20250209T183000Z.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
ALTER TABLE organizations ADD COLUMN logo_url TEXT;
|
||||
|
||||
UPDATE organizations SET logo_url = 'https://fastly.picsum.photos/id/411/100/100.jpg?grayscale&hmac=lGH1KqiTvm1TFkjJ6kimsgMJIL0S7zVS7EHFi0qOgCk';
|
||||
|
||||
ALTER TABLE organizations ALTER COLUMN logo_url SET NOT NULL;
|
||||
5
pkg/coredata/migrations/20250212T174900Z.sql
Normal file
5
pkg/coredata/migrations/20250212T174900Z.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
ALTER TABLE controls ADD COLUMN category TEXT;
|
||||
|
||||
UPDATE controls SET category = 'security';
|
||||
|
||||
ALTER TABLE controls ALTER COLUMN category SET NOT NULL;
|
||||
15
pkg/coredata/migrations/20250218T101900Z.sql
Normal file
15
pkg/coredata/migrations/20250218T101900Z.sql
Normal file
@@ -0,0 +1,15 @@
|
||||
CREATE TYPE service_criticality AS ENUM ('LOW', 'MEDIUM', 'HIGH');
|
||||
CREATE TYPE risk_tier AS ENUM ('CRITICAL', 'SIGNIFICANT', 'GENERAL');
|
||||
|
||||
ALTER TABLE vendors
|
||||
ADD COLUMN service_start_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
|
||||
ADD COLUMN service_termination_date TIMESTAMP WITH TIME ZONE,
|
||||
ADD COLUMN service_criticality service_criticality NOT NULL DEFAULT 'LOW',
|
||||
ADD COLUMN risk_tier risk_tier NOT NULL DEFAULT 'GENERAL',
|
||||
ADD COLUMN status_page_url TEXT;
|
||||
|
||||
UPDATE vendors SET service_start_date = created_at;
|
||||
|
||||
ALTER TABLE vendors ALTER COLUMN service_start_date DROP DEFAULT;
|
||||
ALTER TABLE vendors ALTER COLUMN service_criticality DROP DEFAULT;
|
||||
ALTER TABLE vendors ALTER COLUMN risk_tier DROP DEFAULT;
|
||||
2
pkg/coredata/migrations/20250218T112800Z.sql
Normal file
2
pkg/coredata/migrations/20250218T112800Z.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE vendors ADD COLUMN description TEXT NOT NULL DEFAULT '';
|
||||
ALTER TABLE vendors ALTER COLUMN description DROP DEFAULT;
|
||||
1
pkg/coredata/migrations/20250218T113200Z.sql
Normal file
1
pkg/coredata/migrations/20250218T113200Z.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE vendors ADD COLUMN terms_of_service_url TEXT;
|
||||
1
pkg/coredata/migrations/20250218T113800Z.sql
Normal file
1
pkg/coredata/migrations/20250218T113800Z.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE vendors ADD COLUMN privacy_policy_url TEXT;
|
||||
2
pkg/coredata/migrations/20250218T120000Z.sql
Normal file
2
pkg/coredata/migrations/20250218T120000Z.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE vendors RENAME COLUMN service_start_date TO service_start_at;
|
||||
ALTER TABLE vendors RENAME COLUMN service_termination_date TO service_termination_at;
|
||||
1
pkg/coredata/migrations/20250218T121700Z.sql
Normal file
1
pkg/coredata/migrations/20250218T121700Z.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE vendors ADD COLUMN version INTEGER NOT NULL DEFAULT 1;
|
||||
2
pkg/coredata/migrations/20250218T125600Z.sql
Normal file
2
pkg/coredata/migrations/20250218T125600Z.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE evidences ADD COLUMN filename TEXT NOT NULL DEFAULT '';
|
||||
ALTER TABLE evidences ALTER COLUMN filename DROP DEFAULT;
|
||||
1
pkg/coredata/migrations/20250218T171000Z.sql
Normal file
1
pkg/coredata/migrations/20250218T171000Z.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE peoples ADD COLUMN version INTEGER NOT NULL DEFAULT 1;
|
||||
3
pkg/coredata/migrations/20250225T153220Z.sql
Normal file
3
pkg/coredata/migrations/20250225T153220Z.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
ALTER TABLE usrmgr_users ADD COLUMN organization_id TEXT;
|
||||
|
||||
CREATE INDEX usrmgr_users_organization_id_idx ON usrmgr_users(organization_id);
|
||||
11
pkg/coredata/migrations/20250225T201106Z.sql
Normal file
11
pkg/coredata/migrations/20250225T201106Z.sql
Normal file
@@ -0,0 +1,11 @@
|
||||
CREATE TABLE usrmgr_user_organizations (
|
||||
user_id TEXT REFERENCES usrmgr_users(id) NOT NULL,
|
||||
organization_id TEXT NOT NULL,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
||||
PRIMARY KEY (user_id, organization_id)
|
||||
);
|
||||
|
||||
INSERT INTO usrmgr_user_organizations (user_id, organization_id, created_at)
|
||||
SELECT id, organization_id, NOW()
|
||||
FROM usrmgr_users
|
||||
WHERE organization_id IS NOT NULL;
|
||||
1
pkg/coredata/migrations/20250225T211652Z.sql
Normal file
1
pkg/coredata/migrations/20250225T211652Z.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE usrmgr_users ADD COLUMN fullname TEXT;
|
||||
1
pkg/coredata/migrations/20250225T222000Z.sql
Normal file
1
pkg/coredata/migrations/20250225T222000Z.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE usrmgr_users ALTER COLUMN fullname SET NOT NULL;
|
||||
2
pkg/coredata/migrations/20250227T144100Z.sql
Normal file
2
pkg/coredata/migrations/20250227T144100Z.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE frameworks ADD COLUMN version INTEGER NOT NULL DEFAULT 0;
|
||||
ALTER TABLE frameworks ALTER COLUMN version DROP DEFAULT;
|
||||
2
pkg/coredata/migrations/20250227T152900Z.sql
Normal file
2
pkg/coredata/migrations/20250227T152900Z.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE controls ADD COLUMN version INTEGER NOT NULL DEFAULT 0;
|
||||
ALTER TABLE controls ALTER COLUMN version DROP DEFAULT;
|
||||
12
pkg/coredata/migrations/20250228T000000Z.sql
Normal file
12
pkg/coredata/migrations/20250228T000000Z.sql
Normal file
@@ -0,0 +1,12 @@
|
||||
CREATE TYPE policy_status AS ENUM ('DRAFT', 'ACTIVE');
|
||||
|
||||
CREATE TABLE policies (
|
||||
id TEXT PRIMARY KEY,
|
||||
organization_id TEXT REFERENCES organizations(id) NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
status policy_status NOT NULL,
|
||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
updated_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
version INTEGER NOT NULL
|
||||
);
|
||||
1
pkg/coredata/migrations/20250305T110005Z.sql
Normal file
1
pkg/coredata/migrations/20250305T110005Z.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE policies ADD COLUMN review_date TIMESTAMP WITH TIME ZONE;
|
||||
1
pkg/coredata/migrations/20250305T111053Z.sql
Normal file
1
pkg/coredata/migrations/20250305T111053Z.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE policies ADD COLUMN owner_id TEXT REFERENCES peoples(id) NOT NULL;
|
||||
47
pkg/coredata/migrations/20250305T155800Z.sql
Normal file
47
pkg/coredata/migrations/20250305T155800Z.sql
Normal file
@@ -0,0 +1,47 @@
|
||||
ALTER TABLE organizations ADD COLUMN tenant_id TEXT;
|
||||
UPDATE organizations SET tenant_id = id;
|
||||
ALTER TABLE organizations ALTER COLUMN tenant_id SET NOT NULL;
|
||||
|
||||
ALTER TABLE frameworks ADD COLUMN tenant_id TEXT;
|
||||
UPDATE frameworks f SET tenant_id = f.organization_id;
|
||||
ALTER TABLE frameworks ALTER COLUMN tenant_id SET NOT NULL;
|
||||
|
||||
ALTER TABLE controls ADD COLUMN tenant_id TEXT;
|
||||
UPDATE controls c SET tenant_id = (SELECT organization_id FROM frameworks f WHERE f.id = c.framework_id);
|
||||
ALTER TABLE controls ALTER COLUMN tenant_id SET NOT NULL;
|
||||
|
||||
ALTER TABLE tasks ADD COLUMN tenant_id TEXT;
|
||||
UPDATE tasks t SET tenant_id = (SELECT c.tenant_id FROM controls_tasks ct JOIN controls c ON ct.control_id = c.id WHERE ct.task_id = t.id LIMIT 1);
|
||||
ALTER TABLE tasks ALTER COLUMN tenant_id SET NOT NULL;
|
||||
|
||||
ALTER TABLE evidences ADD COLUMN tenant_id TEXT;
|
||||
UPDATE evidences e SET tenant_id = (SELECT t.tenant_id FROM tasks t WHERE t.id = e.task_id);
|
||||
ALTER TABLE evidences ALTER COLUMN tenant_id SET NOT NULL;
|
||||
|
||||
ALTER TABLE controls_tasks ADD COLUMN tenant_id TEXT;
|
||||
UPDATE controls_tasks ct SET tenant_id = (SELECT f.tenant_id FROM frameworks f JOIN controls c ON c.framework_id = f.id WHERE c.id = ct.control_id);
|
||||
ALTER TABLE controls_tasks ALTER COLUMN tenant_id SET NOT NULL;
|
||||
|
||||
ALTER TABLE control_state_transitions ADD COLUMN tenant_id TEXT;
|
||||
UPDATE control_state_transitions cst SET tenant_id = (SELECT c.tenant_id FROM controls c WHERE c.id = cst.control_id);
|
||||
ALTER TABLE control_state_transitions ALTER COLUMN tenant_id SET NOT NULL;
|
||||
|
||||
ALTER TABLE task_state_transitions ADD COLUMN tenant_id TEXT;
|
||||
UPDATE task_state_transitions tst SET tenant_id = (SELECT t.tenant_id FROM tasks t WHERE t.id = tst.task_id);
|
||||
ALTER TABLE task_state_transitions ALTER COLUMN tenant_id SET NOT NULL;
|
||||
|
||||
ALTER TABLE evidence_state_transitions ADD COLUMN tenant_id TEXT;
|
||||
UPDATE evidence_state_transitions est SET tenant_id = (SELECT e.tenant_id FROM evidences e WHERE e.id = est.evidence_id);
|
||||
ALTER TABLE evidence_state_transitions ALTER COLUMN tenant_id SET NOT NULL;
|
||||
|
||||
ALTER TABLE peoples ADD COLUMN tenant_id TEXT;
|
||||
UPDATE peoples p SET tenant_id = p.organization_id;
|
||||
ALTER TABLE peoples ALTER COLUMN tenant_id SET NOT NULL;
|
||||
|
||||
ALTER TABLE vendors ADD COLUMN tenant_id TEXT;
|
||||
UPDATE vendors v SET tenant_id = v.organization_id;
|
||||
ALTER TABLE vendors ALTER COLUMN tenant_id SET NOT NULL;
|
||||
|
||||
ALTER TABLE policies ADD COLUMN tenant_id TEXT;
|
||||
UPDATE policies p SET tenant_id = p.organization_id;
|
||||
ALTER TABLE policies ALTER COLUMN tenant_id SET NOT NULL;
|
||||
1
pkg/coredata/migrations/20250305T171200Z.sql
Normal file
1
pkg/coredata/migrations/20250305T171200Z.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE usrmgr_sessions ADD COLUMN data jsonb NOT NULL DEFAULT '{}';
|
||||
17
pkg/coredata/migrations/20250310T161900Z.sql
Normal file
17
pkg/coredata/migrations/20250310T161900Z.sql
Normal file
@@ -0,0 +1,17 @@
|
||||
DROP TABLE control_state_transitions;
|
||||
DROP TABLE evidence_state_transitions;
|
||||
DROP TABLE task_state_transitions;
|
||||
|
||||
ALTER TABLE tasks ADD COLUMN control_id TEXT;
|
||||
|
||||
UPDATE tasks
|
||||
SET control_id = controls_tasks.control_id
|
||||
FROM controls_tasks
|
||||
WHERE tasks.id = controls_tasks.task_id;
|
||||
|
||||
ALTER TABLE tasks ALTER COLUMN control_id SET NOT NULL;
|
||||
|
||||
ALTER TABLE tasks ADD CONSTRAINT fk_tasks_control_id
|
||||
FOREIGN KEY (control_id) REFERENCES controls(id) ON DELETE CASCADE;
|
||||
|
||||
DROP TABLE controls_tasks;
|
||||
3
pkg/coredata/migrations/20250310T164900Z.sql
Normal file
3
pkg/coredata/migrations/20250310T164900Z.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
ALTER TABLE controls ADD COLUMN state control_state;
|
||||
ALTER TABLE evidences ADD COLUMN state evidence_state;
|
||||
ALTER TABLE tasks ADD COLUMN state task_state;
|
||||
1
pkg/coredata/migrations/20250310T181100Z.sql
Normal file
1
pkg/coredata/migrations/20250310T181100Z.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE tasks ADD COLUMN version INTEGER NOT NULL DEFAULT 1;
|
||||
Reference in New Issue
Block a user