{"record":{"id":"c93b3776671acdf2","repo":"nautechsystems/nautilus_trader","slug":"failed-to-activate-verification-schema-e","errorCode":null,"errorMessage":"Failed to activate verification schema: {e}","messagePattern":"Failed to activate verification schema: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":4587,"sourceCode":"            \"DROP TRIGGER IF EXISTS execution_verification_decision_append_only \\\n             ON execution_verification_decision\",\n            \"\n            CREATE TRIGGER execution_verification_decision_append_only\n            BEFORE UPDATE OR DELETE ON execution_verification_decision\n            FOR EACH STATEMENT EXECUTE FUNCTION execution_verification_append_only()\n            \",\n            \"DROP TRIGGER IF EXISTS execution_finalized_header_append_only \\\n             ON execution_verified_finalized_header\",\n            \"\n            CREATE TRIGGER execution_finalized_header_append_only\n            BEFORE UPDATE OR DELETE ON execution_verified_finalized_header\n            FOR EACH STATEMENT EXECUTE FUNCTION execution_verification_append_only()\n            \",\n        ] {\n            sqlx::query(statement)\n                .execute(&mut *transaction)\n                .await\n                .map_err(|e| anyhow::anyhow!(\"Failed to activate verification schema: {e}\"))?;\n        }\n        sqlx::query(\n            \"\n            INSERT INTO execution_schema_version (component, version)\n            VALUES ('evm_execution_verification', $1)\n            ON CONFLICT (component) DO UPDATE SET version = EXCLUDED.version\n            WHERE execution_schema_version.version <= EXCLUDED.version\n            \",\n        )\n        .bind(VERIFICATION_SCHEMA_VERSION)\n        .execute(&mut *transaction)\n        .await\n        .map_err(|e| anyhow::anyhow!(\"Failed to activate verification schema: {e}\"))?;\n\n        transaction\n            .commit()\n            .await\n            .map_err(|e| anyhow::anyhow!(\"Failed to commit verification migration: {e}\"))?;","sourceCodeStart":4569,"sourceCodeEnd":4605,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L4569-L4605","documentation":"Thrown when one of the DDL statements that activates the verification schema fails: creating the `execution_verification_append_only()` trigger function or its BEFORE UPDATE OR DELETE triggers on the decision and finalized-header tables, or upserting the schema-version marker row. It wraps the sqlx error from executing each statement in the migration transaction.","triggerScenarios":"Executing `CREATE OR REPLACE FUNCTION ... RETURNS TRIGGER` or `CREATE TRIGGER ...` during `ensure_execution_verification_schema`; failures include the base tables not existing yet, missing ownership/DDL privileges, or the version upsert INSERT failing on a malformed `execution_schema_version` table.","commonSituations":"Connecting as a role with only read/write but no CREATE privileges; an older database where tables were created by a different migration path; a DBA-managed schema where triggers are disallowed; concurrent DDL locks held by another session.","solutions":["Check the wrapped sqlx message for the failing statement and Postgres error code","Grant the database role ownership or DDL (CREATE) privileges on the schema/tables","Ensure the execution verification tables were created before this activation step (run the table-creation migration first)","Check pg_locks for concurrent DDL sessions blocking the trigger creation"],"exampleFix":"// before: role lacking DDL rights\nCREATE USER app WITH SELECT, INSERT, UPDATE, DELETE ON ALL TABLES;\n// after: allow schema activation\nGRANT CREATE ON SCHEMA public TO app;\nGRANT ALL ON ALL TABLES IN SCHEMA public TO app;","handlingStrategy":"try-catch","validationCode":"let ddl_ok: bool = sqlx::query_scalar(\n    \"SELECT has_schema_privilege(current_user, 'public', 'CREATE')\")\n    .fetch_one(&pool).await?;\nif !ddl_ok { return Err(anyhow::anyhow!(\"database role lacks DDL privileges for schema activation\")); }","typeGuard":null,"tryCatchPattern":"match db.ensure_execution_verification_schema().await {\n    Err(e) if e.to_string().contains(\"Failed to activate verification schema\") => {\n        // DDL step failed: check privileges, table existence, blocking locks before retrying\n        return Err(e.context(\"schema activation requires DDL privileges and pre-created tables\"));\n    }\n    other => other,\n}","preventionTips":["Grant CREATE on the schema to the application role","Create base tables in an earlier migration phase before triggers","Avoid DBA-managed trigger restrictions for tables this library owns","Check for concurrent DDL sessions during deployments"],"tags":["postgres","sqlx","ddl","triggers"],"backgroundTag":"database-query-failed","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}