Overview
Theprompts table stores the metadata and current state for each prompt. It works together with prompt_versions in a two-table versioning pattern where prompts holds the HEAD pointer and prompt_versions stores immutable history.
Schema
Primary key. Auto-generated using
gen_random_uuid().Owner of the prompt. References
profiles(id) with ON DELETE CASCADE.Human-readable prompt title. Indexed for full-text search with weight ‘A’ (highest priority).
Optional prompt description. Indexed for full-text search with weight ‘B’.
Soft-delete timestamp. When set, the prompt is considered archived. Used for lifecycle management without hard deletion.
Public sharing flag. When
true, the prompt is readable by anonymous users via /p/[promptId] routes.Full-text search index combining title (weight A), description (weight B), and latest content (weight C). Auto-maintained by triggers.
Creation timestamp. Defaults to
timezone('utc', now()).Last modification timestamp. Auto-updated by
handle_updated_at() trigger on UPDATE.Indexes
- idx_prompts_user_id: Fast lookup of all prompts for a user
- idx_prompts_user_archived_at: Efficient filtering of active vs archived prompts
- idx_prompts_search_tokens: GIN index for full-text search queries
- idx_prompts_is_public: Partial index for public prompt discovery
Row Level Security
Relationships
- One-to-Many with
prompt_versions: Each prompt can have multiple versions - Many-to-Many with
collectionsviacollection_prompts - One-to-Many with
prompt_snapshots(viaprompt_versions) - Many-to-One with
profiles: Each prompt belongs to one user
Two-Table Versioning Pattern
PromptRepo uses a two-table pattern to separate HEAD state from version history:promptsholds mutable metadata (title, description, archived_at, is_public)prompt_versionsstores immutable content snapshots
get_latest_prompt_content() function retrieves the highest version_number for a given prompt:
Triggers
Updated At
updated_at = now() on every UPDATE.
Search Index Maintenance
search_tokens whenever title or description changes. Also triggered when new prompt_versions are inserted (see supabase/migrations/20260208000002_search_index.sql:62).
TypeScript Types
Migration Files
- 20260208000001_prompt_schema.sql: Initial table creation
- 20260208000002_search_index.sql: Full-text search support
- 20260226000006_prompt_lifecycle_archive.sql:
archived_atcolumn - 20260227000007_prompt_public_sharing.sql:
is_publicflag and policy