d1-drizzle-schema

Featured

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.

API & Backend 1,031 stars 104 forks Updated today MIT

Install

View on GitHub

Quality Score: 96/100

Stars 20%
100
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# D1 Drizzle Schema Generate correct Drizzle ORM schemas for Cloudflare D1. D1 is SQLite-based but has important differences that cause subtle bugs if you use standard SQLite patterns. This skill produces schemas that work correctly with D1's constraints. ## Critical D1 Differences | Feature | Standard SQLite | D1 | |---------|-----------------|-----| | Foreign keys | OFF by default | **Always ON** (cannot disable) | | Boolean type | No | No — use `integer({ mode: 'boolean' })` | | Datetime type | No | No — use `integer({ mode: 'timestamp' })` | | Max bound params | ~999 | **100** (affects bulk inserts) | | JSON support | Extension | **Always available** (json_extract, ->, ->>) | | Concurrency | Multi-writer | **Single-threaded** (one query at a time) | ## Workflow ### Step 1: Describe the Data Model Gather requirements: what tables, what relationships, what needs indexing. If working from an existing description, infer the schema directly. ### Step 2: Generate Drizzle Schema Create schema files using D1-correct column patterns: ```typescript import { sqliteTable, text, integer, real, index, uniqueIndex } from 'drizzle-orm/sqlite-core' export const users = sqliteTable('users', { // UUID primary key (preferred for D1) id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()), // Text fields name: text('name').notNull(), email: text('email').notNull(), // Enum (stored as TEXT, validated at schema level) role: text('role', { enum: ['admin', 'edi...

Details

Author
jezweb
Repository
jezweb/claude-skills
Created
11 months ago
Last Updated
today
Language
Python
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category