-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Database Setup and Seed Migration #23
Database Setup and Seed Migration #23
Conversation
src/data-source.ts
Outdated
username: config.DB_USER, | ||
password: config.DB_PASSWORD, | ||
database: config.DB_NAME, | ||
synchronize: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong. Set sychronize:false
. We only use Migrations
for updating schema.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated @NdubuisiJr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't push .env
Remove it from git using git rm --cached .env
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The task's specified that you should use migrations, models, service pattern.
The controller shouldn't access data directly from the model. The service can access the model directly while the controller accesses the model through the service.
@nedssoft @NdubuisiJr all changes has been made |
This is fixed; Also, we need it working, so that the devOps engineers can make necessary changes with the deployment
Description
This PR sets up the database schema, configures TypeORM, and adds initial seed data for testing. The following changes were made:
Entities Setup
User
,Profile
,Product
, andOrganization
entities with proper relationships.Migration
Endpoints
Changes
Entity Changes
User.ts
to include@JoinColumn
for@OneToOne
relationship withProfile
.@OneToMany
and@ManyToMany
relationships with appropriate join columns.Endpoints
GET /api/v1/users
to fetch all users.GET /api/v1/users/:id
to fetch a user by ID with their profile, products, and organizations.How to Test
Clone the Repository
git clone (https://github.com/hngprojects/hng_boilerplate_expressjs) cd hng_boilerplate_expressjs
Install Dependencies
Configure Environment Variables
Ensure your
.env
file has the correct database configuration:port=8000
auth-secret=
DB_USER=
DB_HOST=
DB_PASSWORD=
DB_NAME=
Test Endpoints
Get All Users
Get User by ID
Replace
{user_id}
with a valid user ID from the seeded data.Verify Response
Ensure the response contains the expected user data, including profile, products, and organizations.
Notes
By following these steps, you can verify the database setup, seed data, and endpoints are working correctly.