Cursor prompt to set up a Postgres database schema
Run this in Cursor's agent and you get versioned Postgres migrations with identity keys, timestamptz audit columns, deliberate foreign key delete behavior, and indexes matched to real query patterns. The rollback rehearsal at the end matters most: the agent executes the down migration once, so you learn it works before production does.
Last updated
Design a Postgres schema for {{resource}} in this project and write it as versioned migrations using the migration tool already present, or add a lightweight one and note why you chose it. Use bigint identity primary keys, timestamptz created_at and updated_at with a trigger or ORM hook keeping updated_at current, NOT NULL plus CHECK constraints where the domain demands them, and foreign keys with an explicit ON DELETE choice per relationship rather than a blanket CASCADE. Add unique indexes for natural keys and partial indexes for common filtered queries, for example WHERE deleted_at IS NULL if soft deletes are used. Generate both up and down migrations, apply them to a local database, run the rollback once to prove the down path works, then print the final schema for each table.Customize it
Runs in your browser. Nothing you type here is sent anywhere.
Design a Postgres schema for users in this project and write it as versioned migrations using the migration tool already present, or add a lightweight one and note why you chose it. Use bigint identity primary keys, timestamptz created_at and updated_at with a trigger or ORM hook keeping updated_at current, NOT NULL plus CHECK constraints where the domain demands them, and foreign keys with an explicit ON DELETE choice per relationship rather than a blanket CASCADE. Add unique indexes for natural keys and partial indexes for common filtered queries, for example WHERE deleted_at IS NULL if soft deletes are used. Generate both up and down migrations, apply them to a local database, run the rollback once to prove the down path works, then print the final schema for each table.
Same task in other tools
Questions about this prompt
My project already has migrations. Will Cursor append to them or start over?
With the existing tool visible in the repo, the agent generates new migration files in sequence, and the prompt's instruction to use what is present keeps it from installing a second tool. Attach the migrations folder with @ so it reads your numbering and naming style first.
Should I let it choose ON DELETE behavior per foreign key?
The prompt forces an explicit choice per relationship, but review each one. CASCADE on something like organizations can wipe half your data from one deleted row; RESTRICT plus an application-level cleanup is usually the safer default for aggregate roots.
How do I adapt this for soft deletes across every table?
Add a sentence requiring a nullable deleted_at timestamptz on each table, partial unique indexes filtered on deleted_at IS NULL, and default query scopes excluding deleted rows. Without the partial index detail, agents create plain unique indexes that break when you soft delete and recreate a row.