Skip to content

Commit c641353

Browse files
committed
Initialize migration history on archive DB creation
1 parent 8ac20ff commit c641353

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/app/archive/create_schema.sql

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,3 +544,32 @@ CREATE TABLE blocks_zkapp_commands
544544
CREATE INDEX idx_blocks_zkapp_commands_block_id ON blocks_zkapp_commands(block_id);
545545
CREATE INDEX idx_blocks_zkapp_commands_zkapp_command_id ON blocks_zkapp_commands(zkapp_command_id);
546546
CREATE INDEX idx_blocks_zkapp_commands_sequence_no ON blocks_zkapp_commands(sequence_no);
547+
548+
549+
CREATE TYPE migration_status AS ENUM ('starting', 'applied', 'failed');
550+
551+
CREATE TABLE migration_history (
552+
commit_start_at timestamptz NOT NULL DEFAULT now() PRIMARY KEY,
553+
protocol_version text NOT NULL,
554+
migration_version text NOT NULL,
555+
description text NOT NULL,
556+
status migration_status NOT NULL
557+
);
558+
559+
-- WARN: we're using mesa as current protocol version!
560+
SET archive.current_protocol_version = '4.0.0';
561+
562+
DO $$
563+
DECLARE
564+
protocol_version text := current_setting('archive.current_protocol_version');
565+
BEGIN
566+
INSERT INTO migration_history(
567+
protocol_version, migration_version, description, status
568+
) VALUES (
569+
protocol_version,
570+
'fresh',
571+
'Initialized by create_schema.sql',
572+
'applied'::migration_status
573+
);
574+
END
575+
$$;

0 commit comments

Comments
 (0)