Change tasks can be linked to many controls
Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
12
pkg/probo/coredata/migrations/20250128T093900Z.sql
Normal file
12
pkg/probo/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)
|
||||||
|
);
|
||||||
@@ -62,6 +62,22 @@ func (t *Tasks) LoadByControlID(
|
|||||||
cursor *page.Cursor,
|
cursor *page.Cursor,
|
||||||
) error {
|
) error {
|
||||||
q := `
|
q := `
|
||||||
|
WITH control_tasks AS (
|
||||||
|
SELECT
|
||||||
|
t.id,
|
||||||
|
@control_id AS control_id,
|
||||||
|
t.content_ref,
|
||||||
|
t.created_at,
|
||||||
|
t.updated_at
|
||||||
|
FROM
|
||||||
|
tasks t
|
||||||
|
INNER JOIN
|
||||||
|
controls_tasks ct ON
|
||||||
|
ct.task_id = t.id
|
||||||
|
AND ct.control_id = @control_id
|
||||||
|
WHERE
|
||||||
|
%s
|
||||||
|
)
|
||||||
SELECT
|
SELECT
|
||||||
id,
|
id,
|
||||||
control_id,
|
control_id,
|
||||||
@@ -69,11 +85,9 @@ SELECT
|
|||||||
created_at,
|
created_at,
|
||||||
updated_at
|
updated_at
|
||||||
FROM
|
FROM
|
||||||
tasks
|
control_tasks
|
||||||
WHERE
|
WHERE
|
||||||
%s
|
%s
|
||||||
AND control_id = @control_id
|
|
||||||
AND %s
|
|
||||||
`
|
`
|
||||||
|
|
||||||
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
|
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
|
||||||
|
|||||||
Reference in New Issue
Block a user