Relational database schema from business rules, with indexes and migrations

by fidji ChatGPT English ~695 tokens
Public excerpt Locked
You are a database architect. Extract entities and business rules, settle every cardinality, normalise to 3NF, choose keys, CHECK / UNIQUE / FK actions, amounts in minor units, timestamps with time zone, then derive indexes from the top queries…

About this prompt

Turns a plain-language description of a business into a production-ready relational schema: entities and cardinalities, Mermaid ER diagram, 3NF with justified denormalisation, constraints, money and time-zone pitfalls, indexes derived from your real queries, DDL and a zero-downtime migration plan.

Example output

Provided by the author
STEP 1 — Rules - A time entry belongs to exactly one task and one employee; a task belongs to exactly one project. Question 1: can one time entry be invoiced twice (corrections), or is it locked once invoiced? STEP 2 ```mermaid erDiagram CLIENT ||--o{ PROJECT : owns PROJECT ||--o{ TASK : contains TASK ||--o{ TIME_ENTRY : logs INVOICE ||--o{ TIME_ENTRY : bills ``` STEP 4 — DDL (excerpt, PostgreSQL) ```sql CREATE TABLE time_entry ( id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY, agency_id bigint NOT NULL REFERENCES agency(id), task_id bigint NOT NULL REFERENCES task(id) ON DELETE RESTRICT, employee_id bigint NOT NULL REFERENCES employee(id), work_date date NOT NULL, minutes integer NOT NULL CHECK (minutes BETWEEN 1 AND 1440), rate_cents integer NOT NULL, -- frozen at entry time invoice_id bigint REFERENCES invoice(id) ); ``` STEP 5 — "unbilled hours per client" → CREATE INDEX ON time_entry (agency_id, task_id) WHERE invoice_id IS NULL; (partial index, stays small)…

Details

Model
ChatGPT
Prompt language
English
Who it's for
Developers and founders designing the database of a new application or a new feature
Length
~695 tokens (estimate)
Delivered as
Prompt text, shown online after purchase

Reviews

Buyers only

No reviews yet. Only buyers of this prompt can leave one.

Report this prompt