Marioandres717 / creation-mono

Home Page:https://billeteradb.herokuapp.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wallet

Quick-Start Guide

Prerequisites

  1. Install Docker at your local machine.

Installation

  1. Clone repo and install
git clone git@github.com:Marioandres717/creation-mono.git

cd creation-mono
npm install
  1. Create .env file at the root directory (check .env.file.example for guidance)
# Database
# [protocol]://[user]:[password]@[host]:[port]/[database]
DATABASE_URL=mysql://root:asd123@localhost:3306/walletdb
TOKEN_DURATION=86400000

# Frontend
NX_GRAPHQL_URI=http://localhost:3000/graphql

  1. Create constants.ts file in apps/backend/src/app/auth/constants.ts

    export const jwtConstants = {
      secret: 'secretKey',
    };
  2. Prepare the database

    1. Turn db container on: Known Issues: Errors due to corrupted data:
      (CAUTION): remove tmp folder.
      This command removes the database data. This error may be due to the change from mysql to mariadb, so it is probably safe to run the following command because such an error is only triggered in the early stages of development.

      rm -rf tmp
      
      docker-compose up db
      
    2. Push initial schema to db and verify database

      npx nx run shared-models:db-push
      
      ### Optional ###
      
      docker exec -it db /bin/sh
      mysql -u root -p
      
      # Enter database password
      
      show databases;
      
    3. Generate prisma client

      npx nx run shared-models:gen-client
      
  3. Generate types based on Schema

    npm run update-all
    
  4. Build docker containers

    cd creation-mono
    docker-compose build
    
  5. Run Docker compose

docker-compose up
  1. Open localhost:3000/graphql and create a new user
mutation createUser {
insert_User(User: {
   id: 0,
   email:  "test@tech.ca",
   password: "test12",
   username: "testuser",
   active: 1
}
){
   id,
   email,
   username,
   active
}
}
  1. Log in using the new created user at localhost:4200

Docker

A list of useful docker compose-commands

# containers status
docker-compose ps
# run application
docker-compose up
# shut down application
docker-compose down
# restart container
# docker-compose restart wallet
# you can get the name from docker-compose.yml file
docker-compose restart <compose container name>
# build application based on Dockerfile
docker-compose build
# build single container
docker-compose build <compose container name>
# running bash in container
# this command will run an isolated container
# changes here won't affect the container running
# with docker-compose up in case its available
docker-compose build <compose container> bash
# General docker commands
# docker image list
docker [image|container|volume] [list]

Update node_modules from whitin a container

Useful steps to update the node_modules for a docker image to avoid rebuilding the entire project.

  1. run docker ps and get wallet container id

  2. docker exec -it [container-id] bash
    
    npm install
    
    exit
    
  3. Outside the container

    # container that changes -> image to commit the changes
    docker commit [container-id] wallet:latest
    
  4. run docker-compose restart

MySQL Workbench

  1. SSL required: this needs to be done every time :(

    add useSSL=1 to edit conection / advanced / others
    
    

About

https://billeteradb.herokuapp.com/


Languages

Language:TypeScript 84.8%Language:CSS 13.2%Language:JavaScript 1.3%Language:Shell 0.3%Language:HTML 0.2%Language:Dockerfile 0.2%Language:Procfile 0.0%