Skip to content

Commit 45ff635

Browse files
committed
feat: add local postgres database for dev environment with PGLite
1 parent 2991141 commit 45ff635

File tree

8 files changed

+28
-191
lines changed

8 files changed

+28
-191
lines changed

β€Ž.envβ€Ž

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ NEXT_PUBLIC_POSTHOG_KEY=
1111
NEXT_PUBLIC_POSTHOG_HOST=https://us.i.posthog.com
1212

1313
# Database
14-
# Need a database for production? Just claim it by running `npm run neon:claim`.
14+
# Local database with PGLite, already included in the project, no Docker needed
15+
# Need a database for production? Check out https://www.prisma.io/?via=nextjsboilerplate
1516
# Tested and compatible with Next.js Boilerplate
16-
17-
# `DATABASE_URL` is a placeholder, you can find your connection string in `.env.local` file.
1817
DATABASE_URL=postgresql://postgres:postgres@127.0.0.1:5432/postgres
1918

2019
# Next.js

β€Ž.env.productionβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ CHECKLY_LOGICAL_ID=nextjs-boilerplate
2727

2828
# Database
2929
# Using an incorrect DATABASE_URL value, Next.js build will timeout and you will get the following error: "because it took more than 60 seconds"
30-
# Need a database for production? Just claim it by running `npm run neon:claim`.
30+
# Need a database for production? Check out https://www.prisma.io/?via=nextjsboilerplate
3131
# Tested and compatible with Next.js Boilerplate
3232
# DATABASE_URL=postgresql://postgres@localhost:5432/postgres
3333

β€ŽREADME.mdβ€Ž

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</a>
1111
</p>
1212

13-
πŸš€ Boilerplate and Starter for Next.js with App Router, Tailwind CSS, and TypeScript ⚑️ Prioritizing developer experience first: Next.js, TypeScript, ESLint, Prettier, Lefthook (replacing Husky), Lint-Staged, Vitest (replacing Jest), Testing Library, Playwright, Commitlint, VSCode, Tailwind CSS, Authentication with [Clerk](https://clerk.com?utm_source=github&utm_medium=sponsorship&utm_campaign=nextjs-boilerplate), Database with DrizzleORM (PostgreSQL, SQLite, and MySQL), Local database with PGlite and production with Neon (PostgreSQL), Error Monitoring with [Sentry](https://sentry.io/for/nextjs/?utm_source=github&utm_medium=paid-community&utm_campaign=general-fy25q1-nextjs&utm_content=github-banner-nextjsboilerplate-logo), Logging with LogTape (replacing Pino.js) and Log Management, Monitoring as Code, Storybook, Multi-language (i18n), AI-powered code reviews with CodeRabbit, Secure with [Arcjet](https://launch.arcjet.com/Q6eLbRE) (Bot detection, Rate limiting, Attack protection, etc.), and more.
13+
πŸš€ Boilerplate and Starter for Next.js with App Router, Tailwind CSS, and TypeScript ⚑️ Prioritizing developer experience first: Next.js, TypeScript, ESLint, Prettier, Lefthook (replacing Husky), Lint-Staged, Vitest (replacing Jest), Testing Library, Playwright, Commitlint, VSCode, Tailwind CSS, Authentication with [Clerk](https://clerk.com?utm_source=github&utm_medium=sponsorship&utm_campaign=nextjs-boilerplate), Database with DrizzleORM (PostgreSQL, SQLite, and MySQL), Local database with PGlite and production with [Prisma Postgres](https://www.prisma.io/?via=nextjs-boilerplate), Error Monitoring with [Sentry](https://sentry.io/for/nextjs/?utm_source=github&utm_medium=paid-community&utm_campaign=general-fy25q1-nextjs&utm_content=github-banner-nextjsboilerplate-logo), Logging with LogTape (replacing Pino.js) and Log Management, Monitoring as Code, Storybook, Multi-language (i18n), AI-powered code reviews with CodeRabbit, Secure with [Arcjet](https://launch.arcjet.com/Q6eLbRE) (Bot detection, Rate limiting, Attack protection, etc.), and more.
1414

1515
Clone this project and use it to create your own Next.js project. You can check out the live demo at [Next.js Boilerplate](https://demo.nextjs-boilerplate.com), which includes a working authentication system.
1616

@@ -145,7 +145,7 @@ Developer experience first, extremely flexible code structure and only keep what
145145
- πŸ‘€ Passwordless Authentication with Magic Links, Multi-Factor Auth (MFA), Social Auth (Google, Facebook, Twitter, GitHub, Apple, and more), Passwordless login with Passkeys, User Impersonation
146146
- πŸ“¦ Type-safe ORM with DrizzleORM, compatible with PostgreSQL, SQLite, and MySQL
147147
- πŸ’½ Offline and local development database with PGlite
148-
- ☁️ Remote and production database with Neon (PostgreSQL)
148+
- ☁️ Remote and production database with [Prisma Postgres](https://www.prisma.io/?via=nextjs-boilerplate)
149149
- 🌐 Multi-language (i18n) with next-intl and [Crowdin](https://l.crowdin.com/next-js)
150150
- ♻️ Type-safe environment variables with T3 Env
151151
- ⌨️ Form handling with React Hook Form
@@ -227,17 +227,7 @@ Then, you can run the project locally in development mode with live reload by ex
227227
npm run dev
228228
```
229229

230-
Open http://localhost:3000 with your favorite browser to see your project. For your information, the project is already pre-configured with a database.
231-
232-
> [!WARNING]
233-
> Next.js Boilerplate ships with a fully working Postgres database for your local environment. This database is **temporary** and will expire after **72 hours** if you don't claim it.
234-
>
235-
> Once expired, the project won't be able to connect to the database, and it'll throw connection errors.
236-
>
237-
> To avoid the connection errors and make the database **persistent**, run `npm run neon:claim`. After claiming it, the database becomes persistent and suitable for production use as well.
238-
239-
> [!CAUTION]
240-
> The authentication system requires environment variables to be set up. Please refer to the [Set up authentication](#set-up-authentication) section.
230+
Open http://localhost:3000 with your favorite browser to see your project. For your information, the project is already pre-configured with a local database using PGlite. No extra setup is required to run the project locally.
241231

242232
Need advanced features? Multi-tenancy & Teams, Roles & Permissions, Shadcn UI, End-to-End Typesafety with oRPC, Stripe Payment, Light / Dark mode. Try [Next.js Boilerplate Pro](https://nextjs-boilerplate.com/pro-saas-starter-kit).
243233

@@ -256,29 +246,15 @@ Now you have a fully functional authentication system with Next.js, including fe
256246

257247
The project uses DrizzleORM, a type-safe ORM that is compatible with PostgreSQL, SQLite, and MySQL databases. By default, the project is configured to seamlessly work with PostgreSQL, and you have the flexibility to choose any PostgreSQL database provider of your choice.
258248

259-
When you launch the project locally for the first time, it automatically creates a temporary PostgreSQL database. This allows you to work with a PostgreSQL database without Docker or any additional setup.
260-
261-
This temporary database will **expire after 72 hours** if you don't claim it. To avoid connection errors and **make the database persistent**, simply run the following command:
262-
263-
```shell
264-
npm run neon:claim
265-
```
249+
When you launch the project locally for the first time, it automatically creates a PostgreSQL database on your local machine. This allows you to work with a PostgreSQL database without Docker or any additional setup.
266250

267-
Then, follow the instructions provided in the terminal to complete the claiming process.
251+
To set up a remote and production database, you need to create a PostgreSQL database and obtain the connection string. One recommended option is to use [Prisma PostgreSQL](https://www.prisma.io/?via=nextjs-boilerplate), which provides a free PostgreSQL database. This database is compatible and has been tested with Next.js Boilerplate.
268252

269-
Once claimed, the database is suitable for production use. You can create separate database branches for development, staging, and production environments to keep data isolated.
253+
After creating your Prisma account, you can get the connection string in the `Connect to your database` section and select the `Any client` tab. Then, you can generate the connection string by clicking the `Generate database credentials` button. Finally, you can copy the connection string and add the `DATABASE_URL` variable to the `.env.local` file.
270254

271255
#### Create a fresh and empty database
272256

273-
If you want to create a fresh and empty database, you just need to remove the following environment variables: `DATABASE_URL`, `DATABASE_URL_DIRECT` and `PUBLIC_INSTAGRES_CLAIM_URL` from the `.env.local` file.
274-
275-
Then, run the following command to create a new temporary database:
276-
277-
```shell
278-
npm run dev
279-
```
280-
281-
After the database is created, the connection strings will be automatically added to your `.env.local` file. And, don't forget to claim the database with `npm run neon:claim`.
257+
If you want to create a fresh and empty database, you just need to remove the folder `local.db` from the root of the project. The next time you run the project, a new database will be created automatically.
282258

283259
### Translation (i18n) setup
284260

β€Žpackage-lock.jsonβ€Ž

Lines changed: 7 additions & 149 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žpackage.jsonβ€Ž

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"scripts": {
88
"dev:spotlight": "npx @spotlightjs/spotlight",
99
"dev:next": "next dev",
10-
"dev": "npm-run-all db-remote:neon db:migrate --parallel dev:*",
10+
"dev": "run-p db-server:file dev:*",
1111
"build:next": "next build --webpack",
1212
"build-local": "run-p db-server:memory build:next --race",
1313
"build": "run-s db:migrate build:next",
@@ -22,8 +22,6 @@
2222
"commit": "commit",
2323
"test": "vitest run",
2424
"test:e2e": "playwright test",
25-
"db-remote:neon": "npx get-db --yes --env .env.local --ref nextjs-boilerplate",
26-
"neon:claim": "npx get-db claim --env .env.local --ref nextjs-boilerplate",
2725
"db-server:file": "pglite-server --db=local.db --run 'npm run db:migrate'",
2826
"db-server:memory": "pglite-server --run 'npm run db:migrate'",
2927
"db:generate": "drizzle-kit generate",
@@ -91,7 +89,6 @@
9189
"eslint-plugin-react-refresh": "^0.4.26",
9290
"eslint-plugin-storybook": "^10.1.11",
9391
"eslint-plugin-tailwindcss": "^4.0.0-beta.0",
94-
"get-db": "^0.11.0",
9592
"knip": "^5.80.0",
9693
"lefthook": "^2.0.13",
9794
"npm-run-all": "^4.1.5",

β€Žsrc/app/[locale]/(marketing)/page.tsxβ€Ž

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,14 @@ export default async function Index(props: IIndexProps) {
7171
</li>
7272
<li>πŸ“¦ ORM with DrizzleORM (PostgreSQL, SQLite, MySQL support)</li>
7373
<li>
74-
πŸ’½ Dev database with PGlite and production with Neon (PostgreSQL)
74+
πŸ’½ Dev database with PGlite and production with
75+
{' '}
76+
<a
77+
className="font-bold text-blue-700 hover:border-b-2 hover:border-blue-700"
78+
href="https://www.prisma.io/?via=nextjsindex"
79+
>
80+
Prisma PostgreSQL
81+
</a>
7582
</li>
7683
<li>
7784
🌐 Multi-language support (i18n) with next-intl and

β€Žsrc/models/Schema.tsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { integer, pgTable, serial, timestamp } from 'drizzle-orm/pg-core';
1010
// It automatically run the command `db-server:file`, which apply the migration before Next.js starts in development mode,
1111
// Alternatively, if your database is running, you can run `npm run db:migrate` and there is no need to restart the server.
1212

13-
// Need a database for production? Just claim it by running `npm run neon:claim`.
13+
// Need a database for production? Check out https://www.prisma.io/?via=nextjsboilerplate
1414
// Tested and compatible with Next.js Boilerplate
1515

1616
export const counterSchema = pgTable('counter', {

β€Žsrc/utils/DBConnection.tsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Pool } from 'pg';
33
import { Env } from '@/libs/Env';
44
import * as schema from '@/models/Schema';
55

6-
// Need a database for production? Just claim it by running `npm run neon:claim`.
6+
// Need a database for production? Check out https://www.prisma.io/?via=nextjsboilerplate
77
// Tested and compatible with Next.js Boilerplate
88
export const createDbConnection = () => {
99
const pool = new Pool({

0 commit comments

Comments
Β (0)