d1-drizzle-schema
Generate Drizzle ORM schemas for Cloudflare D1 databases with correct D1-specific patterns. Produces schema files, migration commands, type exports, and DATABASE_SCHEMA.md documentation. Handles D1 quirks: foreign keys always enforced, no native BOOLEAN/DATETIME types, 100 bound parameter limit, JSON stored as TEXT. Use when creating a new database, adding tables, or scaffolding a D1 data layer.
Security Assessment
About d1-drizzle-schema
d1-drizzle-schema generates Drizzle ORM schemas for Cloudflare D1 databases using D1-correct patterns. It solves a specific class of subtle bugs: D1 is SQLite-based but differs from standard SQLite in ways that trip up default patterns — foreign keys are always enforced and cannot be disabled, there are no native BOOLEAN or DATETIME types, the bound-parameter limit is 100 (not ~999), JSON support is always available, and writes are single-threaded. Using ordinary SQLite conventions against D1 produces code that looks right but misbehaves.
The skill walks a seven-step workflow: describe the data model, generate the Drizzle schema with D1-correct column patterns (text UUID primary keys via `crypto.randomUUID()`, booleans as `integer({ mode: 'boolean' })`, timestamps as `integer({ mode: 'timestamp' })`, enums stored as TEXT, typed JSON as TEXT, and always-enforced foreign key references), add Drizzle relations, export inferred types, set up `drizzle.config.ts`, add wrangler migration scripts, and generate a DATABASE_SCHEMA.md for future sessions. It includes a bulk-insert batching pattern that respects the 100-parameter limit and D1 runtime query examples. Supporting reference files cover the full column-type catalog and D1-versus-SQLite specifics, and template assets provide a starter config and example schema. The skill is marked claude-code-only.
Target users are developers building on Cloudflare Workers with D1 who use Drizzle ORM and want schemas that avoid D1's footguns from the start. Typical use cases include scaffolding a new D1 data layer, adding tables to an existing project, and documenting a schema. The migration commands it suggests use standard Cloudflare tooling (`drizzle-kit generate`, `wrangler d1 migrations apply`) and are ordinary, non-destructive developer operations.
FAQ
What D1-specific quirks does this skill handle?
Foreign keys always enforced (cannot be disabled), no native BOOLEAN or DATETIME types, a 100 bound-parameter limit, JSON stored as TEXT, and single-threaded writes. It generates schemas that account for each of these.
How are booleans and timestamps represented?
Booleans use `integer('col', { mode: 'boolean' })` stored as 0/1, and timestamps use `integer('col', { mode: 'timestamp' })` stored as unix seconds, since D1 has no native BOOL or DATETIME types.
What does it produce besides the schema file?
Drizzle relations, exported `$inferSelect`/`$inferInsert` types, a `drizzle.config.ts` from a template, package.json migration scripts, and a DATABASE_SCHEMA.md documenting tables, relationships, indexes, and the migration workflow.
How does it handle D1's parameter limit for bulk inserts?
It computes a batch size as floor(100 / columns-per-row) and inserts rows in batches so no single statement exceeds the 100 bound-parameter limit.
Are there compatibility requirements?
The skill is marked claude-code-only. It targets Cloudflare Workers with D1 and Drizzle ORM, and its migration commands rely on drizzle-kit and wrangler.
Install d1-drizzle-schema
Quick Setup:
- Copy the skill folder to
.claude/skills/ - Claude will automatically detect and use the skill
Repository
jezweb/claude-skills