Skip to content

Latest commit

 

History

History
92 lines (67 loc) · 2.71 KB

README.md

File metadata and controls

92 lines (67 loc) · 2.71 KB

Next Steps (D1 Template)

Note

If you have a better workflow, feel free to open an issue or a PR.

Run the following command to create a D1 Database, then update the database_id in wrangler.toml. (Cloudflare's D1 guide)

pnpx wrangler d1 create <DATABASE-NAME>

1. Set Up Database and Run Migrations

Important

Running drizzle-kit commands for remote databases requires valid cloudflare environment variables (guide)

Once you have updated your wrangler.toml with the correct database_id, follow the instructions below.

Using Wrangler for local database
pnpm db:generate
pnpm d1:migrate:local 
pnpm dev # or pnpm preview
Using Wrangler for remote database
pnpm db:generate
pnpm d1:migrate:remote
pnpm dev # or pnpm preview
Using Drizzle-Kit for local database

Using Migrations

pnpm db:generate
pnpm db:migrate:local
pnpm dev # or pnpm preview

Pushing Schema Changes

pnpm db:push:local
pnpm dev # or pnpm preview
Using Drizzle-Kit for remote database requires Cloudflare environment variables

Using Migrations

pnpm db:generate
pnpm db:migrate
pnpm dev # or pnpm preview

Pushing Schema Changes

pnpm db:push
pnpm dev # or pnpm preview

2. Deployment

To deploy to Cloudflare, you can connect your application via cloudflare dashboard (GitHub integration) or run pnpm deploy. follow Cloudflare's Next.js guide.

3. Configure Cloudflare Environment Variables (Optional)

You can run migrations using wrangler d1 migrations ..., but if you want to use drizzle-kit instead, you need to configure your environment variables.

cp .dev.vars.example .dev.vars

You can find CLOUDFLARE_ACCOUNT_ID, CLOUDFLARE_DATABASE_ID, and CLOUDFLARE_TOKEN in the Cloudflare dashboard:

  • To get CLOUDFLARE_ACCOUNT_ID, go to Workers & Pages -> Overview -> copy Account ID from the right sidebar.
  • To get CLOUDFLARE_DATABASE_ID, open the D1 database you want to connect to and copy the Database ID.
  • To get CLOUDFLARE_TOKEN, go to My Profile -> API Tokens and create a token with D1 edit permissions.

Now you can run Drizzle-Kit remote commands such as db:push, db:migrate, db:studio, etc.