This is a boilerplate for a Next.js project with Cloudflare Pages, D1, and Drizzle ORM.
- Create a new project on Github using this template
- Clone the repository to your local machine
- Install the dependencies using
npm install
- Create a D1 database
- Rename
.env.example
to.env
and set the environment variables - Rename
wrangler.toml.example
towrangler.toml
and set the environment variables - Modify the
package.json
file with your database name
{
"scripts": {
"db:migrate:local": "wrangler d1 migrations apply my-database-name --local",
"db:migrate:preview": "wrangler d1 migrations apply --env preview my-preview-database-name --remote",
"db:migrate:prod": "wrangler d1 migrations apply my-database-name --remote"
}
}
- Generate db migration files
pnpm db:generate
- Run db migrations
- local db:
pnpm db:migrate:local
- preview db:
pnpm db:migrate:preview
- production db:
pnpm db:migrate:prod
- View the database using drizzle studio
- local db:
pnpm db:studio:local
- preview (remote) db:
pnpm db:studio:preview
- production (remote) db:
pnpm db:studio:prod
- Run the app in development mode
pnpm dev
- Run the app in cloudflare pages locally
pnpm pages:dev
- Deploy to production environment
pnpm pages:deploy
- Deploy to preview environment
pnpm pages:deploy:preview