agentsclimarketplace

Database patterns

Skill taipt1504/agent-skills/skills/database-patterns

Database patterns for Java Spring — R2DBC (reactive), JPA/Hibernate (servlet), PostgreSQL, MySQL, connection pooling (HikariCP/r2dbc-pool), Flyway migrations, and query optimization. Use when writing @Entity or R2DBC models, creating Repository interfaces, writing @Query methods, planning Flyway migrations, tuning connection pools, or reviewing SQL performance. Includes scripts/validate-migration.sh for migration file validation.From its SKILL.md

Install
npx -y skills add taipt1504/agent-skills --skill database-patterns

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

2 things to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
  • 3 stars3 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

5.3 KB, as published. Nobody here has run it

Database Patterns

Stack Decision

CriterionJPA / HikariCPR2DBC / R2DBC Pool
RuntimeSpring MVC (blocking)Spring WebFlux (reactive)
RepositoryJpaRepositoryReactiveCrudRepository
Transaction@Transactional@Transactional + TransactionalOperator
PG driverorg.postgresql:postgresqlorg.postgresql:r2dbc-postgresql
MySQL drivercom.mysql.cj.jdbc.Driverio.asyncer:r2dbc-mysql

Engine Differences

AspectPostgreSQLMySQL
PK strategyGENERATED ALWAYS AS IDENTITY / SEQUENCEBIGINT UNSIGNED AUTO_INCREMENT
JPA @GeneratedValueSEQUENCE + @SequenceGeneratorIDENTITY
Stringstext (no storage diff vs varchar)VARCHAR(n) + utf8mb4 required
Timestampstimestamptz (always TZ-aware)DATETIME(3) (store in UTC)
Covering indexINCLUDE (col)List all cols in key (no INCLUDE)
Partial indexWHERE clause on indexNot supported (use composite)
Concurrent indexCREATE INDEX CONCURRENTLYALGORITHM=INPLACE, LOCK=NONE
Transactional DDLYesNo (implicit commit)
Default isolationREAD_COMMITTEDREPEATABLE_READ (gap locks)

Critical Rules (Both Engines)

  1. @SQLRestriction not @Where — Hibernate 6+
  2. FetchType.LAZY always — JOIN FETCH / @EntityGraph at call site
  3. No .block() in reactive — use R2DBC on WebFlux
  4. open-in-view: false — always disable
  5. Parameterized queries only — never concatenate user input
  6. Index all FK columns
  7. Pool size = vCPU * 2 + 1 (SSD); smaller pools outperform oversized
  8. DTO projections for read-only — skip entity lifecycle overhead

Migration Safety (Expand-Contract)

  1. Expand — add nullable column; code writes both old+new
  2. Migrate — backfill in batches (1000 rows), not single UPDATE
  3. Contract — add NOT NULL / drop old column in separate deploy

Always safe: add nullable column, index (CONCURRENTLY/INPLACE), add table. Never in prod: DROP without expand-contract, ALTER to smaller type, TRUNCATE.

Verification Checklist

  • No @Data on entities; use @Getter + @NoArgsConstructor(PROTECTED) + builder
  • @EntityGraph / JOIN FETCH for known N+1 paths
  • DTO projections for read-only queries
  • @Transactional(readOnly = true) on query methods
  • HikariCP leak detection enabled in non-prod
  • Migrations follow V{n}__{description}.sql naming
  • Large table changes use online DDL or batch strategy
  • Migration tested with Testcontainers

References

FileContents
postgresql.mdSchema, indexing (B-tree/GIN/GiST/BRIN/covering/partial), UPSERT, keyset pagination, SKIP LOCKED, RLS, JPA config, R2DBC config, pool sizing, Flyway
mysql.mdSchema, indexing (covering without INCLUDE, invisible, generated columns), utf8mb4, JPA config, R2DBC asyncer driver, pool sizing, Flyway
jpa-hibernate.mdEntity design, N+1 prevention (EntityGraph/JOIN FETCH/DTO projections), HikariCP config, pagination (offset + cursor), batch writes, specifications
r2dbc.mdReactiveCrudRepository, R2dbcEntityTemplate, DatabaseClient, reactive transactions, pool config, Testcontainers testing
migrations.mdFlyway naming, expand-contract, safety rules, large table strategies (PG vs MySQL), Testcontainers validation

Related Skills

  • summer-data — R2DBC converters, audit_log/outbox_events DDL, AuditTableValidator
  • spring-webflux-patterns — JPA (MVC) or R2DBC (WebFlux) stack selection
  • redis-patterns — Cache-aside to reduce DB load
  • testing-workflow — Testcontainers for DB integration tests, @DataR2dbcTest/@DataJpaTest

Keep looking

Skills are one crate of 626,194. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.