v0.5.3-pre.003

This commit is contained in:
2026-08-12 11:00:59 +02:00
parent 8448ad1079
commit 400ced4832
313 changed files with 7773 additions and 2623 deletions

View File

@@ -1,8 +1,53 @@
<!-- file: ks-store/CHANGELOG.md -->
<!-- version: 23 -->
<!-- version: 29 -->
# CHANGELOG — ks-store
## `0.5.3-pre.003`
### Fix `pre.003-delta-fix-005`
- remplace le passage des statements SQLx en `TRACE` par `ConnectOptions::disable_statement_logging`, afin que `ks-store` ne dépende pas directement de la crate `log` uniquement pour `LevelFilter` ;
- conserve l'ouverture PostgreSQL via `PgConnectOptions` + `connect_with` et la journalisation fonctionnelle propre à `ks-store` sous `target: crate::TRACING_TARGET` ;
- adapte le canari de connexion pour vérifier explicitement la désactivation du statement logging SQLx.
### Fix `pre.003-delta-fix-004`
- configure `PgConnectOptions` pour émettre les statements SQLx ordinaires au niveau `TRACE` avant l'ouverture du pool via `connect_with`, tout en conservant le target tiers `sqlx::query` ;
- préserve les événements fonctionnels PostgreSQL `ks-store` sous `target: crate::TRACING_TARGET` avec `backend`, `domain` et `action` ;
- ajoute un canari positif vérifiant le chemin `PgConnectOptions` + `TRACE` + `connect_with`.
### Fix `pre.003-delta-fix-003`
- corrige la branche `incomplete_signatures` de la sélection N2 -> N3 : le `SELECT` contextualisé projette désormais `stack_height` comme l'exige `CoreInstructionRow` ;
- extrait cette requête rare dans `INCOMPLETE_DECODE_INPUTS_SQL` et ajoute un test contractuel vérifiant toutes les colonnes attendues par le mapper Core, afin d'éviter une nouvelle dérive requête/DTO.
### Baseline N1-N3 PostgreSQL
- corrige le premier delta `pre.003` : fermeture de l'`impl PostgresStore`, appels des helpers privés de tests via `super::` et retrait des validateurs de noms de tables du runtime/re-export crate-root ; ces validateurs restent des canaris privés `#[cfg(test)]`.
- reconstruit directement le schéma actif sous `k_sol_*` avec un baseline candidat au gel de **16 tables** : les 13 tables historiques conservées plus `k_sol_obs_account_observations`, `k_sol_core_account_states` et `k_sol_core_return_data` révélées par le canari future-decoder ;
- ajoute `block_time` aux ancres raw/Core transaction, `stack_height` aux contrats top-level/CPI et un lifecycle de processing symétrique pour les CPI ; la reconstruction de Core préserve le parent CPI immédiat lorsque la pile est disponible ;
- renomme le journal N3 en `k_sol_mat_outputs` et aligne l'API publique sur `MaterializedOutputFilter`, `MaterializedOutputQueryRow` et `list_materialized_outputs` ;
- réserve sur `k_sol_decode_events` une provenance nullable de schéma externe (`kind/id/version/hash`) afin qu'un futur décodeur IDL puisse tracer son schéma sans remodeler N1/N2/N3.
### Ressources et initialisation
- corrige `pre.003-delta-fix-002` l'ordre transactionnel des contraintes : les clés primaires référencées sont désormais appliquées avant les clés étrangères ; ajoute un canari couvrant les neuf dépendances FK du baseline afin d'empêcher un nouvel ordre invalide et le rollback complet observé sur base vide ;
- remplace les migrations historiques `0001` à `0004` et les deux scripts de maintenance monolithiques par **236 ressources PostgreSQL atomiques** sous `migrations/postgres/` : tables, contraintes, index, `TRUNCATE` et `DROP`, une instruction SQL par fichier embarquée par `include_str!` ;
- centralise l'initialisation dans un seul orchestrateur PostgreSQL transactionnel avec advisory lock ; les initialiseurs raw/Core/decode partiels sont supprimés, y compris dans les tests ;
- refuse explicitement la présence d'objets historiques `kb_sol_*` au lieu de mélanger les deux namespaces ;
- remplace la lecture `_sqlx_migrations` comme preuve du schéma courant par la vérification du contrat réellement observé ;
- étend le résumé backend-agnostique aux catégories physiques `table` et `index`, avec **75 index attendus** sans exposer leurs noms.
### Readiness et contrats
- conserve explicitement la `returnData` en N2 et enrichit le replay Core v3 avec `block_time`, `stack_height`, parent CPI, contexte top-level et return data ;
- introduit les DTO N1/N2 génériques d'observation/état de compte nécessaires au futur décodage de layouts inconnus, sans ajouter de structure Anchor/IDL spécifique ; leur ingestion/replay fonctionnel est raccordé dans la tranche repositories/replay ;
- ajoute un canari workspace imposant `crate::Type` pour les types publics de `ks-store` utilisés dans leur crate propriétaire ;
- ne crée aucune table DEX/trading ni projection metadata N4 et ne déclare pas encore le gel formel : le snapshot final reste prévu après les validations techniques.
## `0.5.3-pre.002-delta-fix-003`
- corrige deux appels de helpers strictement privés PostgreSQL qui avaient été qualifiés à tort via `crate::`; ils restent locaux à leur module et ne sont pas réexportés au crate-root ;

View File

@@ -1,5 +1,5 @@
# file: ks-store/Cargo.toml
# version: 3
# version: 5
[package]
name = "ks-store"

View File

@@ -1,5 +1,5 @@
<!-- file: ks-store/README.md -->
<!-- version: 6 -->
<!-- version: 7 -->
# ks-store
@@ -10,7 +10,7 @@
La crate expose :
- `Store` et `StoreOpenOptions` comme façade d'ouverture et handle persistant backend-agnostique ;
- les DTO et entités raw, observations, Core, décodage, matérialisation et ledger ;
- les DTO et entités N1 raw/acquisition, N2 Core, N3 decode/materialization et ledger ;
- les traits async `StoreHealthStore`, `RawTransactionStore`, `CoreTransactionStore`, `CoreExtractionStore` et `DecodePipelineStore` ;
- les filtres et résultats de replay sans préfixe backend ;
- des diagnostics et résumés runtime/init sanitisés ne révélant ni secret ni nom physique d'objet ;
@@ -26,11 +26,35 @@ La crate expose :
`StoreOpenOptions` ne dérive pas `Debug` et ne rend pas les options backend accessibles après construction. Les résumés publics exposent uniquement des informations explicitement sanitisées : code backend, présence d'une connexion, état d'initialisation, health, modèle logique et compteurs.
Le backend PostgreSQL masque le descripteur de connexion et utilise lunique target de crate `ks-store`, complété par `backend="postgres"`, `domain="ks-store.pg"` et un champ `action` structuré. Aucun DSN, password ou valeur bindée n'est destiné aux diagnostics publics.
Le backend PostgreSQL masque le descripteur de connexion et utilise l'unique target de crate `ks-store`, complété par `backend="postgres"`, `domain="ks-store.pg"` et un champ `action` structuré. Aucun DSN, password ou valeur bindée n'est destiné aux diagnostics publics.
## Schéma pendant `0.5.3`
## Baseline PostgreSQL `0.5.3-pre.003`
`0.5.3-pre.002` ne modifie pas encore les tables héritées `kb_sol_*`. Leur reconstruction sous `k_sol_*`, les ressources SQL atomiques et le gel N1/N2/N3 commencent en `pre.003` conformément au plan actif.
`pre.003` reconstruit directement le schéma actif sous le namespace `k_sol_*`. Les quatre migrations historiques `0001` à `0004` et les deux scripts de maintenance monolithiques ne font plus partie de la chaîne active.
Le baseline candidat au gel comprend **16 tables N1-N3** :
- N1 : transactions raw, observations d'acquisition de transactions et observations génériques de comptes ;
- N2 : transaction Core, clés de comptes, instructions top-level, CPI, logs, variations de balances, return data et états canoniques de comptes ;
- N3/transverse : processing ledger, événements décodés, déclarations/observations de couverture et `k_sol_mat_outputs`.
Les ressources PostgreSQL sont rangées sous `migrations/postgres/` et suivent la règle **une instruction SQL par fichier**. L'orchestrateur privé applique tables, contraintes et index dans une transaction unique et refuse explicitement un schéma historique contenant encore des objets `kb_sol_*`.
Le baseline comporte actuellement **236 ressources SQL atomiques** et **75 index attendus**, comptés sans exposer leurs noms dans l'API publique.
## Readiness des futurs décodeurs
Le canari future-decoder a conduit à trois corrections génériques avant gel :
- `block_time` devient une colonne de premier rang sur raw/Core transaction ;
- `returnData` est conservée explicitement dans le Core via `k_sol_core_return_data` ;
- un chemin générique d'observation/état de compte est réservé via `k_sol_obs_account_observations` et `k_sol_core_account_states`.
Les instructions top-level et CPI restent physiquement séparées. Les deux contrats portent `stack_height` lorsque disponible ; les CPI conservent un `parent_instruction_path` vers le parent immédiat reconstructible.
N3 réserve en outre une provenance de schéma nullable sur les observations décodées afin qu'un futur décodeur basé sur un schéma externe/IDL puisse tracer ce schéma sans remodeler le Core.
Aucune structure `anchor_*`, DEX ou projection metadata N4 n'est créée en `pre.003`.
## Responsabilités
@@ -43,7 +67,7 @@ Le backend PostgreSQL masque le descripteur de connexion et utilise lunique t
## Hors périmètre
La crate ne décode pas les instructions, n'acquiert pas les transactions et ne décide pas quelle matérialisation ou projection N4 exécuter. Elle persiste les faits produits par `ks-lib` et orchestrés par `ks-pipeline`.
La crate ne décode pas les instructions, n'acquiert pas elle-même les transactions/comptes et ne décide pas quelle matérialisation ou projection N4 exécuter. Elle persiste les faits produits par `ks-lib` et orchestrés par `ks-pipeline`.
## Relations

View File

@@ -1,17 +1,19 @@
<!-- file: ks-store/TODO.md -->
<!-- version: 13 -->
<!-- version: 14 -->
# TODO — ks-store
## Série `0.5.x`
- [ ] `0.5.3`reconstruire `kb_sol_* -> k_sol_*`, ajouter `block_time` aux ancres raw/Core, conserver top-level/CPI dans deux tables Core avec lifecycle/replay équivalents, `stack_height`/parent CPI audités et renommer le journal N3 en `k_sol_mat_outputs`.
- [ ] `0.5.3`déplacer les ressources sous `migrations/postgres/`, imposer une instruction SQL par fichier avec exécution privée via `include_str!`, séparer tables/keys/index/drop/truncate et supprimer le DDL dupliqué en Rust.
- [ ] `0.5.3`corriger l'invalidation descendante, formaliser les replays N1 -> N2 / N2 -> N3 / frontière N3 -> N4, les paginations/limites, les conversions BIGINT et les index justifiés par les requêtes réelles.
- [ ] `0.5.3`finaliser en `pre.005` la présentation fonctionnelle des surfaces `demo_store_*`, `demo_config` et le splash autour des modèles/compteurs du nouveau baseline sans noms d'objets physiques ; le renommage technique `demo_sql_* -> demo_store_*` est réalisé en `pre.002`.
- [ ] `0.5.3`exécuter avant gel le canari future-decoder/Anchor-readiness sur N1/N2/N3 : bytes d'instruction, comptes ordonnés/flags, hiérarchie CPI, logs, `returnData`, observations/états de comptes et provenance decoder/schema ; ajouter seulement les contrats Solana génériques manquants, sans table `anchor_*`.
- [ ] `0.5.3`produire le snapshot machine-readable des tables N1/N2/N3 réellement stabilisées après ce canari (13 tables existantes de baseline, plus éventuels contrats génériques nécessaires), documenter la politique N4 plus souple et les futures projections metadata asset/token + program metadata, puis ajouter les canaris anti-`kb_sol_*`, anti-backend leak, anti-secret et logging sous le target canonique `ks-store` avec domaine structuré `ks-store.pg`.
- [ ] PostgreSQL - auditer le dimensionnement du pool selon les charges réelles.
- [ ] Résilience - décider et implémenter, si justifié, un retry borné pour les timeouts transitoires.
- [ ] Administration - définir les outils supplémentaires prévus par le ROADMAP avant leur implémentation.
- [ ] Historique - documenter et tester les futures opérations historiques ajoutées à la crate.
- [ ] `0.5.3`finaliser en `pre.004` les repositories/replay au-dessus du baseline de 16 tables : sélection autonome des CPI, lecture logique top-level+CPI, invalidation descendante, replay N1 -> N2 / N2 -> N3 / frontière N3 -> N4 et ingestion/replay du nouveau couple observation/état de compte.
- [ ] `0.5.3`finaliser en `pre.004` pagination/limites, conversions BIGINT et plans/index justifiés par les requêtes réelles ; les 75 index du baseline `pre.003` restent optimisables avant gel.
- [ ] `0.5.3`finaliser en `pre.005` la présentation fonctionnelle des surfaces `demo_store_*`, `demo_config` et le splash autour des modèles/compteurs du nouveau baseline sans noms d'objets physiques.
- [ ] `0.5.3`produire le snapshot machine-readable du baseline N1/N2/N3 réellement stabilisé, ajouter les canaris de gel/anti-`kb_sol_*`/anti-backend leak/anti-secret, confirmer le canari future-decoder sur transactions + comptes et documenter la politique N4 plus souple.
- [ ] `0.5.3`valider PostgreSQL réel sur base vide/recréée : 16 tables, index attendus, réouverture idempotente, refus de l'ancien namespace, rollback et roundtrips raw/Core/decode/materialization.
- [ ] `0.5.x`concevoir les projections N4 metadata : asset/token metadata commune Metaplex + Token-2022 et program metadata séparée pour SPM, toutes deux reconstructibles depuis `k_sol_mat_outputs`.
## Plus tard
- [ ] définir une stratégie de pool/réessai configurable commune aux futurs backends sans exposer leurs types de connexion ;
- [ ] décider si un journal append-only des tentatives de processing doit compléter le ledger courant ;
- [ ] ajouter des projections spécialisées uniquement lorsqu'un décodeur/materializer et un besoin queryable réel en démontrent les invariants.

View File

@@ -1,5 +1,5 @@
<!-- file: ks-store/USAGE.md -->
<!-- version: 5 -->
<!-- version: 6 -->
# Utilisation de ks-store
@@ -27,7 +27,30 @@ let store = match ks_store::Store::open(options).await {
};
```
`Store::open` interprète les options du backend actif, crée la connexion, exécute l'auto-initialisation lorsqu'elle est configurée et capture un résumé d'initialisation sanitisé. PostgreSQL reste le seul backend opérationnel exigé en `0.5.3-pre.002`; un code backend inconnu est refusé proprement.
`Store::open` interprète les options du backend actif, crée la connexion, exécute l'auto-initialisation lorsqu'elle est configurée et capture un résumé d'initialisation sanitisé. PostgreSQL reste le seul backend opérationnel exigé en `0.5.3`; un code backend inconnu est refusé proprement.
Avec PostgreSQL, l'auto-initialisation utilise un **seul orchestrateur transactionnel global**. Il ne faut pas initialiser séparément raw/Core/decode : la cohérence du baseline est vérifiée comme un contrat unique.
## Baseline PostgreSQL actif
`0.5.3-pre.003` utilise directement le namespace `k_sol_*` et un baseline candidat au gel de 16 tables N1-N3. Une base contenant encore des objets `kb_sol_*` est refusée ; elle doit être supprimée/reconstruite explicitement.
Les ressources actives sont sous :
```text
ks-store/migrations/postgres/
schema/
tables/
constraints/
indexes/
maintenance/
truncate/
drop/
```
Chaque fichier contient une seule instruction SQL. Les fonctions privées du backend l'embarquent par `include_str!`; le DDL n'est pas dupliqué dans des chaînes Rust.
Le baseline courant compte 236 ressources SQL atomiques et 75 index attendus.
## Résumés sûrs
@@ -42,7 +65,7 @@ let runtime = match store.runtime_summary().await {
Ces contrats ne contiennent pas les options backend brutes. Le descripteur de connexion éventuellement exposé par `runtime.backend` est masqué par le backend propriétaire.
Le résumé d'initialisation classe les ressources par modèles logiques et fournit des compteurs. Il expose aussi `objects`, une liste de catégories physiques sans noms d'objets : PostgreSQL publie déjà le total `table`, tandis que `pre.003` ajoutera le total `index` avec le nouveau baseline. Les noms physiques de tables, index et contraintes restent internes au backend.
Le résumé d'initialisation classe les ressources par modèles logiques et fournit des compteurs. `objects` expose des catégories physiques sans noms d'objets. PostgreSQL publie actuellement les catégories `table` et `index`; un futur backend peut publier d'autres catégories sans modifier le contrat desktop.
## Diagnostics de ressources
@@ -61,7 +84,7 @@ for resource in raw_resources {
}
```
Les méthodes `core_resource_diagnostics`, `decode_resource_diagnostics` et `known_resource_diagnostics` suivent le même contrat backend-agnostique.
Les méthodes `core_resource_diagnostics`, `decode_resource_diagnostics` et `known_resource_diagnostics` suivent le même contrat backend-agnostique. Les codes de ressources publics sont logiques ; les noms physiques PostgreSQL restent internes.
## Contrats de repositories
@@ -73,7 +96,33 @@ Les traits publics effectivement implémentés sont :
- `CoreExtractionStore` ;
- `DecodePipelineStore`.
`Store` implémente ces traits et délègue au backend privé. Les anciens traits historiques sans implémentation réelle ont été retirés avant gel de l'API.
`Store` implémente ces traits et délègue au backend privé.
Le schéma `pre.003` réserve aussi les contrats génériques d'observation/état de comptes nécessaires au gel N1/N2. Leur ingestion/replay opérationnel est raccordé dans la tranche repositories/replay suivante ; leur présence dans le baseline évite une modification structurelle ultérieure pour un futur décodeur de comptes.
## Core et replay N2 -> N3
Le replay d'instruction Core transporte désormais :
- `block_time` nullable ;
- `stack_height` nullable ;
- `parent_instruction_path` pour les CPI ;
- le contexte ordonné des instructions top-level ;
- la `returnData` transactionnelle lorsqu'elle existe.
Le contrat de replay Core est en version 3. Les anciens constructeurs restent utilisables pour les tests/sources synthétiques ; `ks-store` enrichit les inputs issus du Core persistant avec le contexte disponible.
Les instructions top-level et CPI restent deux tables physiques. La sélection logique commune et le replay autonome des CPI sont finalisés dans la tranche repositories/replay.
## Matérialisation N3
Le journal générique est `k_sol_mat_outputs`. L'API publique utilise désormais :
- `MaterializedOutputFilter` ;
- `MaterializedOutputQueryRow` ;
- `DecodePipelineStore::list_materialized_outputs`.
`k_sol_mat_outputs` reste obligatoire même lorsque des projections N4 spécialisées existeront.
## Replay et requêtes bornées
@@ -92,7 +141,7 @@ let entities = match store.replay_entity_summaries(entity_filter).await {
};
```
Les contrats publics utilisent `ReplayTransaction*`, `ReplayProgram*` et `ReplayEntity*`. Le scope d'instruction utilise désormais `TopLevel`, `Inner` et `Logs`; le terme historique `outer` n'est pas introduit dans la nouvelle API.
Les contrats publics utilisent `ReplayTransaction*`, `ReplayProgram*` et `ReplayEntity*`. Le scope d'instruction utilise `TopLevel`, `Inner` et `Logs`; le terme historique `outer` n'est pas introduit dans la nouvelle API store.
## Pagination bornée
@@ -106,7 +155,7 @@ assert_eq!(first_page.limit, ks_store::DEFAULT_PAGE_SIZE);
assert!(next_page.limit <= ks_store::MAX_PAGE_SIZE);
```
La refonte cursorisée prévue par le plan `0.5.3` reste dans la tranche repositories/replay ultérieure.
La refonte cursorisée et la suppression des gros offsets comme contrat durable appartiennent à la tranche repositories/replay.
## Transactions atomiques
@@ -116,9 +165,20 @@ Les bundles `CoreExtractionBundle`, `DecodePersistenceBundle` et `Materializatio
Les tests opt-in utilisent `KS_SECRET_POSTGRES_TEST_URL`. Aucun credential réel ne doit être enregistré dans les fixtures ou logs. Les erreurs d'ouverture de connexion sont volontairement sanitisées.
## Limites de `pre.002`
Pour `pre.003`, les validations PostgreSQL à exécuter après compilation sont particulièrement importantes :
- les tables restent temporairement sous leur namespace historique jusqu'à `pre.003` ;
- les migrations PostgreSQL ne sont pas encore déplacées sous `migrations/postgres/` ;
- la pagination cursorisée et l'invalidation descendante sont traitées dans la tranche repositories/replay ;
- la refonte complète des fenêtres desktop `demo_store_*` est prévue dans la tranche consommateurs.
- init sur base vide ;
- réouverture idempotente ;
- présence des 16 tables et 75 index attendus ;
- refus d'un schéma historique `kb_sol_*` ;
- roundtrip raw/Core/decode/materialization ;
- rollback transactionnel Core/decode.
## Travaux encore ouverts après `pre.003`
- sélection/replay autonome des CPI et lecture logique top-level+CPI ;
- invalidation descendante N1 -> N2 -> N3 -> N4 ;
- replay opérationnel du nouveau flux d'observations/états de comptes ;
- pagination cursorisée et revue finale des index par plans réels ;
- snapshot machine-readable et gel formel en tranche de réconciliation technique ;
- refonte desktop fonctionnelle finale autour du nouveau baseline.

View File

@@ -1,21 +0,0 @@
-- file: ks-store/maintenance/drop_raw_core_store.sql
-- version: 2
-- Drop raw and core Solana storage tables in reverse dependency order.
-- This script is intended for local development and test databases only.
-- It does not drop unrelated schemas, migrations, roles or configuration state.
-- It intentionally avoids CASCADE so unexpected dependencies fail loudly.
-- No custom PostgreSQL enum/domain types are owned by these 0.2.3/0.2.4 tables.
BEGIN;
DROP TABLE IF EXISTS kb_sol_core_balance_changes;
DROP TABLE IF EXISTS kb_sol_core_logs;
DROP TABLE IF EXISTS kb_sol_core_inner_instructions;
DROP TABLE IF EXISTS kb_sol_core_instructions;
DROP TABLE IF EXISTS kb_sol_core_account_keys;
DROP TABLE IF EXISTS kb_sol_core_transactions;
DROP TABLE IF EXISTS kb_sol_obs_transaction_observations;
DROP TABLE IF EXISTS kb_sol_raw_transactions;
COMMIT;

View File

@@ -1,30 +0,0 @@
-- file: ks-store/maintenance/reset_derived_store_keep_raw.sql
-- version: 3
-- Reset every reconstructible Solana projection while preserving acquisition data.
-- Intended for controlled local/research rebuilds only.
-- Preserved tables:
-- - kb_sol_raw_transactions
-- - kb_sol_obs_transaction_observations
-- No CASCADE is used: unexpected dependencies fail loudly.
BEGIN;
TRUNCATE TABLE
kb_sol_mat_events,
kb_sol_decode_coverage_observations,
kb_sol_decode_coverage_declarations,
kb_sol_decode_events,
kb_sol_ops_processing_ledger,
kb_sol_core_balance_changes,
kb_sol_core_logs,
kb_sol_core_inner_instructions,
kb_sol_core_instructions,
kb_sol_core_account_keys,
kb_sol_core_transactions
RESTART IDENTITY;
UPDATE kb_sol_raw_transactions
SET
processing_state = 'received',
lifecycle_reason = NULL,
updated_at = NOW();
COMMIT;

View File

@@ -1,94 +0,0 @@
-- file: ks-store/migrations/0001_canonical_transaction_store.sql
-- version: 2
-- 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);

View File

@@ -1,196 +0,0 @@
-- file: ks-store/migrations/0002_core_store.sql
-- version: 2
-- 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;

View File

@@ -1,41 +0,0 @@
-- file: ks-store/migrations/0003_processing_ledger.sql
-- version: 2
-- 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);

View File

@@ -1,132 +0,0 @@
-- file: ks-store/migrations/0004_decode_materialization_store.sql
-- version: 2
-- 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);

View File

@@ -0,0 +1,5 @@
-- file: migrations/postgres/maintenance/drop/drop_table_if_exists_k_sol_core_account_keys.sql
-- version: 1
-- Drop k_sol_core_account_keys explicitly for maintenance.
DROP TABLE IF EXISTS k_sol_core_account_keys CASCADE;

View File

@@ -0,0 +1,5 @@
-- file: migrations/postgres/maintenance/drop/drop_table_if_exists_k_sol_core_account_states.sql
-- version: 1
-- Drop k_sol_core_account_states explicitly for maintenance.
DROP TABLE IF EXISTS k_sol_core_account_states CASCADE;

View File

@@ -0,0 +1,5 @@
-- file: migrations/postgres/maintenance/drop/drop_table_if_exists_k_sol_core_balance_changes.sql
-- version: 1
-- Drop k_sol_core_balance_changes explicitly for maintenance.
DROP TABLE IF EXISTS k_sol_core_balance_changes CASCADE;

View File

@@ -0,0 +1,5 @@
-- file: migrations/postgres/maintenance/drop/drop_table_if_exists_k_sol_core_inner_instructions.sql
-- version: 1
-- Drop k_sol_core_inner_instructions explicitly for maintenance.
DROP TABLE IF EXISTS k_sol_core_inner_instructions CASCADE;

View File

@@ -0,0 +1,5 @@
-- file: migrations/postgres/maintenance/drop/drop_table_if_exists_k_sol_core_instructions.sql
-- version: 1
-- Drop k_sol_core_instructions explicitly for maintenance.
DROP TABLE IF EXISTS k_sol_core_instructions CASCADE;

View File

@@ -0,0 +1,5 @@
-- file: migrations/postgres/maintenance/drop/drop_table_if_exists_k_sol_core_logs.sql
-- version: 1
-- Drop k_sol_core_logs explicitly for maintenance.
DROP TABLE IF EXISTS k_sol_core_logs CASCADE;

View File

@@ -0,0 +1,5 @@
-- file: migrations/postgres/maintenance/drop/drop_table_if_exists_k_sol_core_return_data.sql
-- version: 1
-- Drop k_sol_core_return_data explicitly for maintenance.
DROP TABLE IF EXISTS k_sol_core_return_data CASCADE;

View File

@@ -0,0 +1,5 @@
-- file: migrations/postgres/maintenance/drop/drop_table_if_exists_k_sol_core_transactions.sql
-- version: 1
-- Drop k_sol_core_transactions explicitly for maintenance.
DROP TABLE IF EXISTS k_sol_core_transactions CASCADE;

View File

@@ -0,0 +1,5 @@
-- file: migrations/postgres/maintenance/drop/drop_table_if_exists_k_sol_decode_coverage_declarations.sql
-- version: 1
-- Drop k_sol_decode_coverage_declarations explicitly for maintenance.
DROP TABLE IF EXISTS k_sol_decode_coverage_declarations CASCADE;

View File

@@ -0,0 +1,5 @@
-- file: migrations/postgres/maintenance/drop/drop_table_if_exists_k_sol_decode_coverage_observations.sql
-- version: 1
-- Drop k_sol_decode_coverage_observations explicitly for maintenance.
DROP TABLE IF EXISTS k_sol_decode_coverage_observations CASCADE;

View File

@@ -0,0 +1,5 @@
-- file: migrations/postgres/maintenance/drop/drop_table_if_exists_k_sol_decode_events.sql
-- version: 1
-- Drop k_sol_decode_events explicitly for maintenance.
DROP TABLE IF EXISTS k_sol_decode_events CASCADE;

View File

@@ -0,0 +1,5 @@
-- file: migrations/postgres/maintenance/drop/drop_table_if_exists_k_sol_mat_outputs.sql
-- version: 1
-- Drop k_sol_mat_outputs explicitly for maintenance.
DROP TABLE IF EXISTS k_sol_mat_outputs CASCADE;

View File

@@ -0,0 +1,5 @@
-- file: migrations/postgres/maintenance/drop/drop_table_if_exists_k_sol_obs_account_observations.sql
-- version: 1
-- Drop k_sol_obs_account_observations explicitly for maintenance.
DROP TABLE IF EXISTS k_sol_obs_account_observations CASCADE;

View File

@@ -0,0 +1,5 @@
-- file: migrations/postgres/maintenance/drop/drop_table_if_exists_k_sol_obs_transaction_observations.sql
-- version: 1
-- Drop k_sol_obs_transaction_observations explicitly for maintenance.
DROP TABLE IF EXISTS k_sol_obs_transaction_observations CASCADE;

View File

@@ -0,0 +1,5 @@
-- file: migrations/postgres/maintenance/drop/drop_table_if_exists_k_sol_ops_processing_ledger.sql
-- version: 1
-- Drop k_sol_ops_processing_ledger explicitly for maintenance.
DROP TABLE IF EXISTS k_sol_ops_processing_ledger CASCADE;

View File

@@ -0,0 +1,5 @@
-- file: migrations/postgres/maintenance/drop/drop_table_if_exists_k_sol_raw_transactions.sql
-- version: 1
-- Drop k_sol_raw_transactions explicitly for maintenance.
DROP TABLE IF EXISTS k_sol_raw_transactions CASCADE;

View File

@@ -0,0 +1,5 @@
-- file: migrations/postgres/maintenance/truncate/truncate_table_k_sol_core_account_keys.sql
-- version: 1
-- Truncate k_sol_core_account_keys explicitly for maintenance.
TRUNCATE TABLE k_sol_core_account_keys RESTART IDENTITY CASCADE;

View File

@@ -0,0 +1,5 @@
-- file: migrations/postgres/maintenance/truncate/truncate_table_k_sol_core_account_states.sql
-- version: 1
-- Truncate k_sol_core_account_states explicitly for maintenance.
TRUNCATE TABLE k_sol_core_account_states RESTART IDENTITY CASCADE;

View File

@@ -0,0 +1,5 @@
-- file: migrations/postgres/maintenance/truncate/truncate_table_k_sol_core_balance_changes.sql
-- version: 1
-- Truncate k_sol_core_balance_changes explicitly for maintenance.
TRUNCATE TABLE k_sol_core_balance_changes RESTART IDENTITY CASCADE;

View File

@@ -0,0 +1,5 @@
-- file: migrations/postgres/maintenance/truncate/truncate_table_k_sol_core_inner_instructions.sql
-- version: 1
-- Truncate k_sol_core_inner_instructions explicitly for maintenance.
TRUNCATE TABLE k_sol_core_inner_instructions RESTART IDENTITY CASCADE;

View File

@@ -0,0 +1,5 @@
-- file: migrations/postgres/maintenance/truncate/truncate_table_k_sol_core_instructions.sql
-- version: 1
-- Truncate k_sol_core_instructions explicitly for maintenance.
TRUNCATE TABLE k_sol_core_instructions RESTART IDENTITY CASCADE;

View File

@@ -0,0 +1,5 @@
-- file: migrations/postgres/maintenance/truncate/truncate_table_k_sol_core_logs.sql
-- version: 1
-- Truncate k_sol_core_logs explicitly for maintenance.
TRUNCATE TABLE k_sol_core_logs RESTART IDENTITY CASCADE;

View File

@@ -0,0 +1,5 @@
-- file: migrations/postgres/maintenance/truncate/truncate_table_k_sol_core_return_data.sql
-- version: 1
-- Truncate k_sol_core_return_data explicitly for maintenance.
TRUNCATE TABLE k_sol_core_return_data RESTART IDENTITY CASCADE;

View File

@@ -0,0 +1,5 @@
-- file: migrations/postgres/maintenance/truncate/truncate_table_k_sol_core_transactions.sql
-- version: 1
-- Truncate k_sol_core_transactions explicitly for maintenance.
TRUNCATE TABLE k_sol_core_transactions RESTART IDENTITY CASCADE;

View File

@@ -0,0 +1,5 @@
-- file: migrations/postgres/maintenance/truncate/truncate_table_k_sol_decode_coverage_declarations.sql
-- version: 1
-- Truncate k_sol_decode_coverage_declarations explicitly for maintenance.
TRUNCATE TABLE k_sol_decode_coverage_declarations RESTART IDENTITY CASCADE;

View File

@@ -0,0 +1,5 @@
-- file: migrations/postgres/maintenance/truncate/truncate_table_k_sol_decode_coverage_observations.sql
-- version: 1
-- Truncate k_sol_decode_coverage_observations explicitly for maintenance.
TRUNCATE TABLE k_sol_decode_coverage_observations RESTART IDENTITY CASCADE;

View File

@@ -0,0 +1,5 @@
-- file: migrations/postgres/maintenance/truncate/truncate_table_k_sol_decode_events.sql
-- version: 1
-- Truncate k_sol_decode_events explicitly for maintenance.
TRUNCATE TABLE k_sol_decode_events RESTART IDENTITY CASCADE;

View File

@@ -0,0 +1,5 @@
-- file: migrations/postgres/maintenance/truncate/truncate_table_k_sol_mat_outputs.sql
-- version: 1
-- Truncate k_sol_mat_outputs explicitly for maintenance.
TRUNCATE TABLE k_sol_mat_outputs RESTART IDENTITY CASCADE;

View File

@@ -0,0 +1,5 @@
-- file: migrations/postgres/maintenance/truncate/truncate_table_k_sol_obs_account_observations.sql
-- version: 1
-- Truncate k_sol_obs_account_observations explicitly for maintenance.
TRUNCATE TABLE k_sol_obs_account_observations RESTART IDENTITY CASCADE;

View File

@@ -0,0 +1,5 @@
-- file: migrations/postgres/maintenance/truncate/truncate_table_k_sol_obs_transaction_observations.sql
-- version: 1
-- Truncate k_sol_obs_transaction_observations explicitly for maintenance.
TRUNCATE TABLE k_sol_obs_transaction_observations RESTART IDENTITY CASCADE;

View File

@@ -0,0 +1,5 @@
-- file: migrations/postgres/maintenance/truncate/truncate_table_k_sol_ops_processing_ledger.sql
-- version: 1
-- Truncate k_sol_ops_processing_ledger explicitly for maintenance.
TRUNCATE TABLE k_sol_ops_processing_ledger RESTART IDENTITY CASCADE;

View File

@@ -0,0 +1,5 @@
-- file: migrations/postgres/maintenance/truncate/truncate_table_k_sol_raw_transactions.sql
-- version: 1
-- Truncate k_sol_raw_transactions explicitly for maintenance.
TRUNCATE TABLE k_sol_raw_transactions RESTART IDENTITY CASCADE;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_account_keys_index_non_negative.sql
-- version: 1
-- Add ck_k_sol_core_account_keys_index_non_negative to k_sol_core_account_keys when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_account_keys_index_non_negative'
AND conrelid = to_regclass('k_sol_core_account_keys')
) THEN
ALTER TABLE k_sol_core_account_keys ADD CONSTRAINT ck_k_sol_core_account_keys_index_non_negative CHECK (account_index >= 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_account_keys_key_not_empty.sql
-- version: 1
-- Add ck_k_sol_core_account_keys_key_not_empty to k_sol_core_account_keys when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_account_keys_key_not_empty'
AND conrelid = to_regclass('k_sol_core_account_keys')
) THEN
ALTER TABLE k_sol_core_account_keys ADD CONSTRAINT ck_k_sol_core_account_keys_key_not_empty CHECK (length(btrim(account_key)) > 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_account_keys_signature_not_empty.sql
-- version: 1
-- Add ck_k_sol_core_account_keys_signature_not_empty to k_sol_core_account_keys when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_account_keys_signature_not_empty'
AND conrelid = to_regclass('k_sol_core_account_keys')
) THEN
ALTER TABLE k_sol_core_account_keys ADD CONSTRAINT ck_k_sol_core_account_keys_signature_not_empty CHECK (length(btrim(signature)) > 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_account_keys_slot_non_negative.sql
-- version: 1
-- Add ck_k_sol_core_account_keys_slot_non_negative to k_sol_core_account_keys when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_account_keys_slot_non_negative'
AND conrelid = to_regclass('k_sol_core_account_keys')
) THEN
ALTER TABLE k_sol_core_account_keys ADD CONSTRAINT ck_k_sol_core_account_keys_slot_non_negative CHECK (slot >= 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_account_keys_source.sql
-- version: 1
-- Add ck_k_sol_core_account_keys_source to k_sol_core_account_keys when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_account_keys_source'
AND conrelid = to_regclass('k_sol_core_account_keys')
) THEN
ALTER TABLE k_sol_core_account_keys ADD CONSTRAINT ck_k_sol_core_account_keys_source CHECK (source IN ('static', 'loaded_writable', 'loaded_readonly'));
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_account_states_account_not_empty.sql
-- version: 1
-- Add ck_k_sol_core_account_states_account_not_empty to k_sol_core_account_states when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_account_states_account_not_empty'
AND conrelid = to_regclass('k_sol_core_account_states')
) THEN
ALTER TABLE k_sol_core_account_states ADD CONSTRAINT ck_k_sol_core_account_states_account_not_empty CHECK (length(btrim(account_key)) > 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_account_states_hash_not_empty.sql
-- version: 1
-- Add ck_k_sol_core_account_states_hash_not_empty to k_sol_core_account_states when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_account_states_hash_not_empty'
AND conrelid = to_regclass('k_sol_core_account_states')
) THEN
ALTER TABLE k_sol_core_account_states ADD CONSTRAINT ck_k_sol_core_account_states_hash_not_empty CHECK (length(btrim(data_hash)) > 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_account_states_lamports_non_negative.sql
-- version: 1
-- Add ck_k_sol_core_account_states_lamports_non_negative to k_sol_core_account_states when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_account_states_lamports_non_negative'
AND conrelid = to_regclass('k_sol_core_account_states')
) THEN
ALTER TABLE k_sol_core_account_states ADD CONSTRAINT ck_k_sol_core_account_states_lamports_non_negative CHECK (lamports >= 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_account_states_owner_not_empty.sql
-- version: 1
-- Add ck_k_sol_core_account_states_owner_not_empty to k_sol_core_account_states when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_account_states_owner_not_empty'
AND conrelid = to_regclass('k_sol_core_account_states')
) THEN
ALTER TABLE k_sol_core_account_states ADD CONSTRAINT ck_k_sol_core_account_states_owner_not_empty CHECK (length(btrim(owner)) > 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_account_states_rent_epoch_non_negative.sql
-- version: 1
-- Add ck_k_sol_core_account_states_rent_epoch_non_negative to k_sol_core_account_states when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_account_states_rent_epoch_non_negative'
AND conrelid = to_regclass('k_sol_core_account_states')
) THEN
ALTER TABLE k_sol_core_account_states ADD CONSTRAINT ck_k_sol_core_account_states_rent_epoch_non_negative CHECK (rent_epoch >= 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_account_states_slot_non_negative.sql
-- version: 1
-- Add ck_k_sol_core_account_states_slot_non_negative to k_sol_core_account_states when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_account_states_slot_non_negative'
AND conrelid = to_regclass('k_sol_core_account_states')
) THEN
ALTER TABLE k_sol_core_account_states ADD CONSTRAINT ck_k_sol_core_account_states_slot_non_negative CHECK (slot >= 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_account_states_space_non_negative.sql
-- version: 1
-- Add ck_k_sol_core_account_states_space_non_negative to k_sol_core_account_states when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_account_states_space_non_negative'
AND conrelid = to_regclass('k_sol_core_account_states')
) THEN
ALTER TABLE k_sol_core_account_states ADD CONSTRAINT ck_k_sol_core_account_states_space_non_negative CHECK (space >= 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_balance_changes_account_index_non_negative.sql
-- version: 1
-- Add ck_k_sol_core_balance_changes_account_index_non_negative to k_sol_core_balance_changes when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_balance_changes_account_index_non_negative'
AND conrelid = to_regclass('k_sol_core_balance_changes')
) THEN
ALTER TABLE k_sol_core_balance_changes ADD CONSTRAINT ck_k_sol_core_balance_changes_account_index_non_negative CHECK (account_index IS NULL OR account_index >= 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_balance_changes_account_not_empty.sql
-- version: 1
-- Add ck_k_sol_core_balance_changes_account_not_empty to k_sol_core_balance_changes when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_balance_changes_account_not_empty'
AND conrelid = to_regclass('k_sol_core_balance_changes')
) THEN
ALTER TABLE k_sol_core_balance_changes ADD CONSTRAINT ck_k_sol_core_balance_changes_account_not_empty CHECK (account_key IS NULL OR length(btrim(account_key)) > 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_balance_changes_index_non_negative.sql
-- version: 1
-- Add ck_k_sol_core_balance_changes_index_non_negative to k_sol_core_balance_changes when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_balance_changes_index_non_negative'
AND conrelid = to_regclass('k_sol_core_balance_changes')
) THEN
ALTER TABLE k_sol_core_balance_changes ADD CONSTRAINT ck_k_sol_core_balance_changes_index_non_negative CHECK (balance_change_index >= 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_balance_changes_kind.sql
-- version: 1
-- Add ck_k_sol_core_balance_changes_kind to k_sol_core_balance_changes when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_balance_changes_kind'
AND conrelid = to_regclass('k_sol_core_balance_changes')
) THEN
ALTER TABLE k_sol_core_balance_changes ADD CONSTRAINT ck_k_sol_core_balance_changes_kind CHECK (balance_kind IN ('native_lamports', 'token_amount'));
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_balance_changes_mint_not_empty.sql
-- version: 1
-- Add ck_k_sol_core_balance_changes_mint_not_empty to k_sol_core_balance_changes when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_balance_changes_mint_not_empty'
AND conrelid = to_regclass('k_sol_core_balance_changes')
) THEN
ALTER TABLE k_sol_core_balance_changes ADD CONSTRAINT ck_k_sol_core_balance_changes_mint_not_empty CHECK (mint IS NULL OR length(btrim(mint)) > 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_balance_changes_owner_not_empty.sql
-- version: 1
-- Add ck_k_sol_core_balance_changes_owner_not_empty to k_sol_core_balance_changes when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_balance_changes_owner_not_empty'
AND conrelid = to_regclass('k_sol_core_balance_changes')
) THEN
ALTER TABLE k_sol_core_balance_changes ADD CONSTRAINT ck_k_sol_core_balance_changes_owner_not_empty CHECK (owner IS NULL OR length(btrim(owner)) > 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_balance_changes_signature_not_empty.sql
-- version: 1
-- Add ck_k_sol_core_balance_changes_signature_not_empty to k_sol_core_balance_changes when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_balance_changes_signature_not_empty'
AND conrelid = to_regclass('k_sol_core_balance_changes')
) THEN
ALTER TABLE k_sol_core_balance_changes ADD CONSTRAINT ck_k_sol_core_balance_changes_signature_not_empty CHECK (length(btrim(signature)) > 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_balance_changes_slot_non_negative.sql
-- version: 1
-- Add ck_k_sol_core_balance_changes_slot_non_negative to k_sol_core_balance_changes when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_balance_changes_slot_non_negative'
AND conrelid = to_regclass('k_sol_core_balance_changes')
) THEN
ALTER TABLE k_sol_core_balance_changes ADD CONSTRAINT ck_k_sol_core_balance_changes_slot_non_negative CHECK (slot >= 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_inner_instructions_parent_not_empty.sql
-- version: 1
-- Add ck_k_sol_core_inner_instructions_parent_not_empty to k_sol_core_inner_instructions when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_inner_instructions_parent_not_empty'
AND conrelid = to_regclass('k_sol_core_inner_instructions')
) THEN
ALTER TABLE k_sol_core_inner_instructions ADD CONSTRAINT ck_k_sol_core_inner_instructions_parent_not_empty CHECK (length(btrim(parent_instruction_path)) > 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_inner_instructions_path_not_empty.sql
-- version: 1
-- Add ck_k_sol_core_inner_instructions_path_not_empty to k_sol_core_inner_instructions when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_inner_instructions_path_not_empty'
AND conrelid = to_regclass('k_sol_core_inner_instructions')
) THEN
ALTER TABLE k_sol_core_inner_instructions ADD CONSTRAINT ck_k_sol_core_inner_instructions_path_not_empty CHECK (length(btrim(instruction_path)) > 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_inner_instructions_processing_state.sql
-- version: 1
-- Add ck_k_sol_core_inner_instructions_processing_state to k_sol_core_inner_instructions when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_inner_instructions_processing_state'
AND conrelid = to_regclass('k_sol_core_inner_instructions')
) THEN
ALTER TABLE k_sol_core_inner_instructions ADD CONSTRAINT ck_k_sol_core_inner_instructions_processing_state CHECK (processing_state IN ('pending', 'decoded', 'materialized', 'ignored', 'failed', 'replay_requested'));
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_inner_instructions_processor_pair.sql
-- version: 1
-- Add ck_k_sol_core_inner_instructions_processor_pair to k_sol_core_inner_instructions when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_inner_instructions_processor_pair'
AND conrelid = to_regclass('k_sol_core_inner_instructions')
) THEN
ALTER TABLE k_sol_core_inner_instructions ADD CONSTRAINT ck_k_sol_core_inner_instructions_processor_pair CHECK ((processor_name IS NULL AND processor_version IS NULL) OR (length(btrim(processor_name)) > 0 AND length(btrim(processor_version)) > 0));
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_inner_instructions_program_not_empty.sql
-- version: 1
-- Add ck_k_sol_core_inner_instructions_program_not_empty to k_sol_core_inner_instructions when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_inner_instructions_program_not_empty'
AND conrelid = to_regclass('k_sol_core_inner_instructions')
) THEN
ALTER TABLE k_sol_core_inner_instructions ADD CONSTRAINT ck_k_sol_core_inner_instructions_program_not_empty CHECK (length(btrim(program_id)) > 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_inner_instructions_signature_not_empty.sql
-- version: 1
-- Add ck_k_sol_core_inner_instructions_signature_not_empty to k_sol_core_inner_instructions when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_inner_instructions_signature_not_empty'
AND conrelid = to_regclass('k_sol_core_inner_instructions')
) THEN
ALTER TABLE k_sol_core_inner_instructions ADD CONSTRAINT ck_k_sol_core_inner_instructions_signature_not_empty CHECK (length(btrim(signature)) > 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_inner_instructions_slot_non_negative.sql
-- version: 1
-- Add ck_k_sol_core_inner_instructions_slot_non_negative to k_sol_core_inner_instructions when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_inner_instructions_slot_non_negative'
AND conrelid = to_regclass('k_sol_core_inner_instructions')
) THEN
ALTER TABLE k_sol_core_inner_instructions ADD CONSTRAINT ck_k_sol_core_inner_instructions_slot_non_negative CHECK (slot >= 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_inner_instructions_stack_height_positive.sql
-- version: 1
-- Add ck_k_sol_core_inner_instructions_stack_height_positive to k_sol_core_inner_instructions when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_inner_instructions_stack_height_positive'
AND conrelid = to_regclass('k_sol_core_inner_instructions')
) THEN
ALTER TABLE k_sol_core_inner_instructions ADD CONSTRAINT ck_k_sol_core_inner_instructions_stack_height_positive CHECK (stack_height IS NULL OR stack_height > 1);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_instructions_path_not_empty.sql
-- version: 1
-- Add ck_k_sol_core_instructions_path_not_empty to k_sol_core_instructions when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_instructions_path_not_empty'
AND conrelid = to_regclass('k_sol_core_instructions')
) THEN
ALTER TABLE k_sol_core_instructions ADD CONSTRAINT ck_k_sol_core_instructions_path_not_empty CHECK (length(btrim(instruction_path)) > 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_instructions_processing_state.sql
-- version: 1
-- Add ck_k_sol_core_instructions_processing_state to k_sol_core_instructions when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_instructions_processing_state'
AND conrelid = to_regclass('k_sol_core_instructions')
) THEN
ALTER TABLE k_sol_core_instructions ADD CONSTRAINT ck_k_sol_core_instructions_processing_state CHECK (processing_state IN ('pending', 'decoded', 'materialized', 'ignored', 'failed', 'replay_requested'));
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_instructions_processor_pair.sql
-- version: 1
-- Add ck_k_sol_core_instructions_processor_pair to k_sol_core_instructions when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_instructions_processor_pair'
AND conrelid = to_regclass('k_sol_core_instructions')
) THEN
ALTER TABLE k_sol_core_instructions ADD CONSTRAINT ck_k_sol_core_instructions_processor_pair CHECK ((processor_name IS NULL AND processor_version IS NULL) OR (length(btrim(processor_name)) > 0 AND length(btrim(processor_version)) > 0));
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_instructions_program_not_empty.sql
-- version: 1
-- Add ck_k_sol_core_instructions_program_not_empty to k_sol_core_instructions when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_instructions_program_not_empty'
AND conrelid = to_regclass('k_sol_core_instructions')
) THEN
ALTER TABLE k_sol_core_instructions ADD CONSTRAINT ck_k_sol_core_instructions_program_not_empty CHECK (length(btrim(program_id)) > 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_instructions_signature_not_empty.sql
-- version: 1
-- Add ck_k_sol_core_instructions_signature_not_empty to k_sol_core_instructions when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_instructions_signature_not_empty'
AND conrelid = to_regclass('k_sol_core_instructions')
) THEN
ALTER TABLE k_sol_core_instructions ADD CONSTRAINT ck_k_sol_core_instructions_signature_not_empty CHECK (length(btrim(signature)) > 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_instructions_slot_non_negative.sql
-- version: 1
-- Add ck_k_sol_core_instructions_slot_non_negative to k_sol_core_instructions when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_instructions_slot_non_negative'
AND conrelid = to_regclass('k_sol_core_instructions')
) THEN
ALTER TABLE k_sol_core_instructions ADD CONSTRAINT ck_k_sol_core_instructions_slot_non_negative CHECK (slot >= 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_instructions_stack_height_positive.sql
-- version: 1
-- Add ck_k_sol_core_instructions_stack_height_positive to k_sol_core_instructions when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_instructions_stack_height_positive'
AND conrelid = to_regclass('k_sol_core_instructions')
) THEN
ALTER TABLE k_sol_core_instructions ADD CONSTRAINT ck_k_sol_core_instructions_stack_height_positive CHECK (stack_height IS NULL OR stack_height > 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_logs_index_non_negative.sql
-- version: 1
-- Add ck_k_sol_core_logs_index_non_negative to k_sol_core_logs when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_logs_index_non_negative'
AND conrelid = to_regclass('k_sol_core_logs')
) THEN
ALTER TABLE k_sol_core_logs ADD CONSTRAINT ck_k_sol_core_logs_index_non_negative CHECK (log_index >= 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_logs_path_not_empty.sql
-- version: 1
-- Add ck_k_sol_core_logs_path_not_empty to k_sol_core_logs when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_logs_path_not_empty'
AND conrelid = to_regclass('k_sol_core_logs')
) THEN
ALTER TABLE k_sol_core_logs ADD CONSTRAINT ck_k_sol_core_logs_path_not_empty CHECK (instruction_path IS NULL OR length(btrim(instruction_path)) > 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_logs_program_not_empty.sql
-- version: 1
-- Add ck_k_sol_core_logs_program_not_empty to k_sol_core_logs when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_logs_program_not_empty'
AND conrelid = to_regclass('k_sol_core_logs')
) THEN
ALTER TABLE k_sol_core_logs ADD CONSTRAINT ck_k_sol_core_logs_program_not_empty CHECK (program_id IS NULL OR length(btrim(program_id)) > 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_logs_signature_not_empty.sql
-- version: 1
-- Add ck_k_sol_core_logs_signature_not_empty to k_sol_core_logs when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_logs_signature_not_empty'
AND conrelid = to_regclass('k_sol_core_logs')
) THEN
ALTER TABLE k_sol_core_logs ADD CONSTRAINT ck_k_sol_core_logs_signature_not_empty CHECK (length(btrim(signature)) > 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_logs_slot_non_negative.sql
-- version: 1
-- Add ck_k_sol_core_logs_slot_non_negative to k_sol_core_logs when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_logs_slot_non_negative'
AND conrelid = to_regclass('k_sol_core_logs')
) THEN
ALTER TABLE k_sol_core_logs ADD CONSTRAINT ck_k_sol_core_logs_slot_non_negative CHECK (slot >= 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_return_data_program_not_empty.sql
-- version: 1
-- Add ck_k_sol_core_return_data_program_not_empty to k_sol_core_return_data when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_return_data_program_not_empty'
AND conrelid = to_regclass('k_sol_core_return_data')
) THEN
ALTER TABLE k_sol_core_return_data ADD CONSTRAINT ck_k_sol_core_return_data_program_not_empty CHECK (length(btrim(program_id)) > 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_return_data_signature_not_empty.sql
-- version: 1
-- Add ck_k_sol_core_return_data_signature_not_empty to k_sol_core_return_data when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_return_data_signature_not_empty'
AND conrelid = to_regclass('k_sol_core_return_data')
) THEN
ALTER TABLE k_sol_core_return_data ADD CONSTRAINT ck_k_sol_core_return_data_signature_not_empty CHECK (length(btrim(signature)) > 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_return_data_slot_non_negative.sql
-- version: 1
-- Add ck_k_sol_core_return_data_slot_non_negative to k_sol_core_return_data when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_return_data_slot_non_negative'
AND conrelid = to_regclass('k_sol_core_return_data')
) THEN
ALTER TABLE k_sol_core_return_data ADD CONSTRAINT ck_k_sol_core_return_data_slot_non_negative CHECK (slot >= 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_transactions_signature_not_empty.sql
-- version: 1
-- Add ck_k_sol_core_transactions_signature_not_empty to k_sol_core_transactions when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_transactions_signature_not_empty'
AND conrelid = to_regclass('k_sol_core_transactions')
) THEN
ALTER TABLE k_sol_core_transactions ADD CONSTRAINT ck_k_sol_core_transactions_signature_not_empty CHECK (length(btrim(signature)) > 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_core_transactions_slot_non_negative.sql
-- version: 1
-- Add ck_k_sol_core_transactions_slot_non_negative to k_sol_core_transactions when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_core_transactions_slot_non_negative'
AND conrelid = to_regclass('k_sol_core_transactions')
) THEN
ALTER TABLE k_sol_core_transactions ADD CONSTRAINT ck_k_sol_core_transactions_slot_non_negative CHECK (slot >= 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_decode_coverage_observations_counts_non_negative.sql
-- version: 1
-- Add ck_k_sol_decode_coverage_observations_counts_non_negative to k_sol_decode_coverage_observations when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_decode_coverage_observations_counts_non_negative'
AND conrelid = to_regclass('k_sol_decode_coverage_observations')
) THEN
ALTER TABLE k_sol_decode_coverage_observations ADD CONSTRAINT ck_k_sol_decode_coverage_observations_counts_non_negative CHECK (decoded_count >= 0 AND materialized_count >= 0 AND error_count >= 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_decode_coverage_observations_slot_non_negative.sql
-- version: 1
-- Add ck_k_sol_decode_coverage_observations_slot_non_negative to k_sol_decode_coverage_observations when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_decode_coverage_observations_slot_non_negative'
AND conrelid = to_regclass('k_sol_decode_coverage_observations')
) THEN
ALTER TABLE k_sol_decode_coverage_observations ADD CONSTRAINT ck_k_sol_decode_coverage_observations_slot_non_negative CHECK (slot >= 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_decode_events_failed_not_committed.sql
-- version: 1
-- Add ck_k_sol_decode_events_failed_not_committed to k_sol_decode_events when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_decode_events_failed_not_committed'
AND conrelid = to_regclass('k_sol_decode_events')
) THEN
ALTER TABLE k_sol_decode_events ADD CONSTRAINT ck_k_sol_decode_events_failed_not_committed CHECK (NOT transaction_failed OR NOT observation_committed);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_decode_events_schema_provenance.sql
-- version: 1
-- Add ck_k_sol_decode_events_schema_provenance to k_sol_decode_events when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_decode_events_schema_provenance'
AND conrelid = to_regclass('k_sol_decode_events')
) THEN
ALTER TABLE k_sol_decode_events ADD CONSTRAINT ck_k_sol_decode_events_schema_provenance CHECK ((schema_kind IS NULL AND schema_id IS NULL AND schema_version IS NULL AND schema_hash IS NULL) OR (length(btrim(schema_kind)) > 0 AND length(btrim(schema_id)) > 0 AND length(btrim(schema_hash)) > 0 AND (schema_version IS NULL OR length(btrim(schema_version)) > 0)));
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_decode_events_slot_non_negative.sql
-- version: 1
-- Add ck_k_sol_decode_events_slot_non_negative to k_sol_decode_events when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_decode_events_slot_non_negative'
AND conrelid = to_regclass('k_sol_decode_events')
) THEN
ALTER TABLE k_sol_decode_events ADD CONSTRAINT ck_k_sol_decode_events_slot_non_negative CHECK (slot >= 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_mat_outputs_slot_non_negative.sql
-- version: 1
-- Add ck_k_sol_mat_outputs_slot_non_negative to k_sol_mat_outputs when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_mat_outputs_slot_non_negative'
AND conrelid = to_regclass('k_sol_mat_outputs')
) THEN
ALTER TABLE k_sol_mat_outputs ADD CONSTRAINT ck_k_sol_mat_outputs_slot_non_negative CHECK (slot >= 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_obs_account_observations_account_not_empty.sql
-- version: 1
-- Add ck_k_sol_obs_account_observations_account_not_empty to k_sol_obs_account_observations when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_obs_account_observations_account_not_empty'
AND conrelid = to_regclass('k_sol_obs_account_observations')
) THEN
ALTER TABLE k_sol_obs_account_observations ADD CONSTRAINT ck_k_sol_obs_account_observations_account_not_empty CHECK (length(btrim(account_key)) > 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_obs_account_observations_commitment_not_empty.sql
-- version: 1
-- Add ck_k_sol_obs_account_observations_commitment_not_empty to k_sol_obs_account_observations when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_obs_account_observations_commitment_not_empty'
AND conrelid = to_regclass('k_sol_obs_account_observations')
) THEN
ALTER TABLE k_sol_obs_account_observations ADD CONSTRAINT ck_k_sol_obs_account_observations_commitment_not_empty CHECK (commitment IS NULL OR length(btrim(commitment)) > 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_obs_account_observations_endpoint_not_empty.sql
-- version: 1
-- Add ck_k_sol_obs_account_observations_endpoint_not_empty to k_sol_obs_account_observations when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_obs_account_observations_endpoint_not_empty'
AND conrelid = to_regclass('k_sol_obs_account_observations')
) THEN
ALTER TABLE k_sol_obs_account_observations ADD CONSTRAINT ck_k_sol_obs_account_observations_endpoint_not_empty CHECK (endpoint_code IS NULL OR length(btrim(endpoint_code)) > 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_obs_account_observations_error_code_not_empty.sql
-- version: 1
-- Add ck_k_sol_obs_account_observations_error_code_not_empty to k_sol_obs_account_observations when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_obs_account_observations_error_code_not_empty'
AND conrelid = to_regclass('k_sol_obs_account_observations')
) THEN
ALTER TABLE k_sol_obs_account_observations ADD CONSTRAINT ck_k_sol_obs_account_observations_error_code_not_empty CHECK (error_code IS NULL OR length(btrim(error_code)) > 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_obs_account_observations_error_message_not_empty.sql
-- version: 1
-- Add ck_k_sol_obs_account_observations_error_message_not_empty to k_sol_obs_account_observations when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_obs_account_observations_error_message_not_empty'
AND conrelid = to_regclass('k_sol_obs_account_observations')
) THEN
ALTER TABLE k_sol_obs_account_observations ADD CONSTRAINT ck_k_sol_obs_account_observations_error_message_not_empty CHECK (error_message IS NULL OR length(btrim(error_message)) > 0);
END IF;
END
$$;

View File

@@ -0,0 +1,16 @@
-- file: migrations/postgres/schema/constraints/add_constraint_if_not_exists_ck_k_sol_obs_account_observations_filter_not_empty.sql
-- version: 1
-- Add ck_k_sol_obs_account_observations_filter_not_empty to k_sol_obs_account_observations when absent.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ck_k_sol_obs_account_observations_filter_not_empty'
AND conrelid = to_regclass('k_sol_obs_account_observations')
) THEN
ALTER TABLE k_sol_obs_account_observations ADD CONSTRAINT ck_k_sol_obs_account_observations_filter_not_empty CHECK (filter_code IS NULL OR length(btrim(filter_code)) > 0);
END IF;
END
$$;

Some files were not shown because too many files have changed in this diff Show More