srtd-cli
This skill should be used when the user mentions "srtd", "sql templates", "migrations-templates", "live reload sql", "supabase functions", when working with files in supabase/migrations-templates/, when .buildlog.json or srtd.config.json is detected, or when writing Postgres functions/views/triggers for Supabase.
When & Why to Use This Skill
The srtd-cli skill is a specialized tool for iterative SQL development and migration management within the Supabase and PostgreSQL ecosystem. It automates the process of applying SQL templates to local databases with live-reload capabilities, handles complex script dependencies, and ensures idempotency for database objects like functions, views, and triggers, making it essential for developers seeking a robust database CI/CD workflow.
Use Cases
- 1. Rapid Database Prototyping: Use the 'watch' command to instantly apply changes to your local Supabase instance as you edit SQL files, enabling a hot-reloading experience for backend logic.
- 2. Idempotent Migration Authoring: Simplify the creation of Postgres functions and triggers by utilizing built-in patterns that safely drop and recreate objects, preventing 'already exists' errors during development.
- 3. Dependency Management: Organize complex database schemas by defining execution orders with the @depends-on annotation, ensuring that tables and types are created before the functions that reference them.
- 4. Automated Migration Bundling: Generate clean, version-controlled migration files from iterative templates using the 'build' command, ready for deployment to production environments.
- 5. Local State Tracking: Maintain consistency between your local database state and your codebase using .buildlog.json, preventing configuration drift across different development environments.
| name | srtd-cli |
|---|---|
| description | This skill should be used when the user mentions "srtd", "sql templates", "migrations-templates", "live reload sql", "supabase functions", when working with files in supabase/migrations-templates/, when .buildlog.json or srtd.config.json is detected, or when writing Postgres functions/views/triggers for Supabase. |
SRTD - Iterative SQL Template Development
Workflow
Start watch in background immediately:
srtd watch --json
Use run_in_background: true. Monitor with TaskOutput for events: templateApplied (success), templateError (check errorMessage/errorHint).
Templates
Location: supabase/migrations-templates/*.sql. Must be idempotent.
Idempotency patterns:
- Functions/Views:
CREATE OR REPLACE(useDROPonly when changing signature) - Policies:
DROP POLICY IF EXISTSthenCREATE POLICY(not replaceable) - Triggers: Drop BOTH trigger AND function first
Dependencies: -- @depends-on: other.sql at top
WIP: .wip.sql suffix → applies locally, never builds
Commands
srtd apply [--force] [--json] # Apply to local DB (use instead of watch for one-off)
srtd build [--bundle] # Generate migration FILES only (does NOT apply to DB)
srtd clear --reset # Reset state if confused
State
.buildlog.json→ commit (tracks built migrations).buildlog.local.json→ gitignored (local DB state)