code for NestJS Fundamentals Course
yarn global add @nestjs/cli
nest new ilovecoffee -p yarn
run
nest g class coffees/dto/update-coffee.dto --flat --no-spec
with --flat
to avoid folder creation of update-coffee.dto
docker-compose up -d
If ports not available
:
Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:5432 -> 0.0.0.0:0: listen tcp 0.0.0.0:5432: bind: An attempt was made to access a socket in a way forbidden by its access permissions.
try: run net stop winnat
by Administrator
.
\dt
example output:
postgres=# \dt
List of relations
Schema | Name | Type | Owner
--------+-----------------------+-------+----------
public | coffee | table | postgres
public | coffee_flavors_flavor | table | postgres
public | flavor | table | postgres
public | migration | table | postgres
(4 rows)
\d+ coffee
\d+ migration
select * from coffee;
select * from migration;
add
"typeorm": "ts-node ./node_modules/typeorm/cli"
to package.json
's scripts
.
yarn run typeorm migration:create src/migrations/CoffeeRefactor
run yarn run build
to generate dist
yarn run typeorm migration:run -d ./ormconfig.ts
will add a record to table migration
yarn run typeorm migration:revert -d ./ormconfig.ts
will clear table migration
yarn run typeorm migration:generate src/migrations/SchemaSync -d ./ormconfig.ts
# because I set `migrations: ['dist/src/migrations/*.js'],` in `ormconfig.ts`
# must build before migrate
yarn run build
yarn run typeorm migration:run -d ./ormconfig.ts