d1-drizzle-schema

Generate Drizzle ORM schemas for Cloudflare D1 databases with D1-specific column patterns.

3|1|Updated Apr 29, 2026
One-click install
npx skills add https://github.com/firstsun-dev/skills --skill d1-drizzle-schema-firstsun-dev
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: d1-drizzle-schema
Source: https://github.com/firstsun-dev/skills/tree/main/custom/develop/d1-drizzle-schema
Command: npx skills add https://github.com/firstsun-dev/skills --skill d1-drizzle-schema-firstsun-dev

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires drizzle-orm, drizzle-kit, and includes references (resource) and assets (resource) components.

What problem does it solve? Writing Drizzle ORM schemas for Cloudflare D1 fails when developers assume standard SQLite behavior, because D1 enforces foreign keys permanently, limits bound parameters to 100, and lacks native BOOLEAN and DATETIME types. This Skill provides verified column patterns and workflow guidance so generated schemas work correctly on D1 the first time. ## Core Features & Use Cases - D1-Correct Column Patterns: Complete reference for UUID primary keys, text enums, booleans as integer, timestamps as integer, and typed JSON columns. - D1 Specifics Reference: Documents D1 limits and differences from SQLite, including the 100 bound parameter cap, always-on foreign keys, and JSON extraction functions. - Bulk Insert Workflow: Provides batch size calculation and migration scripts to avoid silent failures from the parameter limit. - Use Case: When scaffolding a new Cloudflare Workers project with a D1 database, use this Skill to generate the schema.ts file, drizzle-kit config, and migration scripts with correct D1 typing throughout. ## Quick Start Generate a Drizzle ORM schema for my Cloudflare D1 database with users and posts tables including proper D1 column types.

Frequently Asked Questions about d1-drizzle-schema

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I define a Drizzle ORM schema for Cloudflare D1?▼

Define tables using sqliteTable from drizzle-orm/sqlite-core with D1-compatible column types: text for strings and JSON, integer with mode boolean or timestamp for booleans and dates. Always export inferred types using $inferSelect and $inferInsert for each table.

How do I store JSON in a Cloudflare D1 database with Drizzle?▼

Store JSON as a TEXT column with mode json, and Drizzle handles serialization automatically. Add $type for typed JSON, and note that json_extract throws a malformed JSON error on non-JSON text, so guard queries with json_valid.

Does Cloudflare D1 support boolean and timestamp column types?▼

D1 has no native BOOLEAN or DATETIME types. Use integer with mode boolean for true/false values stored as 0/1, and integer with mode timestamp for dates stored as unix epoch seconds and returned as Date objects.

Why does my D1 bulk insert fail silently or partially?▼

D1 limits bound parameters to 100 per query, so large inserts exceed the limit and fail silently or partially. Calculate batch size as Math.floor(100 divided by columns per row) and insert rows in chunks of that size.

Can I disable foreign key enforcement in Cloudflare D1?▼

No, foreign keys are always enforced in D1 and PRAGMA foreign_keys is blocked. For migrations with circular foreign keys, use PRAGMA defer_foreign_keys = on at the start of the migration to control ordering.