Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/CDK-132-data-recovery-mechanism'…
Browse files Browse the repository at this point in the history
… into release/v0.6.4+cdk
  • Loading branch information
vcastellm committed Apr 9, 2024
2 parents 3b1fd91 + 0f5f17d commit 5350426
Show file tree
Hide file tree
Showing 4 changed files with 3,637 additions and 1,034 deletions.
32 changes: 32 additions & 0 deletions db/migrations/state/validium-001.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
-- +migrate Up

CREATE TABLE IF NOT EXISTS state.batch_data_backup
(
batch_num BIGINT,
data BYTEA,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (batch_num, created_at)
);

-- +migrate StatementBegin
CREATE OR REPLACE FUNCTION backup_batch() RETURNS trigger AS $$
BEGIN
INSERT INTO state.batch_data_backup (batch_num, data)
VALUES (OLD.batch_num, OLD.raw_txs_data)
ON CONFLICT (batch_num, created_at) DO UPDATE SET
data = EXCLUDED.data;
RETURN OLD;
END;
$$
LANGUAGE plpgsql;
-- +migrate StatementEnd

CREATE TRIGGER backup_batch
BEFORE DELETE ON state.batch FOR EACH ROW
EXECUTE PROCEDURE backup_batch();

-- +migrate Down

DROP TRIGGER IF EXISTS backup_batch ON state.batch;
DROP FUNCTION IF EXISTS backup_batch();
DROP TABLE IF EXISTS state.batch_data_backup;
Loading

0 comments on commit 5350426

Please sign in to comment.