Skip to content
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

Merged
merged 16 commits into from
Jul 20, 2024

Conversation

incredible-phoenix246
Copy link
Contributor

Description

This PR sets up the database schema, configures TypeORM, and adds initial seed data for testing. The following changes were made:

  1. Entities Setup

    • Created User, Profile, Product, and Organization entities with proper relationships.
  2. Migration

    • Added migration to drop existing schema and recreate it.
    • Created seed migration to insert initial data into the database.
  3. Endpoints

    • Implemented endpoints to fetch user data, including their profile, products, and organizations.

Changes

  1. Entity Changes

    • Updated User.ts to include @JoinColumn for @OneToOne relationship with Profile.
    • Ensured proper use of @OneToMany and @ManyToMany relationships with appropriate join columns.
  2. Endpoints

    • Implemented GET /api/v1/users to fetch all users.
    • Implemented GET /api/v1/users/:id to fetch a user by ID with their profile, products, and organizations.

How to Test

  1. Clone the Repository

    git clone (https://github.com/hngprojects/hng_boilerplate_expressjs)
    cd hng_boilerplate_expressjs
  2. Install Dependencies

    yarn install
  3. Configure Environment Variables
    Ensure your .env file has the correct database configuration:

port=8000
auth-secret=
DB_USER=
DB_HOST=
DB_PASSWORD=
DB_NAME=



4. **Start the Server**
```bash
yarn start:dev
  1. Test Endpoints

    • Get All Users

      curl http://localhost:8000/api/v1/users
    • Get User by ID
      Replace {user_id} with a valid user ID from the seeded data.

      curl http://localhost:8000/api/v1/users/{user_id}
  2. Verify Response
    Ensure the response contains the expected user data, including profile, products, and organizations.

Notes

  • Ensure the PostgreSQL server is running and accessible with the provided credentials.
  • The database schema and initial data will be recreated, so any existing data will be lost.

By following these steps, you can verify the database setup, seed data, and endpoints are working correctly.

@incredible-phoenix246 incredible-phoenix246 self-assigned this Jul 19, 2024
@incredible-phoenix246 incredible-phoenix246 added the feature new feature label Jul 19, 2024
@incredible-phoenix246 incredible-phoenix246 linked an issue Jul 19, 2024 that may be closed by this pull request
username: config.DB_USER,
password: config.DB_PASSWORD,
database: config.DB_NAME,
synchronize: true,
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated @NdubuisiJr

Copy link
Contributor

@Idimmusix Idimmusix left a 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

Copy link

@nedssoft nedssoft left a 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.

@incredible-phoenix246
Copy link
Contributor Author

@nedssoft @NdubuisiJr all changes has been made

@Idimmusix Idimmusix dismissed stale reviews from nedssoft and NdubuisiJr July 20, 2024 11:27

This is fixed; Also, we need it working, so that the devOps engineers can make necessary changes with the deployment

@Idimmusix Idimmusix merged commit 63adced into hngprojects:dev Jul 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEAT] Database Setup - Models, and Seeding
4 participants