Set up a database management system for our golang project using GORM. The task includes configuring the database connection, creating entity classes, and seeding the database with initial data. This setup will help streamline data operations and ensure application can interact with the database efficiently.
Tasks
Database Configuration
Configure the application to connect to a PostgreSQL database using gorm.
Allow the setup to be flexible for configuring any database.
Create app.env and add appropriate database credentials (USERNAME, PASSWORD, DB_NAME)
Change MIGRATE in app.env to true
Entity Classes
Create table structs for User, Profile, Organisation, and Product.
Define relationships between entities:
A user has one profile (https://github.com/OnetoOne).
A user has many products (@OneToMany).
A user belongs to many organisations (@manytomany).
An organisation has many users (@manytomany).
Seeding the Database
Create a data seeding component to initialize the database with sample data.
Ensure the seeding process runs only once during application startup.
Seed the database with the following data:
At least 2 users.
At least 2 products per user.
At least 3 organisations.
User one belongs to 2 of the organisations.
User two belongs to all 3 organisations.
Validation Steps
Ensure the following tables and constraints are created:
Description
Set up a database management system for our golang project using GORM. The task includes configuring the database connection, creating entity classes, and seeding the database with initial data. This setup will help streamline data operations and ensure application can interact with the database efficiently.
Tasks
Database Configuration
Configure the application to connect to a PostgreSQL database using gorm.
Allow the setup to be flexible for configuring any database.
Create app.env and add appropriate database credentials (USERNAME, PASSWORD, DB_NAME)
Change MIGRATE in app.env to true
Entity Classes
Create table structs for User, Profile, Organisation, and Product.
Define relationships between entities:
A user has one profile (https://github.com/OnetoOne). A user has many products (@OneToMany). A user belongs to many organisations (@manytomany). An organisation has many users (@manytomany).
Seeding the Database
Create a data seeding component to initialize the database with sample data.
Ensure the seeding process runs only once during application startup.
Seed the database with the following data:
Validation Steps
Api Endoint
Testing
Acceptance Criteria: