Drizzle ORM
Flareforge uses Drizzle ORM as the default toolkit for interacting with your Cloudflare D1 database. It provides a type-safe query builder that makes database access simple and secure.
Schema Generation
Section titled “Schema Generation”A core principle of Flareforge is that your database schema is not written manually. Instead, it is automatically generated from the taskDefinition
object within your flareforge.jsonc
configuration file.
When you run flareforge codegen
, the framework reads your task groups and fields and generates the corresponding Drizzle schema in .flareforge/database/schema.ts
.
Database Migrations
Section titled “Database Migrations”Flareforge uses drizzle-kit
to handle database migrations. The workflow is designed to be straightforward:
-
Add or change a
group
orfield
within thetaskDefinition
section of yourflareforge.jsonc
file. -
Run the code generator to update the Drizzle schema file based on your changes.
Terminal window npx flareforge codegenTerminal window yarn flareforge codegenTerminal window pnpm flareforge codegen -
Run the
db:generate
script from yourpackage.json
. This command usesdrizzle-kit
to compare the updated schema with your database state and generate a new SQL migration file in themigrations/
directory.Terminal window npm run db:generateTerminal window yarn run db:generateTerminal window pnpm run db:generate -
Apply the new migration to your local D1 database using the
db:apply
script, which executeswrangler d1 migrations apply
.Terminal window npm run db:applyTerminal window yarn run db:applyTerminal window pnpm run db:apply