database/designing-schemas/SKILL.md
Design normalized PostgreSQL schemas from tech specs, with proper constraints, naming conventions, and standard columns.
npx skillsauth add 7a336e6e/skills Designing SchemasInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
4 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Translate data entities from a tech spec into well-structured PostgreSQL tables that follow normalization rules, enforce data integrity through constraints, and use consistent naming conventions.
Read the tech spec and extract all data entities, their attributes, and the relationships between them. Map each entity to a table and each relationship to a foreign key or join table.
Normalize to Third Normal Form (3NF) by default. Every non-key column must depend on the key, the whole key, and nothing but the key. Denormalization is acceptable only with explicit justification (e.g., read-heavy access patterns with measured performance impact).
Prefer UUID for distributed systems or BIGSERIAL for single-database deployments. Every table must have a column named id as its primary key.
Every table must include these columns:
id — primary keycreated_at TIMESTAMPTZ NOT NULL DEFAULT now()updated_at TIMESTAMPTZ NOT NULL DEFAULT now()Add foreign keys for all relationships. Add NOT NULL to every column unless there is a clear reason for allowing nulls. Add CHECK constraints for value boundaries. Create indexes on all foreign key columns.
CREATE TABLE users (
id BIGSERIAL PRIMARY KEY,
email VARCHAR(255) NOT NULL,
password_hash VARCHAR(128) NOT NULL,
display_name VARCHAR(100) NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
CONSTRAINT uq_users_email UNIQUE (email),
CONSTRAINT ck_users_email_format CHECK (email ~* '^.+@.+\..+$')
);
CREATE INDEX ix_users_email ON users (email);
CREATE TABLE task_assignments (
id BIGSERIAL PRIMARY KEY,
user_id BIGINT NOT NULL REFERENCES users (id) ON DELETE CASCADE,
task_id BIGINT NOT NULL REFERENCES tasks (id) ON DELETE CASCADE,
assigned_at TIMESTAMPTZ NOT NULL DEFAULT now(),
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
CONSTRAINT uq_task_assignments_user_task UNIQUE (user_id, task_id)
);
CREATE INDEX ix_task_assignments_user_id ON task_assignments (user_id);
CREATE INDEX ix_task_assignments_task_id ON task_assignments (task_id);
Refer to the naming conventions reference for all naming decisions. Use snake_case throughout. Table names are plural, column names are singular.
Produce a SQL file containing all CREATE TABLE, CREATE INDEX, and ALTER TABLE statements. Group related tables together. Include comments explaining non-obvious design decisions. End with a summary listing all tables and their relationships.
development
Implement features using the Red-Green-Refactor cycle to ensure testability and correctness from the start.
data-ai
Manage the `tasks.md` ledger with strict locking and collision avoidance protocols to allow multiple agents to work in parallel safely.
development
The git-workflow skill defines branching conventions, commit message formats, and pull request standards that all agents must follow for consistent version control.
development
The environment-config skill standardizes how agents manage environment variables, secrets, and application configuration across local development and deployed environments.