This document guides you through setting up the database for the API. It assumes that you have MySQL installed on your system.
The API uses two tables: products
and sales
. Below is the database schema:
The API requires specific environment variables to run correctly. You can find the required structure in the .env.example
file.
To create the .env
file, follow these steps:
-
Navigate to the root directory of the project:
cd <project_directory>
-
Copy the
.env.example
file to.env
:cp .env.example .env
-
Open the
.env
file in your preferred text editor (e.g.,nano
):nano .env
-
Modify the values as needed and save the changes.
To set up the database with the necessary structure, you need to have Node.js and Sequelize installed. Follow the steps below to install the required dependencies and create the tables:
-
Install dependencies:
Navigate to the API directory and run the following command to install all required dependencies, including Sequelize:npm install
-
Set up the database:
Once the dependencies are installed, simply run the Node application. Sequelize will automatically create all the necessary tables. Run the following command from the API directory:This assumes you already have an empty database ready and a
.env
file with the required information.node app.js
This process will set up your database structure with Sequelize.
- The
createdAt
andupdatedAt
fields are managed automatically using MySQL’s timestamp functionality.