/openlogos:db-designerfrom openlogos
Designs database schema from API specifications, generating SQL DDL in the appropriate dialect. Reads tech_stack.database from project config to determine dialect.
Ships in openlogos. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Derive database table structures from API specifications and generate SQL DDL in the appropriate dialect. The database type is determined during Phase 3 Step 0 technology selection, ensuring that field types, constraints, indexes, and security policies are fully aligned with API endpoints.
tech_stack.database from logos-project.yaml to determine the database typelogos/resources/api/ contains API YAML specifications (output from api-designer)tech_stack.database in logos-project.yaml is filled inIf the API directory is empty, prompt the user to complete the API design (api-designer) in Phase 3 Step 2 first. If tech_stack.database is not filled in, prompt the user to complete Phase 3 Step 0 (architecture-designer) first.
Read the tech_stack field from logos/logos-project.yaml to determine the database type and dialect:
Extract all data entities that need to be persisted from the API YAML:
requestBody and responses across all endpoints to identify core data objectsusers, projects)loginRequest)Output an entity checklist for user confirmation:
Identified N data entities requiring persistence from API specifications:
| # | Entity | Source Endpoint | Core Fields |
|---|--------|----------------|-------------|
| 1 | users | auth.yaml → register, login | email, password, status |
| 2 | projects | projects.yaml → create, list, get | name, description, owner_id |
| 3 | subscriptions | billing.yaml → subscribe | plan, status, expires_at |
Design complete table structures for each entity, following the current database dialect:
Every table must include:
created_at, updated_atdeleted_at (as needed)NOT NULL, UNIQUE, CHECK, DEFAULTType mapping principles:
string + format: email → TEXT NOT NULL (with CHECK constraint or application-level validation)string + format: uuid → UUID (PostgreSQL) / CHAR(36) (MySQL)integer → INTEGER / BIGINTboolean → BOOLEAN (PostgreSQL) / TINYINT(1) (MySQL)string + enum → TEXT + CHECK constraint (listing enum values)INTEGER (store in cents), DECIMAL/FLOAT is prohibitedExample (PostgreSQL):
-- Users table (source: auth.yaml → register, login)
CREATE TABLE users (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
email TEXT NOT NULL UNIQUE,
password TEXT NOT NULL,
status TEXT NOT NULL DEFAULT 'pending'
CHECK (status IN ('pending', 'active', 'disabled')),
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
Example (SQLite — using @comment structured annotations):
-- Users table (source: auth.yaml → register, login)
CREATE TABLE users (
-- @comment User unique identifier, UUID v4 string
id TEXT PRIMARY KEY NOT NULL,
-- @comment User email, normalized to lowercase
email TEXT NOT NULL UNIQUE,
-- @comment Argon2id password hash, stores hash only
password_hash TEXT NOT NULL,
-- @comment Creation time, ISO 8601 format
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),
-- @comment Last update time
updated_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))
);
-- @table-comment users Users table storing core registered user information
SQLite Comment Convention: SQLite does not support
COMMENT ONsyntax. You MUST use-- @commentpreceding annotations (for columns) and-- @table-comment <table> <description>trailing annotations (for tables). Seelogos/spec/sql-comment-convention.mdfor details.
Design foreign keys based on entity relationships in the API:
/api/projects/:projectId/members → project_members table linking projects and users)ON DELETE CASCADE: child records are deleted when the parent record is deleted (e.g., user deleted → projects deleted)ON DELETE SET NULL: child records are retained but the foreign key is set to null when the parent is deletedON DELETE RESTRICT: prevent deletion of the parent record if child records existDesign corresponding security mechanisms based on the database type:
PostgreSQL — Row-Level Security (RLS):
ALTER TABLE projects ENABLE ROW LEVEL SECURITY;
CREATE POLICY projects_owner_policy ON projects
USING (owner_id = auth.uid());
MySQL — Application-Level Permissions:
Design indexes for common query patterns, with a rationale for each index:
-- User lookup by email (login scenario, source: S02)
CREATE UNIQUE INDEX idx_users_email ON users(email);
-- Project lookup by owner (project list, source: S04 Step 1)
CREATE INDEX idx_projects_owner ON projects(owner_id);
Index design principles:
Organize the DDL file in the following order:
COMMENT ON TABLE / COMMENT ON COLUMNCOMMENT-- @comment (columns) + -- @table-comment (tables), see SQLite comment rules belowAdd a comment above each DDL block noting the source API endpoint.
SQLite Comment Rules (MUST Follow):
When tech_stack.database is SQLite, you MUST use the following structured comment format:
-- @comment <description> on the line immediately above the column definition
-- @comment and the column (blank lines break the association)-- @comment lines are concatenated automatically-- @table-comment <table_name> <description> on the line immediately after CREATE TABLE ... ();FOREIGN KEY, standalone CHECK, UNIQUE) do not need -- @commenttech_stack.database)logos/resources/database/schema.sql (simple projects); or split by domain: auth.sql, billing.sql (complex projects)COMMENT ON TABLE; MySQL: COMMENT = '...'; SQLite: -- @table-comment)COMMENT ON COLUMN; MySQL: COMMENT '...' after field definition; SQLite: -- @comment)| Feature | PostgreSQL | MySQL | SQLite |
|---|---|---|---|
| UUID Primary Key | UUID DEFAULT gen_random_uuid() | CHAR(36) DEFAULT (UUID()) or BINARY(16) | TEXT PRIMARY KEY NOT NULL (app-generated UUID) |
| Timestamp Type | TIMESTAMPTZ | DATETIME / TIMESTAMP (mind timezone handling) | TEXT (ISO 8601 string) |
| JSON Support | JSONB (indexable) | JSON (limited functionality) | TEXT (app-layer JSON serialization) |
| Row-Level Security | RLS (ENABLE ROW LEVEL SECURITY) | Not supported; application layer | Not supported; application layer |
| Table Comment | COMMENT ON TABLE t IS '...' | CREATE TABLE t (...) COMMENT = '...' | -- @table-comment t description |
| Column Comment | COMMENT ON COLUMN t.c IS '...' | col_name TYPE COMMENT '...' | -- @comment description (preceding line) |
deleted_at timestamp field over physical deletioncreated_at and updated_atuserId → DB uses user_id; as long as the mapping rule is clear), reducing unnecessary transformations in the code layerid UUID DEFAULT gen_random_uuid() PRIMARY KEYTIMESTAMPTZALTER TABLE ... ENABLE ROW LEVEL SECURITY;id CHAR(36) DEFAULT (UUID()) PRIMARY KEY or auto-increment BIGINTTIMESTAMP (automatic timezone conversion) or DATETIME (stored as-is)CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci when creating tablesENGINE=InnoDBTEXT PRIMARY KEY NOT NULL (app-generated UUID v4) or INTEGER PRIMARY KEY AUTOINCREMENTTEXT with ISO 8601 strings, default DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))PRAGMA foreign_keys = ON; at connection time-- @comment / -- @table-comment structured annotations (see logos/spec/sql-comment-convention.md)updated_at must be refreshed at the application layer; do not rely on ON UPDATE triggersThe following prompts can be copied directly for use with AI:
Help me design the databaseDerive database DDL from the API specificationsHelp me design the database tables involved in S01Help me add indexes and RLS policies to the existing table structuresWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
SQL, PostgreSQL, MySQL, SQLite
database-design, sql-ddl, schema-generation, api-to-database
npx claudepluginhub miniidealab/openlogos --plugin openlogos16 skills in this plugin
/api-designerDesign OpenAPI specifications derived from scenario sequence diagrams. Use when scenarios exist in 2-scenario-implementation/ but logos/resources/api/ is empty. All description and summary values in YAML must be double-quoted./architecture-designerDesign technical architecture and select technology stack. Use when product design exists in logos/resources/prd/2-product-design/ but logos/resources/prd/3-technical-plan/1-architecture/ is empty./change-writerWrite change proposals with impact analysis following OpenLogos delta workflow. Use when the project lifecycle is active and source code or methodology documents need modification./code-implementorGenerate business code and test code based on the full specification chain (sequence diagrams, API YAML, DB DDL, test case specs). Use when test cases exist in logos/resources/test/ but logos/resources/implementation/ is empty./code-reviewerReview code for OpenLogos methodology compliance, including YAML validity checks. Use when reviewing code changes, checking pull requests, or performing code quality analysis./deployment-designerDesign the deployment plan (topology, environments, release commands, migrations, rollback, post-deploy smoke) and the environment registry deploy configuration for openlogos deploy. Use when API/DB design is complete but logos/resources/prd/3-technical-plan/3-deployment/ is empty, or when a change affects deployment.Other plugins' skills for the same job