{"record":{"id":"e8d35268b3b94e6f","repo":"nautechsystems/nautilus_trader","slug":"failed-to-call-create-token-partition-for-chain","errorCode":null,"errorMessage":"Failed to call create_token_partition for chain {}: {e}","messagePattern":"Failed to call create_token_partition for chain (.+?): (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":399,"sourceCode":"                )\n            })?;\n\n        Ok(result.0)\n    }\n\n    /// Creates a table partition for the token table specific to the given chain\n    /// by calling the existing PostgreSQL function `create_token_partition`.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the database operation fails.\n    pub async fn create_token_partition(&self, chain: &Chain) -> anyhow::Result<String> {\n        let result: (String,) = sqlx::query_as(\"SELECT create_token_partition($1)\")\n            .bind(chain.chain_id as i32)\n            .fetch_one(&self.pool)\n            .await\n            .map_err(|e| {\n                anyhow::anyhow!(\n                    \"Failed to call create_token_partition for chain {}: {e}\",\n                    chain.chain_id\n                )\n            })?;\n\n        Ok(result.0)\n    }\n\n    /// Returns the highest block number that maintains data continuity in the database.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the database query fails.\n    pub async fn get_block_consistency_status(\n        &self,\n        chain: &Chain,\n    ) -> anyhow::Result<CachedBlocksConsistencyStatus> {\n        log::debug!(\"Fetching block consistency status\");","sourceCodeStart":381,"sourceCodeEnd":417,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L381-L417","documentation":"create_token_partition calls the PostgreSQL function create_token_partition($1) for a chain; failures of the sqlx query_as call are wrapped in this anyhow error with the chain_id embedded. Like the block variant, the cause may be a missing function, permission, or a server-side partitioning error.","triggerScenarios":"Calling CacheDatabase::create_token_partition when the token partition function is absent (migrations pending), the role lacks EXECUTE, or the server-side function errors for the given chain_id.","commonSituations":"Fresh environment where schema migrations weren't applied; version mismatch between adapter and database schema; restricted DB role in production.","solutions":["Read the wrapped {e}: 'does not exist' points to missing migrations","Run database migrations to install create_token_partition","Grant EXECUTE on the function to the app DB user","Confirm the parent token table exists before creating partitions"],"exampleFix":"null","handlingStrategy":"validation","validationCode":"// check function and parent token table exist before creating partitions\nlet ok: (bool,) = sqlx::query_as(\n    \"SELECT EXISTS (SELECT 1 FROM pg_proc WHERE proname='create_token_partition') \\\n     AND EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name='token')\"\n).fetch_one(&pool).await?;\nif !ok.0 { return Err(anyhow::anyhow!(\"token partition prerequisites missing; run migrations\")); }","typeGuard":null,"tryCatchPattern":"db.create_token_partition(&chain).await.map_err(|e| {\n    if e.to_string().contains(\"does not exist\") {\n        anyhow::anyhow!(\"missing create_token_partition; migrations not applied: {e:#}\")\n    } else {\n        anyhow::anyhow!(\"token partition failed for chain {}: {e:#}\", chain.chain_id)\n    }\n})?;","preventionTips":["Keep database schema version aligned with the adapter version in deployment","Grant EXECUTE on create_token_partition to the application role","Create partitions for all configured chains during a single startup phase","Check migrations were applied to the exact database in DATABASE_URL, not a peer environment"],"tags":["database","postgres","partitioning","sqlx"],"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-14T05:17:10.506Z"}