Add delete measure

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
Bryan Frimin
2025-04-27 21:01:08 -07:00
parent 76b6df79fc
commit 230ae1130f
10 changed files with 570 additions and 25 deletions

View File

@@ -433,3 +433,22 @@ WHERE %s
_, err := conn.Exec(ctx, q, args)
return err
}
func (m *Mesure) Delete(
ctx context.Context,
conn pg.Conn,
scope Scoper,
) error {
q := `
DELETE FROM mesures
WHERE %s
AND id = @mesure_id
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{"mesure_id": m.ID}
maps.Copy(args, scope.SQLArguments())
_, err := conn.Exec(ctx, q, args)
return err
}

View File

@@ -0,0 +1,7 @@
ALTER TABLE evidences DROP CONSTRAINT evidences_task_id_fkey;
ALTER TABLE evidences
ADD CONSTRAINT evidences_task_id_fkey
FOREIGN KEY (task_id)
REFERENCES tasks(id)
ON DELETE CASCADE;