This is a blog app backend built with Nest.js, GraphQL and Postgres with TypeORM.
You must have the following installed on your machine:
- Node.js (v20.12.2)
- npm (v10.7.0)
- Docker Desktop (including Docker Compose)
npm install
To create a user with the role of admin
, you need to run seed script. If you want to run it yourself, you can follow the instructions.
💥 Otherwise, when you start the development server, the migrations and seed scripts will run automatically as defined in docker-compose.yml
file.
💥 Make sure you have populated .env.migrations
file with the necessary environment variables. You can use the .env.migrations.example
file as a template.
# Copy the .env.migrations.example file to .env.migrations
cp .env.migrations.example .env.migrations
💥 For running the migrations and seed scripts, you need to have a Postgres instance running. You can use the following command to run a Postgres instance using Docker Compose.
# Before starting the migration:
npm run docker:start:migrations
# Create a new migration
npm run typeorm:migration:create <migration-name>
# Generate a new migration based on changes in entities
npm run typeorm:migration:generate <migration-name>
# Run migrations
npm run typeorm:migration:run
# Rollback migrations
npm run typeorm:migration:revert
# Show all migrations
npm run typeorm:migration:show
# Drop everything in DB
npm run typeorm:schema:drop
# Typeorm CLI with ts-node
npm run typeorm:cli
# Run all seed scripts in ./seeds directory
npm run typeorm:seed
# Run a specific seed script by name
npm run typeorm:seed -- --name ./seeds/create-admin.seed.ts
# After running the migration:
npm run docker:stop:migrations
💥 Make sure you have populated the .env
file with the necessary environment variables. You can use the .env.example
file as a template.
# Copy the .env.example file to .env
cp .env.example .env
💥 Make sure to run the migrations if you are running the project for the first time. You will have to re-run the migrations whenever there are changes to entities.
# start development server
npm run docker:start:dev
# stop development server
npm run docker:stop:dev
# see logs
docker logs <container-name> -f