You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+152-13
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,25 @@
1
-
# Next.js TypeScript Material UI quality checking project
1
+
# Next.js TypeScript Material UI quality checking project<!-- omit in toc -->
2
2
3
3
Includes TypeScript, Material UI, ESLint, Jest, and React Testing Library
4
4
5
-
-[Deploy your own](#deploy-your-own)
6
-
-[How to use](#how-to-use)
5
+
-[App startup](#app-startup)
6
+
-[SQLite](#sqlite)
7
+
-[Postgres](#postgres)
8
+
-[Using Prisma](#using-prisma)
9
+
-[Adding a table to your database](#adding-a-table-to-your-database)
10
+
-[Creating migrations](#creating-migrations)
11
+
-[Seeding sample data](#seeding-sample-data)
12
+
-[Using prisma client to perform database actions](#using-prisma-client-to-perform-database-actions)
7
13
-[Scripts](#scripts)
14
+
-[generate-types](#generate-types)
15
+
-[watch-queries](#watch-queries)
16
+
-[generate](#generate)
17
+
-[migrate](#migrate)
18
+
-[deploy](#deploy)
19
+
-[reset](#reset)
20
+
-[seed](#seed)
21
+
-[studio](#studio)
22
+
-[prisma](#prisma)
8
23
-[build](#build)
9
24
-[dev](#dev)
10
25
-[format](#format)
@@ -15,28 +30,152 @@ Includes TypeScript, Material UI, ESLint, Jest, and React Testing Library
15
30
-[quality](#quality)
16
31
-[Accessibility ](#accessibility)
17
32
18
-
## Deploy your own
33
+
## App startup
19
34
20
-
Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example):
35
+
Choose how to start your development server based on your database configuration below.
21
36
22
-
[](https://vercel.com/new/git/external?repository-url=https://github.com/MileTwo/nextjs-typescript-material-ui-eslint-jest)
37
+
### SQLite
23
38
24
-
## How to use
39
+
First time starting your app make sure to run `prisma` then start your app.
25
40
26
-
Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example:
41
+
```
42
+
npm run prisma && npm run dev
43
+
```
44
+
45
+
### Postgres
46
+
47
+
Ensure you have a `.env` file with a `DATABASE_URL` variable following the [format required by prisma](https://www.prisma.io/docs/concepts/database-connectors/postgresql#connection-details) and using the credentials found in your `docker-compose.yml` file.
Start up your development server with the following command:
54
+
55
+
```
56
+
docker-compose up
57
+
```
58
+
59
+
Once your development server is up and running, in a new terminal run the following command:
60
+
61
+
```
62
+
npm run prisma && npm run dev
63
+
```
64
+
65
+
`npm run prisma` will do a few things for us:
66
+
67
+
- Format your `prisma/schema.prisma` file (`prisma format`) | [prisma format documentation](https://www.prisma.io/docs/reference/api-reference/command-reference#format)
68
+
- Keeps your `prisma/schema.prisma` file in sync with your database by auto generating migrations when needed (`npm run migrate`) | [prisma migration documentation](https://www.prisma.io/docs/concepts/components/prisma-migrate)
69
+
- Seed your database with (`npm run seed`) | [prisma seeding documentation](https://www.prisma.io/docs/guides/database/seed-database/)
70
+
71
+
## Using Prisma
72
+
73
+
> Prisma helps app developers build faster and make fewer errors with an open source ORM for PostgreSQL, MySQL and SQLite. | [Source](https://www.prisma.io/)
74
+
75
+
### Adding a table to your database
76
+
77
+
Adding a table is as easy as adding a model to your `schema.prisma` file, followed by [creating a migration](#Creating-migrations). For a tutorial on this visit the [prisma schema documentation](https://www.prisma.io/docs/concepts/components/prisma-schema).
78
+
79
+
### Creating migrations
80
+
81
+
Once you've made the [appropriate changes to your `schema.prisma`](#Adding-a-table-to-your-database) file you can auto generate a migration using
Deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).
87
+
This will generate a new folder under `prisma/migrations` with a SQL file outlining the changes to be reflected to your database and also generate new TypeScript code for prisma client usage.
88
+
89
+
To learn more visit the [prisma migration documentation](https://www.prisma.io/docs/concepts/components/prisma-migrate) or the [prisma generate documentation](https://www.prisma.io/docs/reference/api-reference/command-reference#generate).
90
+
91
+
### Seeding sample data
92
+
93
+
To seed your database, using [prisma client](#Using-prisma-client-to-perform-database-actions), add in sample data in the `prisma/seed.ts` file.
94
+
95
+
To learn more visit the [prisma seeding documentation](https://www.prisma.io/docs/guides/database/seed-database/).
96
+
97
+
### Using prisma client to perform database actions
98
+
99
+
Using the prisma client you can do the various actions required to build applications utilizing a database.
100
+
101
+
To learn more visit [working with the prisma client](https://www.prisma.io/docs/concepts/components/prisma-client/working-with-prismaclient).
35
102
36
103
## Scripts
37
104
38
105
All scripts can be run by prefixing with `npm run`, for example `npm run build`
39
106
107
+
### generate-types
108
+
109
+
Using [graphql code generator](https://www.graphql-code-generator.com/) this generates types based on the `codegen.yml` configuration. In the initial setup this will update files under the `gen/` directory.
110
+
111
+
```bash
112
+
npm run generate-types
113
+
```
114
+
115
+
### watch-queries
116
+
117
+
Using [graphql code generator](https://www.graphql-code-generator.com/) this command listens for changes based on the `documents` key in the `codegen.yml` file, and generates types.
118
+
119
+
```bash
120
+
npm run watch-queries
121
+
```
122
+
123
+
### generate
124
+
125
+
See the [prisma generate documentation](https://www.prisma.io/docs/reference/api-reference/command-reference#generate).
126
+
127
+
```bash
128
+
npm run generate
129
+
```
130
+
131
+
### migrate
132
+
133
+
See the [prisma migration documentation](https://www.prisma.io/docs/concepts/components/prisma-migrate).
134
+
135
+
```bash
136
+
npm run migrate
137
+
```
138
+
139
+
### deploy
140
+
141
+
> To apply pending migrations to development, staging, or testing environments, run the `migrate deploy` command as part of your CI/CD pipeline | [Source](https://www.prisma.io/docs/guides/deployment/deploy-database-changes-with-prisma-migrate).
142
+
143
+
```bash
144
+
npm run deploy
145
+
```
146
+
147
+
### reset
148
+
149
+
When you want to reset your database to a clean slate, this clears all migrations and re-runs the migration list, then seeds the database. For more visit [prisma migrate reset](https://www.prisma.io/docs/reference/api-reference/command-reference/#migrate-reset).
150
+
151
+
```bash
152
+
npm run reset
153
+
```
154
+
155
+
### seed
156
+
157
+
Runs the `prisma/seed.ts` script to seed your database. See the [prisma seeding documentation](https://www.prisma.io/docs/guides/database/seed-database/).
158
+
159
+
```bash
160
+
npm run seed
161
+
```
162
+
163
+
### studio
164
+
165
+
Allows you to interact with and manage your data interactively. For more visit [prisma studio](https://www.prisma.io/docs/reference/api-reference/command-reference/#studio).
166
+
167
+
```bash
168
+
npm run studio
169
+
```
170
+
171
+
### prisma
172
+
173
+
An aggregate command used to format your schema file, check for differences from schema to db, generate a prisma client, and seed your database.
174
+
175
+
```bash
176
+
npm run prisma
177
+
```
178
+
40
179
### build
41
180
42
181
Builds the production application in the .next folder.
@@ -49,7 +188,7 @@ npm run build
49
188
50
189
Starts the application in development mode with hot-code reloading, error reporting, and more:
51
190
52
-
The application will start at http://localhost:3000 by default. The default port can be changed with -p, like so:
191
+
The application will start at http://localhost:3000 by default. The default port can be changed with `-p`, like so:
0 commit comments