howto-develop-with-postgres
Use when writing database access code, creating schemas, or managing transactions with PostgreSQL - enforces transaction safety with TX_ naming, read-write separation, type safety for UUIDs/JSONB, and snake_case conventions to prevent data corruption and type errors
What this skill does
# PostgreSQL Development Patterns ## Overview Enforce transaction safety, type safety, and naming conventions to prevent data corruption and runtime errors. **Core principles:** - Transactions prevent partial updates (data corruption) - Type safety catches errors at compile time - Naming conventions ensure consistency - Read-write separation prevents accidental mutations ## Transaction Management ### Transaction vs Query Execution **Methods that START transactions:** - Must NOT accept a specific connection/executor parameter, takes things like a database pool or client - Create the transaction and then pass that transaction object to an underlying method that performs the actual query - Usually exported or public **Methods that PARTICIPATE in transactions:** - MUST accept a generic connection/executor parameter - Execute queries using the provided executor - Usually unexported or private **What DOES NOT count as "starting a transaction":** - Single INSERT/UPDATE/DELETE operations - Atomic operations like `onConflictDoUpdate` - SELECT queries ## Type Safety ### Primary Keys **Default: ULID stored as UUID** - When in doubt, use ULID: "Most things can leak in some way" - Prevents ID enumeration attacks - Time-sortable for indexing efficiency **Exceptions (context-dependent):** - Pure join tables (composite PK from both FKs) - Small lookup tables (serial/identity acceptable) - Internal-only tables with no user visibility (serial/identity acceptable) **Rule:** If unsure whether data will be user-visible, use ULID. ### Financial Data **Use exact decimal types (numeric/decimal) for monetary values:** - Never use float/double for money (causes rounding errors) - Use numeric/decimal with appropriate precision and scale - Example: `numeric(19, 4)` for general financial data **Why:** Floating-point types accumulate rounding errors. Exact decimal types prevent financial discrepancies. ### JSONB Columns **ALWAYS type JSONB columns in your ORM/schema:** - Use typed schema when structure is known - Use `Record<string, unknown>` if truly schemaless - Never leave JSONB untyped **Why:** Prevents runtime errors from accessing undefined properties or wrong types. ### Read-Write Separation **Maintain separate client types at compile time:** - Read-write client: Full mutation capabilities - Read-only client: Mutation methods removed at type level - Default to read-only for query methods - Use read-write only when mutations needed **Why:** Prevents accidental writes to replica, enforces deliberate mutation choices. ## Naming Conventions ### Database Identifiers **All database objects use snake_case:** - Tables: `user_preferences`, `order_items` - Columns: `created_at`, `user_id`, `is_active` - Indexes: `idx_tablename_columns` (e.g., `idx_users_email`) - Foreign keys: `fk_tablename_reftable` (e.g., `fk_orders_users`) **Application code:** Map to idiomatic case (camelCase in TypeScript, etc.) ### Schema Patterns **Standard mixins:** - `created_at`, `updated_at` timestamps on all tables - `deleted_at` for soft deletion when needed - `tenant_id` for multi-tenant tables (project-dependent) **Proactive indexing:** - All foreign key columns - Columns used in WHERE clauses - Columns used in JOIN conditions - Columns used in ORDER BY ## Concurrency **Default isolation (Read Committed) for most operations.** **Use stricter isolation when:** - Financial operations: Serializable isolation - Inventory/count operations: Serializable isolation - Critical sections: Pessimistic locking (`SELECT ... FOR UPDATE`) ## Migrations **Always use generate + migrate workflow:** 1. Generate migration file 2. Review migration SQL 3. Apply migration to database **Never use auto-push workflow in production.** ## Common Mistakes | Mistake | Reality | Fix | | ------------------------------------------------- | --------------------------------------------------------------------------------------- | ------------------------------------------------------------- | | "This is one operation, doesn't need transaction" | Multi-step operations without transactions cause partial updates and data corruption | Wrap in transaction with TX\_ prefix | | "Single atomic operation needs TX\_ prefix" | TX\_ is for explicit transaction blocks, not atomic operations | No TX\_ for single INSERT/UPDATE/DELETE | | "UUID is just a string" | Type confusion causes runtime errors (wrong ID formats, failed lookups) | Use strict UUID type in language | | "I'll type JSONB later when schema stabilizes" | Untyped JSONB leads to undefined property access and type errors | Type immediately with known fields or Record<string, unknown> | | "Read client vs write client doesn't matter" | Using wrong client bypasses separation, allows accidental mutations | Use read-only client by default, switch deliberately | | "I'll add indexes when we see performance issues" | Missing indexes on foreign keys cause slow queries from day one | Add indexes proactively for FKs and common filters | | "This table won't be user-visible, use serial" | Requirements change, IDs leak in logs/URLs/errors | Use ULID by default unless certain it's internal-only | | "Float/double is fine for money, close enough" | Rounding errors accumulate, causing financial discrepancies (0.01 differences multiply) | Use numeric/decimal types for exact arithmetic | ## Red Flags - STOP and Refactor **Transaction management:** - Method calls `.transaction()` but no `TX_` prefix - Method has `TX_` prefix but accepts executor parameter - Multi-step operation without transaction wrapper **Type safety:** - JSONB column without type annotation - UUID/ULID stored as plain string type - No separation between read and write clients - Float/double types for monetary values **Schema:** - Missing indexes on foreign keys - No `created_at`/`updated_at` timestamps - camelCase or PascalCase in database identifiers **All of these mean: Stop and fix immediately.**
Related in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only — no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.