Design and implement a structured database schema for managing user data in a Nest.js application using TypeORM. Include functionality to seed initial user data and ensure the database setup supports easy configuration switching and migration management.
Acceptance Criteria
The User table is successfully created in PostgreSQL using Nest.js and TypeORM.
Initial user data is seeded into the database.
Migrations are written and successfully applied to update the database schema.
Comprehensive documentation is provided for setup, configuration, and maintenance of the database schema, migrations, and seeding process within a Nest.js application.
Requirements:
1. Database Schema Design:
Create a User table schema with the following fields
id: Primary key, auto-incremented integer.
username: Unique username of the user.
email: Unique email address of the user.
password: Hashed password of the user.
createdAt: Timestamp indicating when the user record was created.
updatedAt: Timestamp indicating when the user record was last updated.
Column Name
Data Type
Constraints
id UUID
Primary Key
Default: UUID Generate
username
VAR(50)
Unique, Not Null
email
VAR(20)
Unique, Not Null
password
VAR(50)
Not Null
firstName
VAR(50)
Not Null
lastName
VAR(50)
Not Null
createdAt
TIMESTAMP
Default: Current Timestamp
updatedAt
TIMESTAMP
Default: Current Timestamp, On Update
Create a Organisations table schema with the following fields
id: Primary key, auto-incremented integer.
name: Unique name of the organisation.
email: Unique email address of the organisation.
description: Description of the organisation.
industry: Industry of organisation.
type: Type of organisation.
address: Address of the organisation.
country: Country of residence of the organisation.
state: State of residence of the organisation.
createdAt: Timestamp indicating when the organisation record was created.
updatedAt: Timestamp indicating when the organisation record was last updated.
Column Name
Data Type
Constraints
id UUID
Primary Key
Default: UUID Generate
name
VAR(255)
Unique, Not Null
email
VAR(20)
Unique, Not Null
description
VAR(50)
Null
industry
VAR(50)
Not Null
type
VAR(50)
Not Null
country
VAR(50)
Null
state
VAR(50)
Null
address
VAR(50)
Null
createdAt
TIMESTAMP
Default: Current Timestamp
updatedAt
TIMESTAMP
Default: Current Timestamp, On Update
Create a Products table schema with the following fields
id: Primary key, auto-incremented integer.
product_name: Unique name of the product.
description: Description of the product.
price: Price of the product.
categoryId: Foreign key pointing to the category of the product.
createdAt: Timestamp indicating when the product record was created.
updatedAt: Timestamp indicating when the product record was last updated.
Column Name
Data Type
Constraints
id
UUID
Primary Key, Default: UUID Generate
name
VAR(255)
Unique, Not Null
description
VAR(20)
Unique, Not Null
price
VAR(50)
Null
categoryId
VAR(50)
Foreign Key, Default: UUID Generate
createdAt
TIMESTAMP
Default: Current Timestamp
updatedAt
TIMESTAMP
Default: Current Timestamp, On Update
2. Nest.js and TypeORM Setup:
Integrate Nest.js with TypeORM for seamless database connectivity.
Configure Nest.js application to connect to PostgreSQL.
Description:
Design and implement a structured database schema for managing user data in a Nest.js application using TypeORM. Include functionality to seed initial user data and ensure the database setup supports easy configuration switching and migration management.
Acceptance Criteria
Requirements:
1. Database Schema Design:
User
table schema with the following fieldsid
: Primary key, auto-incremented integer.username
: Unique username of the user.email
: Unique email address of the user.password
: Hashed password of the user.createdAt
: Timestamp indicating when the user record was created.updatedAt
: Timestamp indicating when the user record was last updated.id
UUIDusername
email
password
firstName
lastName
createdAt
updatedAt
Organisations
table schema with the following fieldsid
: Primary key, auto-incremented integer.name
: Unique name of the organisation.email
: Unique email address of the organisation.description
: Description of the organisation.industry
: Industry of organisation.type
: Type of organisation.address
: Address of the organisation.country
: Country of residence of the organisation.state
: State of residence of the organisation.createdAt
: Timestamp indicating when the organisation record was created.updatedAt
: Timestamp indicating when the organisation record was last updated.id
UUIDname
email
description
industry
type
country
state
address
createdAt
updatedAt
Products
table schema with the following fieldsid
: Primary key, auto-incremented integer.product_name
: Unique name of the product.description
: Description of the product.price
: Price of the product.categoryId
: Foreign key pointing to the category of the product.createdAt
: Timestamp indicating when the product record was created.updatedAt
: Timestamp indicating when the product record was last updated.id
name
description
price
categoryId
createdAt
updatedAt
2. Nest.js and TypeORM Setup:
Database Configuration Data
3. Seeding Initial Data:
User
table.Seeding Script
4. Migration Strategy:
User
table schema and handle future schema.5. Environment Flexibility:
6. Testing and Documentation:
6. Additional Considerations:
7. Dependencies:
References: