forked from 0xPolygonHermez/zkevm-node
-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/CDK-132-data-recovery-mechanism'…
… into release/v0.6.4+cdk
- Loading branch information
Showing
4 changed files
with
3,637 additions
and
1,034 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.