From product-builder
Adds a Cloudflare D1 database to an existing Product Builder project using Drizzle ORM, Wrangler bindings, migrations, and React Router server context. Use when the user asks to add D1, Cloudflare database storage, Drizzle ORM, database migrations, or persistent SQLite data to an existing Cloudflare Workers React Router project.
How this skill is triggered — by the user, by Claude, or both
Slash command
/product-builder:adding-databaseThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Work in the target project repository. If the project path is unclear, ask for only the path before changing files.
Work in the target project repository. If the project path is unclear, ask for only the path before changing files.
Derive these values from the project or user prompt when possible:
PROJECT_PATH: <absolute path>
D1_DATABASE_NAME: <cloudflare-d1-database-name>
D1_BINDING: APP_DB
Use APP_DB as the default binding unless the existing project already uses a different D1 binding.
pnpm for package installation and scripts.react-router-patterns before changing React Router context, Worker request handling, route modules, loaders, or actions. Any React Router code must follow those patterns.drizzle-zod for DAO-owned validation schemas when DAOs are added.db/migrations.app/db/schema.ts.wrangler.jsonc settings and merge D1 configuration into it.ALTER COLUMN — changing a column type or adding a NOT NULL column without a default requires creating a new table, copying data, and dropping the old one. Drizzle Kit handles this automatically during migration generation, but the resulting migration may drop and recreate tables.pnpm wrangler d1 create returns the database ID in its output. Capture it immediately — there is no list command that shows the ID later without wrangler d1 list, which requires an authenticated session.drizzle-kit generate reads drizzle.config.ts, which needs CLOUDFLARE_ACCOUNT_ID, CLOUDFLARE_DATABASE_ID, and CLOUDFLARE_D1_TOKEN in .env. If .env is missing or incomplete, the command fails with an unhelpful credentials error.pnpm wrangler d1 migrations apply --local) and remote D1 (pnpm db:migrate) use different migration tracking. Always run both after generating a new migration.react-router-patterns, then add the database schema and wire Drizzle into app context and the Worker using 03-app-integration.md.Drizzle ORM, Cloudflare D1.app/db/ (schema.ts, dao.ts, daos/), app/services/, db/migrations/.See [data-model.md](data-model.md) in architecture.docs/conventions/data-access.md — seed with key patterns from data-access-architecture.md: DAO interface contract, one DAO per table, type ownership (<Entity>Record, Create<Entity>, Update<Entity>, <Entity>Filters), getAll() for filtered access, service transaction boundaries, dependency graph (Routes → Services → DAOs → Database). Anti-patterns: no custom public query methods on DAOs, no DAO-to-DAO imports, no business logic in DAOs.docs/data-model.md reference in Project Documentation section.drizzle-orm, drizzle-zod, and drizzle-kit are installed.package.json includes db:generate, db:migrate, and db:local:migrate.drizzle.config.ts reads Cloudflare credentials from .env..env.example documents CLOUDFLARE_ACCOUNT_ID, CLOUDFLARE_DATABASE_ID, and CLOUDFLARE_D1_TOKEN..env uses the account ID from pnpm wrangler whoami and the database ID from pnpm wrangler d1 create.wrangler.jsonc includes a D1 binding with migrations_table and migrations_dir.app/db/schema.ts exports schema.app/context.ts exposes db: DrizzleD1Database<typeof schema>.workers/app.ts creates drizzle(env.APP_DB, { schema }) and sets it in router context.data-access-architecture.md was followed for any tables, DAOs, services, transactions, or data access workflows.react-router-patterns was loaded and followed for any React Router context or Worker request-handling changes.docs/architecture.md includes Drizzle ORM / D1 in stack, db/ directories in structure, data model link, and data-access convention link.docs/data-model.md was created and reflects app/db/schema.ts.docs/conventions/data-access.md was created with seed patterns from data-access-architecture.md.README.md documents the D1 setup, required environment variables, and migration commands.AGENTS.md documents database-specific instructions and references docs/data-model.md in the Project Documentation section.pnpm db:generate, pnpm db:migrate, and pnpm db:local:migrate work or failures are explained.Provides CDSS development patterns for drug interaction checking, dose validation, clinical scoring (NEWS2, qSOFA), and alert classification integrated into EMR workflows.
npx claudepluginhub adrianhdezm/mystack --plugin product-builder