Skip to content

Commit

Permalink
Set up database with Prisma ORM (#13)
Browse files Browse the repository at this point in the history
Co-authored-by: Gabriel Majeri <gabriel.majeri6@gmail.com>
  • Loading branch information
MocicaRazvan and GabrielMajeri authored Jan 16, 2024
1 parent 2ab4fc2 commit 42e10b3
Show file tree
Hide file tree
Showing 7 changed files with 275 additions and 121 deletions.
3 changes: 3 additions & 0 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ NEXTAUTH_URL=http://localhost:3000

# Configure a secret key for encrypting session tokens
NEXTAUTH_SECRET=dev

# Connection string for Prisma
DATABASE_URL="postgresql://taxes_app:dev_pwd@localhost:5432/taxes?schema=public"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*

# root env file
.env

# local env files
.env*.local

Expand Down
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,49 @@ This app enables the online payment of admission/accomodation/study taxes at the

## Development instructions

### Dependencies

You need to have the latest stable versions of [Node.js](https://nodejs.org/en) and [npm](https://www.npmjs.com/) installed.

If it is the first time you're running the app, you will have to install all of the required package dependencies by running `npm install` in the root directory.

### Database setup

The app requires a [PostgreSQL](https://www.postgresql.org/) database to be available. The easiest way to spin up one locally is by installing [Docker](https://www.docker.com/) and then running:

```bash
docker compose up
```

in this directory.
[Prisma](https://www.prisma.io/) is our chosen [ORM](https://en.wikipedia.org/wiki/Object%E2%80%93relational_mapping). Some useful commands:

- To use the Prisma CLI with the development database:

```bash
npm run prisma
```

- To initialize the database, or to push changes without creating a migration:

```bash
npm run prisma:push
```

- To synchronize the database and create a migration:

```bash
npm run prisma:migrate --name "migration name"
```

- To generate or update the Prisma client:

```bash
npm run prisma:generate
```

This step is required after every schema change, because the Prisma client is dynamically generated and stored in a subdirectory of the `node_modules` folder, which is not commited into version control.

### Authentification config

The app uses [NextAuth.js](https://next-auth.js.org/) to provide support for authentication using [Microsoft Entra ID (formerly Azure AD)](https://www.microsoft.com/en-us/security/business/identity-access/microsoft-entra-id). In development, you have to create a `.env.local` file in the root directory and define the following environment variables:

Expand All @@ -33,6 +65,8 @@ AZURE_AD_CLIENT_ID=<client ID of app registration>
AZURE_AD_CLIENT_SECRET<client secret created for app>
```

### Useful development commands

To start a local development server, use:

```bash
Expand Down
236 changes: 117 additions & 119 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 42e10b3

Please sign in to comment.