Skip to content

Commit e6ecfdd

Browse files
committed
create_schema.sql: Initialize migration history on archive DB creation
1 parent 8ac20ff commit e6ecfdd

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/app/archive/create_schema.sql

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,3 +544,30 @@ 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+
CREATE TYPE migration_status AS ENUM ('starting', 'applied', 'failed');
549+
CREATE TABLE migration_history (
550+
commit_start_at timestamptz NOT NULL DEFAULT now() PRIMARY KEY,
551+
protocol_version text NOT NULL,
552+
migration_version text NOT NULL,
553+
description text NOT NULL,
554+
status migration_status NOT NULL
555+
);
556+
557+
-- WARN: we're using mesa as current protocol version!
558+
SET archive.current_protocol_version = '4.0.0';
559+
560+
DO $$
561+
DECLARE
562+
protocol_version text := current_setting('archive.current_protocol_version');
563+
BEGIN
564+
INSERT INTO migration_history(
565+
protocol_version, migration_version, description, status
566+
) VALUES (
567+
protocol_version,
568+
'fresh',
569+
'Initialized by create_schema.sql',
570+
'applied'::migration_status
571+
);
572+
END
573+
$$;

0 commit comments

Comments
 (0)