Skip to content

Commit e8295b7

Browse files
committed
Initial Commit
0 parents  commit e8295b7

File tree

19 files changed

+844
-0
lines changed

19 files changed

+844
-0
lines changed

.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
27+
# local env files
28+
.env.local
29+
.env.development.local
30+
.env.test.local
31+
.env.production.local
32+
33+
# vercel
34+
.vercel

Procfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: yarn start

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
title: NextJS Prisma
3+
description: A NextJS app using Prisma with a PostgreSQL database
4+
tags:
5+
- next
6+
- prisma
7+
- postgresql
8+
- typescript
9+
---
10+
11+
# NextJS Prisma Example
12+
13+
This example is a [NextJS](https://nextjs.org/) todo app that uses
14+
[Prisma](https://www.prisma.io/) to store todos in Postgres.
15+
16+
[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/new?template=https%3A%2F%2Fgithub.com%2Frailwayapp%2Fexamples%2Ftree%2Fmaster%2Fexamples%2Fnextjs-prisma&plugins=postgresql)
17+
18+
## ✨ Features
19+
20+
- Prisma
21+
- NextJS
22+
- Postgres
23+
- TypeScript
24+
25+
## 💁‍♀️ How to use
26+
27+
- [Provision a Postgres container on Railway](https://dev.new)
28+
- Connect to your Railway project with `railway link`
29+
- Migrate the database `railway run yarn migrate:dev`
30+
- Run the NextJS app `railway run yarn dev`
31+
32+
## 📝 Notes
33+
34+
This app is a simple todo list where the data is persisted to Postgres. [Prisma
35+
migrations](https://www.prisma.io/docs/concepts/components/prisma-migrate#prisma-migrate)
36+
can be created with `railway run yarn migrate:dev` and deployed with `railway run yarn migrate:deploy`. The Prisma client can be regenerated with
37+
`yarn generate`.
38+
39+
[swr](https://swr.vercel.app/) is used to fetch data on the client and perform optimistic updates.

next-env.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/// <reference types="next" />
2+
/// <reference types="next/types/global" />

package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "with-nextjs-postgres",
3+
"version": "0.1.0",
4+
"private": true,
5+
"scripts": {
6+
"dev": "next dev",
7+
"build": "yarn migrate:deploy && next build",
8+
"start": "next start --port ${PORT-3000}",
9+
"migrate:dev": "prisma migrate dev --preview-feature",
10+
"migrate:deploy": "prisma migrate deploy --preview-feature",
11+
"migrate:status": "prisma migrate status --preview-feature",
12+
"generate": "prisma generate"
13+
},
14+
"dependencies": {
15+
"@prisma/client": "2.30.0",
16+
"next": "12.1.0",
17+
"pg": "^8.5.1",
18+
"react": "17.0.1",
19+
"react-dom": "17.0.1",
20+
"swr": "^0.4.1"
21+
},
22+
"devDependencies": {
23+
"prisma": "2.30.0",
24+
"@types/node": "^14.14.22",
25+
"@types/react": "^17.0.0",
26+
"typescript": "^4.1.3"
27+
}
28+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- CreateTable
2+
CREATE TABLE "Todo" (
3+
"id" TEXT NOT NULL,
4+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
5+
"text" TEXT NOT NULL,
6+
"completed" BOOLEAN NOT NULL,
7+
8+
PRIMARY KEY ("id")
9+
);

prisma/migrations/migration_lock.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Please do not edit this file manually
2+
provider = "postgresql"

prisma/schema.prisma

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// This is your Prisma schema file,
2+
// learn more about it in the docs: https://pris.ly/d/prisma-schema
3+
4+
datasource db {
5+
provider = "postgresql"
6+
url = env("DATABASE_URL")
7+
}
8+
9+
generator client {
10+
provider = "prisma-client-js"
11+
}
12+
13+
model Todo {
14+
id String @id @default(uuid())
15+
createdAt DateTime @default(now())
16+
text String
17+
completed Boolean
18+
}

public/favicon.ico

14.7 KB
Binary file not shown.

public/vercel.svg

Lines changed: 4 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)