d1-drizzle-migrations

ldsgroups225's avatarfrom ldsgroups225

Use this when changing the database schema, generating/applying Drizzle migrations for Cloudflare D1 (SQLite), or working with Better Auth schema generation.

0stars🔀0forks📁View on GitHub🕐Updated Jan 9, 2026

When & Why to Use This Skill

This Claude skill streamlines database management for Cloudflare D1 using Drizzle ORM. It automates the end-to-end workflow of schema evolution, including generating SQL migrations, applying changes to local or remote SQLite environments, and managing Better Auth schema integrations. By enforcing centralized schema definitions within a monorepo, it ensures architectural consistency and reduces manual CLI overhead for developers.

Use Cases

  • Schema Evolution: Automatically generate and apply SQL migrations when adding or modifying database tables in a Cloudflare D1 environment.
  • Authentication Setup: Seamlessly regenerate and sync Better Auth schemas within a dedicated data-ops package to maintain security and consistency.
  • Cross-Environment Deployment: Apply database migrations to local SQLite files for development testing or deploy them to production Cloudflare D1 instances using secure environment variables.
  • Monorepo Maintenance: Rebuild shared data libraries and regenerate worker types automatically after schema changes to ensure type safety across the entire application stack.
named1-drizzle-migrations
descriptionUse this when changing the database schema, generating/applying Drizzle migrations for Cloudflare D1 (SQLite), or working with Better Auth schema generation.

Cloudflare D1 + Drizzle migrations (via packages/data-ops)

Use this skill when the user asks to add or modify tables, regenerate auth schema, generate migration SQL, or apply migrations locally/remote.

Hard rules (architecture)

  • Do not define DB schemas in apps.
  • Always define schemas in packages/data-ops/src/drizzle/ and import from there.

Better Auth schema

  • Generate auth schema:
    • pnpm run --filter data-ops better-auth:generate

Drizzle migrations

  • Generate SQL migrations:

    • pnpm run --filter data-ops drizzle:generate
  • Run migrations (uses the packages/data-ops script drizzle:migrate):

    • pnpm run --filter data-ops drizzle:migrate

Apply migrations

  • Apply locally (recommended):

    • Run the user app at least once so a local D1 SQLite file exists under apps/user-application/.wrangler/state/....
    • Then run: pnpm run --filter data-ops drizzle:migrate
  • Apply locally (manual / fallback, run from apps/user-application):

    • npx wrangler d1 execute DB --local --file=../../packages/data-ops/src/drizzle/<migration_file>.sql
  • Apply remotely (D1 HTTP driver):

    • NODE_ENV=production pnpm run --filter data-ops drizzle:migrate

Remote migrate requires CLOUDFLARE_ACCOUNT_ID (or CLOUDFLARE_D1_ACCOUNT_ID), CLOUDFLARE_DATABASE_ID, and CLOUDFLARE_D1_TOKEN (or CLOUDFLARE_D1_API_TOKEN).

Verification

  • After schema changes, rebuild the shared library:
    • pnpm run build:data-ops
  • If runtime bindings/types changed, regenerate worker types (see worker typegen skill).
d1-drizzle-migrations – AI Agent Skills | Claude Skills