Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Database schema design, migrations, query optimization with SQL, Exposed ORM, Flyway. Use for database, migration, schema, sql, flyway tags. Provides migration patterns, validation commands, rollback strategies.
.claude/skills/microck-database-implementation/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-06 | ✗→✓ | ▲ Improved | 120% | 0% |
| case-12 | ✗→✓ | ▲ Improved | 46% | 0% |
| case-13 | ✗→✓ | ▲ Improved | 54% | 0% |
| case-18 | ✗→✓ | ▲ Improved | 254% | 0% |
| case-08 | ✓→✗ | ▼ Worse | 140% | 0% |
Domain-specific guidance for database schema design, migrations, and data modeling.
Load this Skill when task has tags:
database, migration, schema, sql, flywayexposed, orm, query, index, constraintbash# Gradle + Flyway ./gradlew flywayMigrate # Test migration on clean database ./gradlew flywayClean flywayMigrate # Check migration status ./gradlew flywayInfo # Validate migrations ./gradlew flywayValidate
bash# Migration tests ./gradlew test --tests "*migration*" # Database integration tests ./gradlew test --tests "*Repository*" # All tests ./gradlew test
✅ Migration runs without errors on clean database ✅ Schema matches design specifications ✅ Indexes created correctly ✅ Constraints validate as expected ✅ Rollback works (if applicable) ✅ Tests pass with new schema
sql-- V001__create_users_table.sql CREATE TABLE users ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), email VARCHAR(255) NOT NULL UNIQUE, password_hash VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ); -- Indexes CREATE INDEX idx_users_email ON users(email); CREATE INDEX idx_users_created_at ON users(created_at);
sql-- V002__add_users_phone.sql ALTER TABLE users ADD COLUMN phone VARCHAR(20); -- Add with default value ALTER TABLE users ADD COLUMN is_active BOOLEAN NOT NULL DEFAULT true;
sql-- V003__create_tasks_table.sql CREATE TABLE tasks ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), title VARCHAR(500) NOT NULL, user_id UUID NOT NULL, created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- Foreign key with cascade CONSTRAINT fk_tasks_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE ); CREATE INDEX idx_tasks_user_id ON tasks(user_id);
sql-- V004__create_user_roles.sql CREATE TABLE user_roles ( user_id UUID NOT NULL, role_id UUID NOT NULL, assigned_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (user_id, role_id), CONSTRAINT fk_user_roles_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, CONSTRAINT fk_user_roles_role FOREIGN KEY (role_id) REFERENCES roles(id) ON DELETE CASCADE ); CREATE INDEX idx_user_roles_user_id ON user_roles(user_id); CREATE INDEX idx_user_roles_role_id ON user_roles(role_id);
kotlin@Test fun `migration V004 creates user_roles table`() { // Arrange - Clean database flyway.clean() // Act - Run migrations flyway.migrate() // Assert - Check table exists val tableExists = database.useConnection { connection -> val meta = connection.metaData val rs = meta.getTables(null, null, "user_roles", null) rs.next() } assertTrue(tableExists, "user_roles table should exist after migration") }
kotlin@Test fun `user_roles enforces foreign key constraint`() { // Arrange val invalidUserId = UUID.randomUUID() val role = createTestRole() // Act & Assert assertThrows<SQLException> { database.transaction { UserRoles.insert { it[userId] = invalidUserId // Invalid - user doesn't exist it[roleId] = role.id } } } }
Issue: Adding NOT NULL column to table with existing rows
ERROR: column "status" contains null valuesWhat to try:
Example fix:
sql-- Step 1: Add nullable ALTER TABLE tasks ADD COLUMN status VARCHAR(20); -- Step 2: Update existing rows UPDATE tasks SET status = 'pending' WHERE status IS NULL; -- Step 3: Make NOT NULL ALTER TABLE tasks ALTER COLUMN status SET NOT NULL;
Issue: Table A references B, B references A - which to create first?
What to try:
Example:
sql-- V001: Create tables without FKs CREATE TABLE users (...); CREATE TABLE profiles (...); -- V002: Add foreign keys ALTER TABLE users ADD CONSTRAINT fk_users_profile ...; ALTER TABLE profiles ADD CONSTRAINT fk_profiles_user ...;
Issue: Creating index on large table times out
What to try:
Issue: ORM expects UUID but database has VARCHAR
What to try:
sql ALTER TABLE tasks ALTER COLUMN id TYPE UUID USING id::uuid;
Issue: Foreign key references table that doesn't exist yet
What to try:
If blocked: Report to orchestrator - migration order issue or missing prerequisite
⚠️ BLOCKED - Requires Senior Engineer
Issue: [Specific problem - migration fails, constraint violation, etc.]
Attempted Fixes:
- [What you tried #1]
- [What you tried #2]
- [Why attempts didn't work]
Root Cause (if known): [Your analysis]
Partial Progress: [What work you DID complete]
Context for Senior Engineer:
- Migration SQL: [Paste migration]
- Error output: [Database error]
- Related migrations: [Dependencies]
Requires: [What needs to happen]kotlinobject Users : UUIDTable("users") { val email = varchar("email", 255).uniqueIndex() val passwordHash = varchar("password_hash", 255) val name = varchar("name", 255) val createdAt = timestamp("created_at").defaultExpression(CurrentTimestamp()) val updatedAt = timestamp("updated_at").defaultExpression(CurrentTimestamp()) }
kotlinobject Tasks : UUIDTable("tasks") { val title = varchar("title", 500) val userId = reference("user_id", Users) val createdAt = timestamp("created_at").defaultExpression(CurrentTimestamp()) }
kotlinfun findTasksWithUser(userId: UUID): List<TaskWithUser> { return (Tasks innerJoin Users) .select { Tasks.userId eq userId } .map { row -> TaskWithUser( task = rowToTask(row), user = rowToUser(row) ) } }
Good (can rollback):
Difficult to rollback:
For complex migrations, document rollback steps:
sql-- Migration: V005__add_user_status.sql ALTER TABLE users ADD COLUMN status VARCHAR(20) NOT NULL DEFAULT 'active'; -- Rollback (document in comments): -- ALTER TABLE users DROP COLUMN status;
✅ DO create indexes on:
❌ DON'T create indexes on:
sql-- ❌ BAD - Missing index, full table scan SELECT * FROM users WHERE email = 'user@example.com'; -- ✅ GOOD - Index on email column CREATE INDEX idx_users_email ON users(email); -- ❌ BAD - N+1 query problem SELECT * FROM users; -- 1 query SELECT * FROM tasks WHERE user_id = ?; -- N queries (one per user) -- ✅ GOOD - Single query with JOIN SELECT u.*, t.* FROM users u LEFT JOIN tasks t ON t.user_id = u.id;
❌ Don't modify existing migrations (create new one) ❌ Don't drop columns without data backup ❌ Don't forget indexes on foreign keys ❌ Don't use SELECT in production queries ❌ Don't skip testing migrations on clean database ❌ Don't forget CASCADE behavior on foreign keys ❌ Don't create migrations that depend on data state
When reading task sections, prioritize:
requirements - What schema changes neededtechnical-approach - Migration strategydata-model - Entity relationshipsmigration - Specific SQL requirementsFor deeper patterns and examples, see:
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | fail→fail | 13,256 | 7,310 | -45% | 1 | 1 | 0% | 2,634 | 4,341 | +65% | 0 | 0 | — |
case-02 | pass→pass | 8,326 | 6,950 | -17% | 1 | 1 | 0% | 1,454 | 3,976 | +173% | 0 | 0 | — |
case-03 | pass→pass | 8,568 | 5,377 | -37% | 1 | 1 | 0% | 1,495 | 3,692 | +147% | 0 | 0 | — |
case-04 | pass→pass | 6,295 | 5,236 | -17% | 1 | 1 | 0% | 1,136 | 3,797 | +234% | 0 | 0 | — |
case-05 | fail→fail | 7,930 | 6,592 | -17% | 1 | 1 | 0% | 1,473 | 4,104 | +179% | 0 | 0 | — |
case-06 | fail→pass | 10,128 | 7,553 | -25% | 1 | 1 | 0% | 1,891 | 4,160 | +120% | 0 | 0 | — |
case-12 | fail→pass | 15,459 | 8,208 | -47% | 1 | 1 | 0% | 3,010 | 4,383 | +46% | 0 | 0 | — |
case-07 | pass→pass | 9,390 | 7,790 | -17% | 1 | 1 | 0% | 1,753 | 4,367 | +149% | 0 | 0 | — |
case-08 | pass→fail | 9,719 | 8,052 | -17% | 1 | 1 | 0% | 1,893 | 4,539 | +140% | 0 | 0 | — |
case-09 | pass→pass | 9,000 | 5,070 | -44% | 1 | 1 | 0% | 1,568 | 3,758 | +140% | 0 | 0 | — |
case-10 | pass→pass | 3,323 | 3,925 | +18% | 1 | 1 | 0% | 599 | 3,480 | +481% | 0 | 0 | — |
case-11 | pass→pass | 10,732 | 6,796 | -37% | 1 | 1 | 0% | 1,985 | 4,141 | +109% | 0 | 0 | — |
case-13 | fail→pass | 13,190 | 6,361 | -52% | 1 | 1 | 0% | 2,627 | 4,042 | +54% | 0 | 0 | — |
case-14 | pass→pass | 10,063 | 6,463 | -36% | 1 | 1 | 0% | 1,811 | 4,013 | +122% | 0 | 0 | — |
case-15 | pass→pass | 13,060 | 8,089 | -38% | 1 | 1 | 0% | 2,154 | 4,300 | +100% | 0 | 0 | — |
case-16 | pass→pass | 10,359 | 6,236 | -40% | 1 | 1 | 0% | 1,937 | 3,968 | +105% | 0 | 0 | — |
case-17 | pass→pass | 8,692 | 4,557 | -48% | 1 | 1 | 0% | 1,443 | 3,609 | +150% | 0 | 0 | — |
case-18 | fail→pass | 18,723 | 3,153 | -83% | 1 | 1 | 0% | 949 | 3,360 | +254% | 0 | 0 | — |
case-19 | pass→pass | 31,386 | 6,470 | -79% | 1 | 1 | 0% | 2,344 | 3,865 | +65% | 0 | 0 | — |
case-20 | pass→pass | 14,540 | 9,553 | -34% | 1 | 1 | 0% | 2,441 | 4,321 | +77% | 0 | 0 | — |
case-21 | pass→pass | 13,894 | 11,218 | -19% | 1 | 1 | 0% | 2,415 | 4,832 | +100% | 0 | 0 | — |
case-22 | pass→pass | 15,746 | 10,433 | -34% | 1 | 1 | 0% | 2,781 | 4,669 | +68% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted, and 21 counted toward the lift figure. The other 1 produced results that are not comparable between the two arms, so they are excluded from the headline rather than averaged into it. The headline lift of +14 percentage points is the difference between those two pass rates over the 21 comparable cases. 1 case got worse with the skill loaded, and it is included in that figure.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.