Skip to content

Commit

Permalink
Add cascade delete to kv store table fk (#12629)
Browse files Browse the repository at this point in the history
* Add cascade delete to kv store table fk

* Add changeset
  • Loading branch information
ilija42 committed Mar 28, 2024
1 parent 478f73b commit 3ec8cc9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/brave-games-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": major
---

Fix kv_store migration fk cascade deletion
2 changes: 2 additions & 0 deletions core/services/job/kv_orm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,6 @@ func TestJobKVStore(t *testing.T) {
require.NoError(t, kvStore.Store(key, td2))
require.NoError(t, kvStore.Get(key, &retData))
require.Equal(t, td2, retData)

require.NoError(t, jobORM.DeleteJob(jobID))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- +goose Up

BEGIN;

ALTER TABLE job_kv_store DROP CONSTRAINT job_kv_store_job_id_fkey;
ALTER TABLE job_kv_store
ADD CONSTRAINT job_kv_store_job_id_fkey
FOREIGN KEY (job_id)
REFERENCES jobs(id)
ON DELETE CASCADE;

COMMIT;

-- +goose Down
BEGIN;

ALTER TABLE job_kv_store DROP CONSTRAINT job_kv_store_job_id_fkey;
ALTER TABLE job_kv_store
ADD CONSTRAINT job_kv_store_job_id_fkey
FOREIGN KEY (job_id)
REFERENCES jobs(id);

COMMIT;

0 comments on commit 3ec8cc9

Please sign in to comment.