forked from 0xPolygonHermez/zkevm-node
-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3a6b23e
commit a0ec07d
Showing
3 changed files
with
76 additions
and
0 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; |
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
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