Skip to content

olicassis/crud_exercise

Repository files navigation

CRUD exercise

This repository documents a CRUD exercise performed as part of a training to learn about some back-end development technologies. A sketch of this exercise can be found in this google document.

Dependencies

. Node

. Fastify

. Fastify/postgres

. Fastify/jwt

. Fastify/plugin

. Fastify/autoload

. Fastify/cli

. pg

. Dotenv

. Knex

For more information, please, see the package.json file.

Run npm install to install the dependencies within this project.

Useful commands

Docker related commands

. To run the docker compose file and start its services and volumes:

~$ docker-compose -f docker-compose.yml up

. To down the services and volumes in the docker compose file:

~$ docker-compose -f docker-compose.yml down

. To remove all docker volumes:

~$ docker volume rm $(docker volume ls -qf dangling=true)

. To acces a bash terminal to execute commands over the database configured for this exercise:

~$ docker exec -it crud_exercise-db-1 /bin/bash

Database related commands

. To acces the database terminal of the db configured for this exercise:

~$ psql order postgres

. To remove all the databases created:

~$ drop schema public cascade;

. To create the public schema:

~$ create schema public;

OBS: The last two commands in this section are not recommended and were used just to quickly correct some newbie errors.

Knex related commands

. To create a migration based on a knexfile:

~$ knex --env <env_name> --knexfile knexfile.js migrate:make <migration_name>

Below, the command executed to create a migration for the creation of the user table in the database:

~$ knex --env dockerLocal --knexfile knexfile.js migrate:make create_user_table

. To execute all migrations (migrations already executed will not be executed twice):

~$ knex --env <env_name> --knexfile knexfile.js migrate:latest

Nodemon installation

Install nodemon globally:

~$ npm install nodemon -g

References

Docker compose (postgres case)

  1. Geshan
  2. Hub Docker

OBS: use postgres full image (alpine version does not create database on docker compose up).

Fastify

  1. Fastify official documentation

  2. Fastify REST API

Knex

  1. Knex official guide

  2. Migration CLI

Postgres

  1. Postgres official reference

  2. Fastify + Postgres

To install nvm and node

  1. NVM github

Auth (jwt token)

  1. Jwt authentication with Fastfy (simplified)

  2. JWT official

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published