Relational Database (PostgreSQL)
Relevant source files
The following files were used as context for generating this wiki page:
The PostgreSQL relational database manages the primary application state, including project configurations, user permissions, and resource metadata. It provides a transactional foundation for the Speakeasy platform, ensuring data consistency across services like the API server and background workers. Sources: CLAUDE.md, REVIEW.md:144-145
Schema Design and Requirements
Speakeasy enforces strict structural requirements for all PostgreSQL tables to ensure uniform data management and multi-tenancy. Sources: REVIEW.md:144-146
Mandatory Columns and Constraints
Every table in the relational database must include specific columns for tracking and scoping:
| Column | Type | Constraints | Description |
|---|---|---|---|
project_id | uuid | NOT NULL, FK to projects | Ensures data is isolated to a specific project. |
created_at | timestamptz | DEFAULT clock_timestamp() | Records the timestamp of row creation. |
updated_at | timestamptz | DEFAULT clock_timestamp() | Records the timestamp of the last update. |
deleted_at | timestamptz | NULLABLE | Supports soft deletion of records. |
Sources: REVIEW.md:147-152, server/migrations/20260715170908_skills-skill-versions.sql:3-10
Naming Conventions and Deletion
- Identifiers: Use
snake_casefor all table and column names. Sources: REVIEW.md:154 - Pluralization: Table names use plural nouns (e.g.,
skills,mcp_frontends). Sources: REVIEW.md:154, server/migrations/20260715170908_skills-skill-versions.sql:2 - Soft Deletes: Tables implement soft deletes using a
deleted_atcolumn often paired with a generateddeletedboolean column. Sources: REVIEW.md:149, server/migrations/20260421144856_mcp_frontends_and_slugs.sql:14 - Foreign Keys: All foreign key constraints must specify
ON DELETE SET NULLorON DELETE CASCADE. Sources: REVIEW.md:153, server/migrations/20260715170908_skills-skill-versions.sql:12
Data Modeling Examples
The following diagram illustrates the relationship between projects, skills, and Model Context Protocol (MCP) components as defined in the schema migrations.
The diagram shows how various entities are scoped to a parent project and how versioned content is maintained. Sources: server/migrations/20260715170908_skills-skill-versions.sql, server/migrations/20260421144856_mcp_frontends_and_slugs.sql
Skills and Versions
The skills table stores metadata for assistant skills, while skill_versions contains the actual logic or content, identified by SHA256 hashes for integrity. Sources: server/migrations/20260715170908_skills-skill-versions.sql:2-40
MCP Frontends
The mcp_frontends table configures how Model Context Protocol servers are exposed, linking them to specific environments and OAuth configurations. Sources: server/migrations/20260421144856_mcp_frontends_and_slugs.sql:2-25
Database Operations and Workflow
Database management relies on code generation and strict migration protocols. Sources: REVIEW.md:159-173
Query Management with SQLc
The project uses SQLc to generate type-safe Go code from raw SQL queries.
- Queries are stored in
**/queries.sqlfiles. Sources: CLAUDE.md:83 - Every query MUST be scoped to a
project_id. Sources: REVIEW.md:168 - Inline SQL is forbidden in application code. Sources: REVIEW.md:170
Migration Workflow
Migrations are managed using Atlas and must follow an "expand-contract" pattern to ensure backwards compatibility. Sources: REVIEW.md:159-165
The flow ensures that schema changes are reviewed independently of application logic. Sources: CLAUDE.md:76-78, REVIEW.md:171-172
Procedures for Development
- Setup: The
./zeroscript handles initial database setup and applies pending migrations. Sources: CONTRIBUTING.md:3-6 - Seeding: Run
mise seedto populate the database with sample data including projects, agent sessions, and telemetry. Sources: CONTRIBUTING.md:46-55 - Resetting: The seed command is idempotent and resets the database by wiping and re-inserting fresh data. Sources: CONTRIBUTING.md:58-60
Transactional Integrity and Auditing
Transactional atomicity is required for mutations affecting scoped resources.
- Audit Logging: Every mutation on a project or organization-scoped resource must produce an audit entry. Sources: REVIEW.md:131
- Atomicity: Audit writes must occur within the same database transaction (
dbtx) as the primary mutation. Sources: REVIEW.md:133-134 - Dependency Injection: Services should inject
*pgxpool.Pooland initialize queries within handler methods usingrepo.New(s.db). Sources: REVIEW.md:65-67
PostgreSQL serves as the source of truth for Speakeasy, enforcing multi-tenancy through project_id scoping and maintaining a versioned history of critical assets like Skills. Sources: REVIEW.md:144, server/migrations/20260715170908_skills-skill-versions.sql