-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
77 lines (59 loc) · 2.75 KB
/
Copy pathMakefile
File metadata and controls
77 lines (59 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
.PHONY: dev-up dev-down stage-up stage-down prod-up prod-down down-test clean logs makemigrations migrate seed test lint typecheck build
DEV_COMPOSE = docker compose -f docker-compose.yml -f docker-compose.dev.yml
STAGE_COMPOSE = docker compose -f docker-compose.yml -f docker-compose.stage.yml
PROD_COMPOSE = docker compose -f docker-compose.yml -f docker-compose.prod.yml
# Own project name + port keep this fully isolated from the dev stack — safe to run even
# while `make dev-up` is up. See docker-compose.test.yml for why the port comes from an env var.
TEST_COMPOSE = POSTGRES_HOST_PORT=5434 docker compose -p node-express-boilerplate-test -f docker-compose.yml -f docker-compose.test.yml
TEST_DATABASE_URL = postgresql://postgres:postgres@localhost:5434/app_test?schema=public
## Bring up the full stack (app + Postgres) with hot reload.
dev-up:
$(DEV_COMPOSE) up --build
## Bring up the immutable runtime image against .env.staging, detached.
stage-up:
$(STAGE_COMPOSE) up --build -d
## Bring up the immutable runtime image against .env.production, detached.
prod-up:
$(PROD_COMPOSE) up --build -d
dev-down:
$(DEV_COMPOSE) down
stage-down:
$(STAGE_COMPOSE) down
prod-down:
$(PROD_COMPOSE) down
## Destructive — also drops volumes (Postgres data). Separate from `dev-down` on purpose.
clean:
$(DEV_COMPOSE) down -v
logs:
$(DEV_COMPOSE) logs -f app
## Dev-only: diffs schema.prisma against the dev database, writes new migration file(s)
## under prisma/migrations, and applies them. Always targets .env.development — stage/prod
## never generate migrations, they only run `make migrate` against already-committed ones.
## Pass a name to skip the interactive prompt, e.g. `make makemigrations NAME=add_foo`.
makemigrations:
NODE_ENV=development npx prisma migrate dev $(if $(NAME),--name $(NAME))
## NODE_ENV picks which .env.<ENV> prisma.config.ts loads, e.g. `make migrate ENV=staging`.
## Applies migrations that already exist under prisma/migrations — never creates new ones.
ENV ?= development
migrate:
NODE_ENV=$(ENV) npx prisma migrate deploy
## Seeds demo data (admin + 20 users, 40 items, 150 orders) into the target database.
## e.g. `make seed ENV=staging` to seed a different environment.
seed:
NODE_ENV=$(ENV) npm run prisma:seed
## Brings up an isolated test Postgres (own project, port, and volume — never touches the
## dev database or seeded data), applies migrations, runs the suite on the host, tears down.
test:
$(TEST_COMPOSE) up -d --wait postgres
DATABASE_URL=$(TEST_DATABASE_URL) npx prisma migrate deploy
npm run test
$(TEST_COMPOSE) down
## Recovery target if a `make test` run gets interrupted before tearing itself down.
down-test:
$(TEST_COMPOSE) down
lint:
npm run lint
typecheck:
npm run typecheck
build:
npm run build