0.1.0-pre.004
This commit is contained in:
94
kb-store/migrations/0001_canonical_transaction_store.sql
Normal file
94
kb-store/migrations/0001_canonical_transaction_store.sql
Normal file
@@ -0,0 +1,94 @@
|
||||
-- file: kb-store/migrations/0001_canonical_transaction_store.sql
|
||||
-- version: 1
|
||||
|
||||
-- Current canonical transaction and acquisition observation store.
|
||||
-- This baseline contains only active tables and uses the current PostgreSQL schema.
|
||||
-- Historical 0.2.x upgrade logic was validated before this baseline was consolidated.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS kb_sol_raw_transactions (
|
||||
id BIGSERIAL,
|
||||
signature TEXT NOT NULL,
|
||||
slot BIGINT NOT NULL,
|
||||
canonical_json JSONB,
|
||||
canonical_json_hash TEXT,
|
||||
canonical_format_version INTEGER NOT NULL DEFAULT 1,
|
||||
retention_state TEXT NOT NULL DEFAULT 'full',
|
||||
processing_state TEXT NOT NULL DEFAULT 'received',
|
||||
lifecycle_reason TEXT,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
CONSTRAINT pk_kb_sol_raw_transactions PRIMARY KEY (id),
|
||||
CONSTRAINT ck_kb_sol_raw_transactions_signature_not_empty CHECK (length(btrim(signature)) > 0),
|
||||
CONSTRAINT ck_kb_sol_raw_transactions_slot_non_negative CHECK (slot >= 0),
|
||||
CONSTRAINT ck_kb_sol_raw_transactions_format_version_positive CHECK (canonical_format_version > 0),
|
||||
CONSTRAINT ck_kb_sol_raw_transactions_retention_state CHECK (retention_state IN ('full', 'compacted', 'archived', 'purged')),
|
||||
CONSTRAINT ck_kb_sol_raw_transactions_processing_state CHECK (processing_state IN ('received', 'core_extracted', 'decoded', 'materialized', 'failed')),
|
||||
CONSTRAINT ck_kb_sol_raw_transactions_full_has_json CHECK (retention_state <> 'full' OR canonical_json IS NOT NULL)
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS ux_kb_sol_raw_transactions_signature ON kb_sol_raw_transactions (signature);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ix_kb_sol_raw_transactions_slot ON kb_sol_raw_transactions (slot);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ix_kb_sol_raw_transactions_created_at ON kb_sol_raw_transactions (created_at);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ix_kb_sol_raw_transactions_processing ON kb_sol_raw_transactions (processing_state);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ix_kb_sol_raw_transactions_canonical_hash ON kb_sol_raw_transactions (canonical_json_hash) WHERE canonical_json_hash IS NOT NULL;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS kb_sol_obs_transaction_observations (
|
||||
id BIGSERIAL,
|
||||
raw_transaction_id BIGINT,
|
||||
observation_key TEXT NOT NULL,
|
||||
signature TEXT,
|
||||
slot BIGINT,
|
||||
provider TEXT NOT NULL,
|
||||
endpoint_code TEXT,
|
||||
protocol TEXT NOT NULL,
|
||||
acquisition_method TEXT NOT NULL,
|
||||
origin TEXT NOT NULL,
|
||||
commitment TEXT,
|
||||
capture_session_id TEXT,
|
||||
filter_code TEXT,
|
||||
detected_at TIMESTAMPTZ,
|
||||
received_at TIMESTAMPTZ NOT NULL,
|
||||
normalized_at TIMESTAMPTZ,
|
||||
persisted_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
payload_size_bytes BIGINT,
|
||||
source_payload_hash TEXT,
|
||||
status TEXT NOT NULL DEFAULT 'received',
|
||||
error_code TEXT,
|
||||
error_message TEXT,
|
||||
CONSTRAINT pk_kb_sol_obs_transaction_observations PRIMARY KEY (id),
|
||||
CONSTRAINT fk_kb_sol_obs_transaction_observations_raw_transaction FOREIGN KEY (raw_transaction_id) REFERENCES kb_sol_raw_transactions(id) ON DELETE SET NULL,
|
||||
CONSTRAINT ck_kb_sol_obs_transaction_observations_key_not_empty CHECK (length(btrim(observation_key)) > 0),
|
||||
CONSTRAINT ck_kb_sol_obs_transaction_observations_signature_not_empty CHECK (signature IS NULL OR length(btrim(signature)) > 0),
|
||||
CONSTRAINT ck_kb_sol_obs_transaction_observations_slot_non_negative CHECK (slot IS NULL OR slot >= 0),
|
||||
CONSTRAINT ck_kb_sol_obs_transaction_observations_provider_not_empty CHECK (length(btrim(provider)) > 0),
|
||||
CONSTRAINT ck_kb_sol_obs_transaction_observations_endpoint_not_empty CHECK (endpoint_code IS NULL OR length(btrim(endpoint_code)) > 0),
|
||||
CONSTRAINT ck_kb_sol_obs_transaction_observations_protocol_not_empty CHECK (length(btrim(protocol)) > 0),
|
||||
CONSTRAINT ck_kb_sol_obs_transaction_observations_method_not_empty CHECK (length(btrim(acquisition_method)) > 0),
|
||||
CONSTRAINT ck_kb_sol_obs_transaction_observations_origin CHECK (origin IN ('live', 'backfill', 'replay', 'repair', 'migration')),
|
||||
CONSTRAINT ck_kb_sol_obs_transaction_observations_commitment_not_empty CHECK (commitment IS NULL OR length(btrim(commitment)) > 0),
|
||||
CONSTRAINT ck_kb_sol_obs_transaction_observations_session_not_empty CHECK (capture_session_id IS NULL OR length(btrim(capture_session_id)) > 0),
|
||||
CONSTRAINT ck_kb_sol_obs_transaction_observations_filter_not_empty CHECK (filter_code IS NULL OR length(btrim(filter_code)) > 0),
|
||||
CONSTRAINT ck_kb_sol_obs_transaction_observations_payload_size_non_negative CHECK (payload_size_bytes IS NULL OR payload_size_bytes >= 0),
|
||||
CONSTRAINT ck_kb_sol_obs_transaction_observations_hash_not_empty CHECK (source_payload_hash IS NULL OR length(btrim(source_payload_hash)) > 0),
|
||||
CONSTRAINT ck_kb_sol_obs_transaction_observations_status CHECK (status IN ('detected', 'received', 'normalized', 'persisted', 'failed', 'missing')),
|
||||
CONSTRAINT ck_kb_sol_obs_transaction_observations_error_code_not_empty CHECK (error_code IS NULL OR length(btrim(error_code)) > 0),
|
||||
CONSTRAINT ck_kb_sol_obs_transaction_observations_error_message_not_empty CHECK (error_message IS NULL OR length(btrim(error_message)) > 0)
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS ux_kb_sol_obs_transaction_observations_key ON kb_sol_obs_transaction_observations (observation_key);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ix_kb_sol_obs_transaction_observations_signature ON kb_sol_obs_transaction_observations (signature) WHERE signature IS NOT NULL;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ix_kb_sol_obs_transaction_observations_slot ON kb_sol_obs_transaction_observations (slot) WHERE slot IS NOT NULL;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ix_kb_sol_obs_transaction_observations_provider_method ON kb_sol_obs_transaction_observations (provider, acquisition_method);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ix_kb_sol_obs_transaction_observations_received_at ON kb_sol_obs_transaction_observations (received_at);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ix_kb_sol_obs_transaction_observations_raw_transaction ON kb_sol_obs_transaction_observations (raw_transaction_id) WHERE raw_transaction_id IS NOT NULL;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ix_kb_sol_obs_transaction_observations_status ON kb_sol_obs_transaction_observations (status);
|
||||
196
kb-store/migrations/0002_core_store.sql
Normal file
196
kb-store/migrations/0002_core_store.sql
Normal file
@@ -0,0 +1,196 @@
|
||||
-- file: kb-store/migrations/0002_core_store.sql
|
||||
-- version: 1
|
||||
|
||||
-- Current normalized Solana core store.
|
||||
-- This migration uses the current PostgreSQL schema from the active profile.
|
||||
-- It must not create application schemas such as raw, core, obs, decode, mat or catalog.
|
||||
-- Object naming convention: pk_ for primary keys, fk_ for foreign keys, ux_ for unique indexes and ix_ for non-unique indexes.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS kb_sol_core_transactions (
|
||||
id BIGSERIAL,
|
||||
raw_transaction_id BIGINT,
|
||||
signature TEXT NOT NULL,
|
||||
slot BIGINT NOT NULL,
|
||||
failed BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
err_json JSONB,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
CONSTRAINT pk_kb_sol_core_transactions PRIMARY KEY (id),
|
||||
CONSTRAINT fk_kb_sol_core_transactions_raw_transaction FOREIGN KEY (raw_transaction_id) REFERENCES kb_sol_raw_transactions(id) ON DELETE SET NULL,
|
||||
CONSTRAINT ck_kb_sol_core_transactions_signature_not_empty CHECK (length(btrim(signature)) > 0),
|
||||
CONSTRAINT ck_kb_sol_core_transactions_slot_non_negative CHECK (slot >= 0)
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS ux_kb_sol_core_transactions_signature
|
||||
ON kb_sol_core_transactions (signature);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ix_kb_sol_core_transactions_slot
|
||||
ON kb_sol_core_transactions (slot);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ix_kb_sol_core_transactions_created_at
|
||||
ON kb_sol_core_transactions (created_at);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS kb_sol_core_account_keys (
|
||||
id BIGSERIAL,
|
||||
transaction_id BIGINT NOT NULL,
|
||||
signature TEXT NOT NULL,
|
||||
slot BIGINT NOT NULL,
|
||||
account_index INTEGER NOT NULL,
|
||||
account_key TEXT NOT NULL,
|
||||
source TEXT NOT NULL,
|
||||
writable BOOLEAN NOT NULL,
|
||||
signer BOOLEAN NOT NULL,
|
||||
executable BOOLEAN,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
CONSTRAINT pk_kb_sol_core_account_keys PRIMARY KEY (id),
|
||||
CONSTRAINT fk_kb_sol_core_account_keys_transaction FOREIGN KEY (transaction_id) REFERENCES kb_sol_core_transactions(id) ON DELETE CASCADE,
|
||||
CONSTRAINT ck_kb_sol_core_account_keys_signature_not_empty CHECK (length(btrim(signature)) > 0),
|
||||
CONSTRAINT ck_kb_sol_core_account_keys_slot_non_negative CHECK (slot >= 0),
|
||||
CONSTRAINT ck_kb_sol_core_account_keys_index_non_negative CHECK (account_index >= 0),
|
||||
CONSTRAINT ck_kb_sol_core_account_keys_key_not_empty CHECK (length(btrim(account_key)) > 0),
|
||||
CONSTRAINT ck_kb_sol_core_account_keys_source CHECK (source IN ('static', 'loaded_writable', 'loaded_readonly'))
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS ux_kb_sol_core_account_keys_sig_index
|
||||
ON kb_sol_core_account_keys (signature, account_index);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ix_kb_sol_core_account_keys_key
|
||||
ON kb_sol_core_account_keys (account_key);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS kb_sol_core_instructions (
|
||||
id BIGSERIAL,
|
||||
transaction_id BIGINT NOT NULL,
|
||||
signature TEXT NOT NULL,
|
||||
slot BIGINT NOT NULL,
|
||||
instruction_path TEXT NOT NULL,
|
||||
program_id TEXT NOT NULL,
|
||||
accounts_json JSONB NOT NULL,
|
||||
payload_json JSONB,
|
||||
payload_json_hash TEXT,
|
||||
processing_state TEXT NOT NULL DEFAULT 'pending',
|
||||
processor_name TEXT,
|
||||
processor_version TEXT,
|
||||
lifecycle_reason TEXT,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
CONSTRAINT pk_kb_sol_core_instructions PRIMARY KEY (id),
|
||||
CONSTRAINT fk_kb_sol_core_instructions_transaction FOREIGN KEY (transaction_id) REFERENCES kb_sol_core_transactions(id) ON DELETE CASCADE,
|
||||
CONSTRAINT ck_kb_sol_core_instructions_signature_not_empty CHECK (length(btrim(signature)) > 0),
|
||||
CONSTRAINT ck_kb_sol_core_instructions_slot_non_negative CHECK (slot >= 0),
|
||||
CONSTRAINT ck_kb_sol_core_instructions_path_not_empty CHECK (length(btrim(instruction_path)) > 0),
|
||||
CONSTRAINT ck_kb_sol_core_instructions_program_not_empty CHECK (length(btrim(program_id)) > 0),
|
||||
CONSTRAINT ck_kb_sol_core_instructions_processing_state CHECK (processing_state IN ('pending', 'decoded', 'materialized', 'ignored', 'failed', 'replay_requested'))
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS ux_kb_sol_core_instructions_sig_path
|
||||
ON kb_sol_core_instructions (signature, instruction_path);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ix_kb_sol_core_instructions_program
|
||||
ON kb_sol_core_instructions (program_id);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ix_kb_sol_core_instructions_slot
|
||||
ON kb_sol_core_instructions (slot);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ix_kb_sol_core_instructions_processing
|
||||
ON kb_sol_core_instructions (processing_state);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS kb_sol_core_inner_instructions (
|
||||
id BIGSERIAL,
|
||||
transaction_id BIGINT NOT NULL,
|
||||
signature TEXT NOT NULL,
|
||||
slot BIGINT NOT NULL,
|
||||
parent_instruction_path TEXT NOT NULL,
|
||||
instruction_path TEXT NOT NULL,
|
||||
program_id TEXT NOT NULL,
|
||||
accounts_json JSONB NOT NULL,
|
||||
payload_json JSONB,
|
||||
payload_json_hash TEXT,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
CONSTRAINT pk_kb_sol_core_inner_instructions PRIMARY KEY (id),
|
||||
CONSTRAINT fk_kb_sol_core_inner_instructions_transaction FOREIGN KEY (transaction_id) REFERENCES kb_sol_core_transactions(id) ON DELETE CASCADE,
|
||||
CONSTRAINT ck_kb_sol_core_inner_instructions_signature_not_empty CHECK (length(btrim(signature)) > 0),
|
||||
CONSTRAINT ck_kb_sol_core_inner_instructions_slot_non_negative CHECK (slot >= 0),
|
||||
CONSTRAINT ck_kb_sol_core_inner_instructions_parent_not_empty CHECK (length(btrim(parent_instruction_path)) > 0),
|
||||
CONSTRAINT ck_kb_sol_core_inner_instructions_path_not_empty CHECK (length(btrim(instruction_path)) > 0),
|
||||
CONSTRAINT ck_kb_sol_core_inner_instructions_program_not_empty CHECK (length(btrim(program_id)) > 0)
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS ux_kb_sol_core_inner_instructions_sig_path
|
||||
ON kb_sol_core_inner_instructions (signature, instruction_path);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ix_kb_sol_core_inner_instructions_parent
|
||||
ON kb_sol_core_inner_instructions (signature, parent_instruction_path);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ix_kb_sol_core_inner_instructions_program
|
||||
ON kb_sol_core_inner_instructions (program_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS kb_sol_core_logs (
|
||||
id BIGSERIAL,
|
||||
transaction_id BIGINT NOT NULL,
|
||||
signature TEXT NOT NULL,
|
||||
slot BIGINT NOT NULL,
|
||||
log_index INTEGER NOT NULL,
|
||||
instruction_path TEXT,
|
||||
program_id TEXT,
|
||||
log_text TEXT,
|
||||
log_text_hash TEXT,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
CONSTRAINT pk_kb_sol_core_logs PRIMARY KEY (id),
|
||||
CONSTRAINT fk_kb_sol_core_logs_transaction FOREIGN KEY (transaction_id) REFERENCES kb_sol_core_transactions(id) ON DELETE CASCADE,
|
||||
CONSTRAINT ck_kb_sol_core_logs_signature_not_empty CHECK (length(btrim(signature)) > 0),
|
||||
CONSTRAINT ck_kb_sol_core_logs_slot_non_negative CHECK (slot >= 0),
|
||||
CONSTRAINT ck_kb_sol_core_logs_index_non_negative CHECK (log_index >= 0),
|
||||
CONSTRAINT ck_kb_sol_core_logs_text_not_empty CHECK (log_text IS NULL OR length(btrim(log_text)) > 0),
|
||||
CONSTRAINT ck_kb_sol_core_logs_path_not_empty CHECK (instruction_path IS NULL OR length(btrim(instruction_path)) > 0),
|
||||
CONSTRAINT ck_kb_sol_core_logs_program_not_empty CHECK (program_id IS NULL OR length(btrim(program_id)) > 0)
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS ux_kb_sol_core_logs_sig_index
|
||||
ON kb_sol_core_logs (signature, log_index);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ix_kb_sol_core_logs_program
|
||||
ON kb_sol_core_logs (program_id)
|
||||
WHERE program_id IS NOT NULL;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ix_kb_sol_core_logs_path
|
||||
ON kb_sol_core_logs (signature, instruction_path)
|
||||
WHERE instruction_path IS NOT NULL;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS kb_sol_core_balance_changes (
|
||||
id BIGSERIAL,
|
||||
transaction_id BIGINT NOT NULL,
|
||||
signature TEXT NOT NULL,
|
||||
slot BIGINT NOT NULL,
|
||||
balance_change_index INTEGER NOT NULL,
|
||||
balance_kind TEXT NOT NULL,
|
||||
account_index INTEGER,
|
||||
account_key TEXT,
|
||||
mint TEXT,
|
||||
owner TEXT,
|
||||
pre_balance_json JSONB,
|
||||
post_balance_json JSONB,
|
||||
delta_json JSONB,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
CONSTRAINT pk_kb_sol_core_balance_changes PRIMARY KEY (id),
|
||||
CONSTRAINT fk_kb_sol_core_balance_changes_transaction FOREIGN KEY (transaction_id) REFERENCES kb_sol_core_transactions(id) ON DELETE CASCADE,
|
||||
CONSTRAINT ck_kb_sol_core_balance_changes_signature_not_empty CHECK (length(btrim(signature)) > 0),
|
||||
CONSTRAINT ck_kb_sol_core_balance_changes_slot_non_negative CHECK (slot >= 0),
|
||||
CONSTRAINT ck_kb_sol_core_balance_changes_index_non_negative CHECK (balance_change_index >= 0),
|
||||
CONSTRAINT ck_kb_sol_core_balance_changes_account_index_non_negative CHECK (account_index IS NULL OR account_index >= 0),
|
||||
CONSTRAINT ck_kb_sol_core_balance_changes_kind CHECK (balance_kind IN ('native_lamports', 'token_amount')),
|
||||
CONSTRAINT ck_kb_sol_core_balance_changes_account_not_empty CHECK (account_key IS NULL OR length(btrim(account_key)) > 0),
|
||||
CONSTRAINT ck_kb_sol_core_balance_changes_mint_not_empty CHECK (mint IS NULL OR length(btrim(mint)) > 0),
|
||||
CONSTRAINT ck_kb_sol_core_balance_changes_owner_not_empty CHECK (owner IS NULL OR length(btrim(owner)) > 0)
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS ux_kb_sol_core_balance_changes_sig_index
|
||||
ON kb_sol_core_balance_changes (signature, balance_change_index);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ix_kb_sol_core_balance_changes_account
|
||||
ON kb_sol_core_balance_changes (account_key)
|
||||
WHERE account_key IS NOT NULL;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ix_kb_sol_core_balance_changes_mint
|
||||
ON kb_sol_core_balance_changes (mint)
|
||||
WHERE mint IS NOT NULL;
|
||||
|
||||
41
kb-store/migrations/0003_processing_ledger.sql
Normal file
41
kb-store/migrations/0003_processing_ledger.sql
Normal file
@@ -0,0 +1,41 @@
|
||||
-- file: kb-store/migrations/0003_processing_ledger.sql
|
||||
-- version: 1
|
||||
|
||||
-- Current processing ledger for canonical to core extraction and later pipeline stages.
|
||||
-- This migration uses the current PostgreSQL schema from the active profile.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS kb_sol_ops_processing_ledger (
|
||||
id BIGSERIAL,
|
||||
stage TEXT NOT NULL,
|
||||
processor_name TEXT NOT NULL,
|
||||
processor_version TEXT NOT NULL,
|
||||
input_key TEXT NOT NULL,
|
||||
input_hash TEXT NOT NULL,
|
||||
status TEXT NOT NULL,
|
||||
attempt_count INTEGER NOT NULL DEFAULT 0,
|
||||
started_at TIMESTAMPTZ,
|
||||
finished_at TIMESTAMPTZ,
|
||||
error_code TEXT,
|
||||
error_message TEXT,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
CONSTRAINT pk_kb_sol_ops_processing_ledger PRIMARY KEY (id),
|
||||
CONSTRAINT ck_kb_sol_ops_processing_ledger_stage_not_empty CHECK (length(btrim(stage)) > 0),
|
||||
CONSTRAINT ck_kb_sol_ops_processing_ledger_processor_name_not_empty CHECK (length(btrim(processor_name)) > 0),
|
||||
CONSTRAINT ck_kb_sol_ops_processing_ledger_processor_version_not_empty CHECK (length(btrim(processor_version)) > 0),
|
||||
CONSTRAINT ck_kb_sol_ops_processing_ledger_input_key_not_empty CHECK (length(btrim(input_key)) > 0),
|
||||
CONSTRAINT ck_kb_sol_ops_processing_ledger_input_hash_not_empty CHECK (length(btrim(input_hash)) > 0),
|
||||
CONSTRAINT ck_kb_sol_ops_processing_ledger_status CHECK (status IN ('running', 'succeeded', 'failed')),
|
||||
CONSTRAINT ck_kb_sol_ops_processing_ledger_attempt_count_non_negative CHECK (attempt_count >= 0),
|
||||
CONSTRAINT ck_kb_sol_ops_processing_ledger_error_code_not_empty CHECK (error_code IS NULL OR length(btrim(error_code)) > 0),
|
||||
CONSTRAINT ck_kb_sol_ops_processing_ledger_error_message_not_empty CHECK (error_message IS NULL OR length(btrim(error_message)) > 0)
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS ux_kb_sol_ops_processing_ledger_identity
|
||||
ON kb_sol_ops_processing_ledger (stage, processor_name, processor_version, input_key);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ix_kb_sol_ops_processing_ledger_status
|
||||
ON kb_sol_ops_processing_ledger (stage, processor_name, status, updated_at);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ix_kb_sol_ops_processing_ledger_input_hash
|
||||
ON kb_sol_ops_processing_ledger (input_hash);
|
||||
132
kb-store/migrations/0004_decode_materialization_store.sql
Normal file
132
kb-store/migrations/0004_decode_materialization_store.sql
Normal file
@@ -0,0 +1,132 @@
|
||||
-- file: kb-store/migrations/0004_decode_materialization_store.sql
|
||||
-- version: 1
|
||||
|
||||
-- Common versioned decode, coverage and materialization store.
|
||||
-- This migration uses the current PostgreSQL schema from the active profile.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS kb_sol_decode_events (
|
||||
id BIGSERIAL,
|
||||
processor_name TEXT NOT NULL,
|
||||
processor_version TEXT NOT NULL,
|
||||
input_key TEXT NOT NULL,
|
||||
input_hash TEXT NOT NULL,
|
||||
event_key TEXT NOT NULL,
|
||||
signature TEXT NOT NULL,
|
||||
slot BIGINT NOT NULL,
|
||||
instruction_path TEXT NOT NULL,
|
||||
program_id TEXT NOT NULL,
|
||||
protocol_code TEXT NOT NULL,
|
||||
surface_code TEXT NOT NULL,
|
||||
event_code TEXT NOT NULL,
|
||||
event_name TEXT NOT NULL,
|
||||
event_family TEXT NOT NULL,
|
||||
source_kind TEXT NOT NULL,
|
||||
confidence TEXT NOT NULL,
|
||||
proof_kind TEXT NOT NULL,
|
||||
proof_jsonb JSONB NOT NULL,
|
||||
payload_jsonb JSONB NOT NULL,
|
||||
transaction_failed BOOLEAN NOT NULL,
|
||||
transaction_error_jsonb JSONB,
|
||||
observation_committed BOOLEAN NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
CONSTRAINT pk_kb_sol_decode_events PRIMARY KEY (id),
|
||||
CONSTRAINT ck_kb_sol_decode_events_slot_non_negative CHECK (slot >= 0),
|
||||
CONSTRAINT ck_kb_sol_decode_events_failed_not_committed CHECK (NOT transaction_failed OR NOT observation_committed)
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS ux_kb_sol_decode_events_processor_input_event
|
||||
ON kb_sol_decode_events (processor_name, processor_version, input_key, event_key);
|
||||
CREATE INDEX IF NOT EXISTS ix_kb_sol_decode_events_signature_path
|
||||
ON kb_sol_decode_events (signature, instruction_path);
|
||||
CREATE INDEX IF NOT EXISTS ix_kb_sol_decode_events_program_surface
|
||||
ON kb_sol_decode_events (program_id, surface_code, event_code);
|
||||
CREATE INDEX IF NOT EXISTS ix_kb_sol_decode_events_family_commit
|
||||
ON kb_sol_decode_events (event_family, transaction_failed, observation_committed);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS kb_sol_decode_coverage_declarations (
|
||||
id BIGSERIAL,
|
||||
processor_name TEXT NOT NULL,
|
||||
processor_version TEXT NOT NULL,
|
||||
program_id TEXT NOT NULL,
|
||||
surface_code TEXT,
|
||||
entry_kind TEXT NOT NULL,
|
||||
entry_code TEXT NOT NULL,
|
||||
discriminator_hex TEXT,
|
||||
historical BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
CONSTRAINT pk_kb_sol_decode_coverage_declarations PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS ux_kb_sol_decode_coverage_declarations_identity
|
||||
ON kb_sol_decode_coverage_declarations (
|
||||
processor_name,
|
||||
processor_version,
|
||||
program_id,
|
||||
COALESCE(surface_code, ''),
|
||||
entry_kind,
|
||||
entry_code,
|
||||
COALESCE(discriminator_hex, '')
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS ix_kb_sol_decode_coverage_declarations_program
|
||||
ON kb_sol_decode_coverage_declarations (program_id, processor_name, processor_version);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS kb_sol_decode_coverage_observations (
|
||||
id BIGSERIAL,
|
||||
processor_name TEXT NOT NULL,
|
||||
processor_version TEXT NOT NULL,
|
||||
input_key TEXT NOT NULL,
|
||||
input_hash TEXT NOT NULL,
|
||||
signature TEXT NOT NULL,
|
||||
slot BIGINT NOT NULL,
|
||||
instruction_path TEXT NOT NULL,
|
||||
program_id TEXT NOT NULL,
|
||||
surface_code TEXT,
|
||||
entry_code TEXT,
|
||||
discriminator_hex TEXT,
|
||||
status TEXT NOT NULL,
|
||||
recognized BOOLEAN NOT NULL,
|
||||
decoded_count INTEGER NOT NULL DEFAULT 0,
|
||||
materialized_count INTEGER NOT NULL DEFAULT 0,
|
||||
error_count INTEGER NOT NULL DEFAULT 0,
|
||||
transaction_failed BOOLEAN NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
CONSTRAINT pk_kb_sol_decode_coverage_observations PRIMARY KEY (id),
|
||||
CONSTRAINT ck_kb_sol_decode_coverage_observations_slot_non_negative CHECK (slot >= 0),
|
||||
CONSTRAINT ck_kb_sol_decode_coverage_observations_counts_non_negative CHECK (decoded_count >= 0 AND materialized_count >= 0 AND error_count >= 0)
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS ux_kb_sol_decode_coverage_observations_identity
|
||||
ON kb_sol_decode_coverage_observations (processor_name, processor_version, input_key);
|
||||
CREATE INDEX IF NOT EXISTS ix_kb_sol_decode_coverage_observations_program_status
|
||||
ON kb_sol_decode_coverage_observations (program_id, status, transaction_failed);
|
||||
CREATE INDEX IF NOT EXISTS ix_kb_sol_decode_coverage_observations_entry
|
||||
ON kb_sol_decode_coverage_observations (processor_name, processor_version, surface_code, entry_code);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS kb_sol_mat_events (
|
||||
id BIGSERIAL,
|
||||
processor_name TEXT NOT NULL,
|
||||
processor_version TEXT NOT NULL,
|
||||
input_key TEXT NOT NULL,
|
||||
input_hash TEXT NOT NULL,
|
||||
output_key TEXT NOT NULL,
|
||||
source_event_key TEXT NOT NULL,
|
||||
source_decoder_name TEXT NOT NULL,
|
||||
source_decoder_version TEXT NOT NULL,
|
||||
source_decode_input_key TEXT NOT NULL,
|
||||
signature TEXT NOT NULL,
|
||||
slot BIGINT NOT NULL,
|
||||
materialized_family TEXT NOT NULL,
|
||||
payload_jsonb JSONB NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
CONSTRAINT pk_kb_sol_mat_events PRIMARY KEY (id),
|
||||
CONSTRAINT ck_kb_sol_mat_events_slot_non_negative CHECK (slot >= 0)
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS ux_kb_sol_mat_events_processor_input_output
|
||||
ON kb_sol_mat_events (processor_name, processor_version, input_key, output_key);
|
||||
CREATE INDEX IF NOT EXISTS ix_kb_sol_mat_events_signature_family
|
||||
ON kb_sol_mat_events (source_decoder_name, source_decoder_version, source_decode_input_key, signature, materialized_family);
|
||||
Reference in New Issue
Block a user