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
grouporfieldwithin thetaskDefinitionsection of yourflareforge.jsoncfile. -
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:generatescript from yourpackage.json. This command usesdrizzle-kitto 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:applyscript, which executeswrangler d1 migrations apply.Terminal window npm run db:applyTerminal window yarn run db:applyTerminal window pnpm run db:apply