This starter makes it easy to start up a project with database using Drizzle.
Create your new project:
npx degit redwoodjs/example-drizzle my-project-name
cd my-project-name
pnpm install
pnpm dev
Point your browser to the URL displayed in the terminal (e.g. http://localhost:5173/
). You should see a "Hello World" message in your browser.
Within your project's wrangler.jsonc
file, replace the placeholder values. For example:
You'll need a Cloudflare account as this starter uses Cloudflare D1 for the database.
Create a new D1 database:
npx wrangler d1 create my-project-db
Copy the database_id
from the output and paste it into:
- Your project's
wrangler.json
file - The
.env
file (copy from.env.example
)
CLOUDFLARE_ACCOUNT_ID=your-account-id
CLOUDFLARE_DATABASE_ID=your-database-id
CLOUDFLARE_D1_TOKEN=your-api-token
To get your Cloudflare credentials:
- Account ID: Find this under Workers & Pages in your Cloudflare dashboard
- API Token: Generate this under User Profile > API Tokens with the following permissions:
- Account Settings: Read
- D1: Edit
The starter includes a basic user model in src/db/schema.ts
:
export const users = sqliteTable("users", {
id: text("id").primaryKey(),
name: text("name").notNull(),
email: text("email").notNull().unique(),
createdAt: integer("created_at", { mode: "timestamp" })
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
});
When you need to make changes to your database schema:
- Update your schema in
src/db/schema.ts
- Run
pnpm migrate:new
to create a new migration - Run
pnpm migrate:dev
to apply the migration
VS Code extensions that make development easier:
For database management, we recommend Bee Keeper Studio.