- Next.js
- TypeScript
- Next.js 9+ API Routes
- Slonik (with PostgreSQL)
- @slonik/migrator for database migrations
You'll need PostgreSQL for this.
Copy the .env.example
file to a new file called .env
and fill in the values described in the following table.
This user and database will be created by the migrations, and will be used by the Next.js application. The user will be given limited access only to the database specified:
Variable | Description |
---|---|
PGHOST |
Name of the host to connect to - often localhost |
PGUSER |
Database user |
PGPASSWORD |
Password for the database user |
PGDATABASE |
Database that the user has access to |
In order to create this user and database, we will also need the ADMIN
variables, which are PostgreSQL admin connection details.
The migrations that have been written using @slonik/migrator can be run using the following command:
node migrate up
To roll back the changes in the migrations, run the following command:
node migrate down
The @slonik/migrator tool can be used to create new migrations as well.
For example, to create a new migration called todo
(for example, to create a database table called todo
):
node migrate create todo