diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..c5145f65 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,41 @@ +Dockerfile +lib-cov +*.seed +*.log +*.csv +*.dat +*.out +*.pid +*.gz +*.swp + +pids +logs +results +tmp + +# Build +public/css/main.css + +# Coverage reports +coverage + + + +# Dependency directory +node_modules +bower_components + +# Editors +.idea +*.iml + +# OS metadata +.DS_Store +Thumbs.db + +# Ignore built ts files +dist + +# ignore yarn.lock +yarn.lock diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..2506134e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM node:21-alpine3.19 +WORKDIR /app +RUN apk add --no-cache git +COPY package*.json /app +COPY /.git /app/.git +RUN npm install +COPY . /app +ENV PORT=3000 +EXPOSE ${PORT} +CMD ["npm", "run", "dev"] \ No newline at end of file diff --git a/README.md b/README.md index 8b0f5be1..93ff4255 100644 --- a/README.md +++ b/README.md @@ -149,65 +149,64 @@ If setting up Swagger for the first time, follow these steps: **Note:** YAML strictly follows indentations, so ensure you follow them. -# Sequelize Usage Guide +# Sequelize Usage Guide ## Introduction + This documentation provides guidance on setting up and using Sequelize in the project. Sequelize is a promise-based Node.js ORM for PostgreSQL, MySQL, SQLite, and MSSQL databases. ## Setup -1. *Clone the Repository:* Clone the project repository to your local machine. - bash - git clone - -2. *Install Dependencies:* Install the project dependencies using npm. - bash - npm install - -3. *Run Migrations:* Execute existing migrations to create database tables. - bash - npm run migrate - + +1. _Clone the Repository:_ Clone the project repository to your local machine. + bash + git clone +2. _Install Dependencies:_ Install the project dependencies using npm. + bash + npm install +3. _Run Migrations:_ Execute existing migrations to create database tables. + bash + npm run migrate ## Usage + ### Running Migrations -- *Create Tables:* To create database tables based on existing migrations. - bash - npm run migrate - -- *Undo Changes:* If you need to rollback changes made by migrations. - bash - npm run migrate:undo - + +- _Create Tables:_ To create database tables based on existing migrations. + bash + npm run migrate +- _Undo Changes:_ If you need to rollback changes made by migrations. + bash + npm run migrate:undo ### Seeding Data -- *Seed Database:* Add initial data to the database. - bash - npm run seed - -- *Undo Seeding:* Remove seeded data from the database. - bash - npm run seed:undo - + +- _Seed Database:_ Add initial data to the database. + bash + npm run seed +- _Undo Seeding:_ Remove seeded data from the database. + bash + npm run seed:undo ### Creating Models -- *Generate Model:* Create a new model using the Sequelize CLI. - bash - npx sequelize-cli model:generate --name --attributes :,:,... - + +- _Generate Model:_ Create a new model using the Sequelize CLI. + bash + npx sequelize-cli model:generate --name --attributes :,:,... ### Generating Migrations -- *Generate Migration:* Generate a new migration file for making changes to the database schema. - bash - npx sequelize-cli migration:generate --name - + +- _Generate Migration:_ Generate a new migration file for making changes to the database schema. + bash + npx sequelize-cli migration:generate --name ### Executing Migrations -- *Run Migrations:* Execute the generated migration to apply changes to the database. - bash - npm run migrate - + +- _Run Migrations:_ Execute the generated migration to apply changes to the database. + bash + npm run migrate ## Conclusion + Sequelize simplifies database interactions in the project by providing an ORM layer. Follow the steps outlined above to set up Sequelize and manage database schema changes effectively. For more information, refer to the Sequelize documentation. ## Useful Links @@ -215,4 +214,3 @@ Sequelize simplifies database interactions in the project by providing an ORM la 1. [Pivotal Tracker's Official Documentation](https://www.pivotaltracker.com/help/articles/github_integration/#attaching-branches-to-a-story-automatically) 2. [freeCodeCamp Article on Naming Commits](https://www.freecodecamp.org/news/writing-good-commit-messages-a-practical-guide/) 3. [Medium Article on Naming Branches](https://medium.com/@abhay.pixolo/naming-conventions-for-git-chores-a-cheatsheet) - diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..74e0dafd --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,29 @@ +version: '3.9' +services: + backend: + container_name: backend + image: mavericks-backend:v1 + build: + context: . + dockerfile: Dockerfile + ports: + - '3000:3000' + environment: + - DATABASE_URL=postgresql://$DEV_DB_USER:$DEV_DB_PASSWORD@db:5432/$DEV_DB_NAME + depends_on: + - db + db: + container_name: db + image: postgres:latest + restart: always + environment: + - POSTGRES_USER=$DEV_DB_USER + - POSTGRES_PASSWORD=$DEV_DB_PASSWORD + - POSTGRES_DB=$DEV_DB_NAME + ports: + - '5432:5432' + volumes: + - db-data:/var/lib/postgresql/data + +volumes: + db-data: diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 00000000..d486907f --- /dev/null +++ b/jest.config.js @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const config = { + clearMocks: true, + collectCoverage: true, + coverageDirectory: 'coverage', + preset: 'ts-jest', + testEnvironment: 'node', +}; +exports.default = config; diff --git a/src/database/config/config.js b/src/database/config/config.js index 0da9ecde..58270bc3 100644 --- a/src/database/config/config.js +++ b/src/database/config/config.js @@ -9,6 +9,7 @@ module.exports = { dialect: process.env.DEV_DB_DRIVER, port: process.env.DEV_DB_PORT, + host: process.env.DEV_DB_HOST, }, test: { username: process.env.TEST_DB_USER,