spring-boot-database-schema

A set of rules for designing a PostgreSQL database schema, which describes tables, columns, relationships, and data restrictions. It covers names, data types, keys, indexes, and SQL file organization.

In plain words
What is it for?
Use it when creating or changing tables, primary keys, foreign keys, indexes, constraints, or database migration files.
Why use it?
It makes stored data and relationships predictable across modules. Clear constraints and names help catch invalid data and make database changes easier to understand.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/lsampaioweb/ai-instructions/spring-boot-database-schema
Clone the repo
git clone --depth 1 https://github.com/lsampaioweb/ai-instructions

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 1,201 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.01201
Opus 5 $0.00000 $0.00600
Sonnet 5 $0.00000 $0.00240
Haiku 4.5 $0.00000 $0.00120

Measured 2d ago against content hash c65483d2bf23, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

spring-boot-database-schema scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/spring-boot-database-schema.mdc · 67 lines

How it starts

The opening of the file, as written. The whole thing — 67 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Spring Boot Database-Schema Engine

Naming Conventions

  • Use singular snake_case for table names; avoid generic tokens such as tbl, data, or obj.
  • Name primary key columns as <table_name>_id (never standalone id).
  • Name foreign key columns as <referenced_table_name>_id.
  • Name non-key columns with domain-qualified semantics (never standalone name, value, type, status, or date).
  • Name primary key constraints as pk_<table_name>.
  • Name foreign key constraints as fk_<source_table>_<target_table>.
  • Name unique constraints as uq_<table_name>_<column_name>.
  • Name check constraints as ck_<table_name>_<rule_name>.
  • Name non-unique indexes as ix_<table_name>_<column_name>.
  • Name unique indexes as ux_<table_name>_<column_name>.
  • For composite constraints or indexes, append column tokens in declaration order separated by underscores.

Rules

  • Use PostgreSQL as the default relational system-of-record for CRUD modules unless request constraints require a different store.
  • Default primary keys and row identifiers to INTEGER.
  • Use SMALLINT only for clearly bounded low-cardinality domains expected to stay below 32,767 rows for the full lifecycle.
  • Use BIGINT only when stated scale expectations or lifetime cardinality can exceed INTEGER limits.
  • Declare integer primary keys using GENERATED ALWAYS AS IDENTITY.
  • Use TEXT for variable-length string columns with no business-rule length limit.
  • Use VARCHAR(n) only when the domain enforces a maximum character length.
  • Use NUMERIC(precision, scale) for monetary or decimal columns.
  • Use DATE for calendar-day business fields.
  • Use TIMESTAMPTZ (timestamp with time zone) for event-time and audit fields.
  • Model application-owned closed-set domains through lookup/reference tables plus foreign-key columns in business tables.
  • Keep a stable domain code column in each lookup/reference table for idempotent seed data and application mapping.
  • Mark required columns with NOT NULL.
  • Leave optional columns nullable by design.
  • Keep delete mode, retention window, historical-table strategy, and archival behavior as explicit design decisions for every new business table.
  • When the user prompt does not specify lifecycle, retention, archival, or delete semantics for a new table or column, treat the schema design as unresolved and ask the user before generating DDL.
  • Add created_at TIMESTAMPTZ NOT NULL DEFAULT NOW() and updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() to every business table.
  • Omit created_at and updated_at audit columns only for pure lookup or reference tables with no lifecycle.
  • Declare columns in this order within every table: primary key, required foreign keys, business columns, optional foreign keys, audit columns (created_at, updated_at) last.
  • Keep SQL DDL idempotent.
  • Add succinct SQL comments before each business table, lookup/reference table, idempotent seed-data block, and non-obvious index.
  • Place SQL DDL schema files under src/main/resources/sql/db/.
  • Place SQL query files (XML property sources) directly under src/main/resources/sql/.
  • Keep seed-data statements idempotent and stable across reruns, including lookup/reference seeds.
  • Keep primary, unique, and foreign key constraints explicit in SQL DDL.
  • Declare unique and check constraints as named CONSTRAINT clauses (e.g., CONSTRAINT uq_users_email UNIQUE (email)) rather than inline column keywords.
  • Declare both ON DELETE and ON UPDATE actions on every FK constraint.
  • Use ON DELETE RESTRICT and ON UPDATE CASCADE as the default FK action pair.
  • Use hard delete (physical DELETE) only when the user explicitly confirms there is no soft-delete, archival, or historical-retention requirement.
  • Implement soft delete with a deleted_at TIMESTAMPTZ column only when explicitly requested; document the retention and cleanup strategy alongside the schema change.
  • Use ON DELETE CASCADE only for child records with no independent existence.
  • Use ON DELETE SET NULL only for optional associations.
  • Add a CREATE INDEX IF NOT EXISTS for every foreign key column in SQL DDL.
  • Treat every non-foreign-key index as an explicit query-shape decision; when the user prompt does not justify that index, ask before generating it.
  • Declare the FK column as nullable for every optional association that uses ON DELETE SET NULL.
  • When a new relation introduces business-data deletion, retention, archival, or historical-movement consequences and the user prompt is silent, treat the delete behavior as unresolved and ask the user before finalizing the constraint action.
  • When adding a FK constraint to a table with existing data, use NOT VALID to add the constraint without scanning existing rows, then run VALIDATE CONSTRAINT in a separate transaction.
  • For hierarchical or tree-structured data, declare a self-referencing FK on the parent column (e.g., parent_id REFERENCES same_table(id)) with ON DELETE CASCADE when child nodes have no independent existence.
  • Keep domain invariants enforced by explicit SQL constraints and relation actions.

Read the full file on GitHub · 67 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 67 lines · 0 tokens per session scan A c65483d2bf23

Subscribe to this mod's changes

spring-boot-database-schema is a cursor rule published in the GitHub repository lsampaioweb/ai-instructions (1 stars, last pushed 10d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,201 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.