-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
155 additions
and
31 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
const rawSQL = ` | ||
CREATE TABLE IF NOT EXISTS users( | ||
id VARCHAR (100) PRIMARY KEY, | ||
email VARCHAR (100) NOT NULL, | ||
first_name VARCHAR (50) NOT NULL, | ||
last_name VARCHAR (50) NOT NULL, | ||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), | ||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), | ||
is_verified BOOLEAN NOT NULL DEFAULT FALSE | ||
); | ||
CREATE TABLE IF NOT EXISTS groups( | ||
id SERIAL PRIMARY KEY, | ||
name VARCHAR(50), | ||
description VARCHAR(100), | ||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), | ||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() | ||
); | ||
CREATE TABLE IF NOT EXISTS roles( | ||
id SERIAL PRIMARY KEY, | ||
name VARCHAR(50), | ||
description VARCHAR(100), | ||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), | ||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() | ||
); | ||
CREATE TABLE IF NOT EXISTS user_group( | ||
user_id VARCHAR(100) REFERENCES users(id), | ||
group_id INT REFERENCES groups(id) | ||
); | ||
CREATE TABLE IF NOT EXISTS group_role( | ||
group_id INT REFERENCES groups(id), | ||
role_id INT REFERENCES roles(id) | ||
); | ||
`; | ||
|
||
export class InitialTables1729468099287 implements MigrationInterface { | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
return queryRunner.query(rawSQL); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
return queryRunner.query(` | ||
DROP table group_role; | ||
DROP table user_group; | ||
DROP table users; | ||
DROP table groups; | ||
DROP table roles; | ||
`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
INSERT INTO groups (name, description) VALUES | ||
('Admin', 'Administrative group with full system access'), | ||
('Supply Chain Manager', 'Manages the supply chain operations'), | ||
('Warehouse Operator', 'Responsible for warehouse operations and stock control'), | ||
('Procurement Officer', 'Handles purchasing and procurement of goods and services'), | ||
('Logistics Coordinator', 'Coordinates transportation and logistics operations'); | ||
|
||
INSERT INTO users (id, email, first_name, last_name, created_at, updated_at, is_verified) VALUES | ||
('user_001', '[email protected]','John', 'Doe', NOW(), NOW(), TRUE), | ||
('user_002', '[email protected]','Jane', 'Smith', NOW(), NOW(), FALSE), | ||
('user_003', '[email protected]','Alice', 'Johnson', NOW(), NOW(), TRUE), | ||
('user_004', '[email protected]','Bob', 'Brown', NOW(), NOW(), FALSE), | ||
('user_005', '[email protected]','Charlie', 'Davis', NOW(), NOW(), TRUE); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,4 @@ export class CreateUserDto { | |
email: string; | ||
firstName: string; | ||
lastName: string; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Column, Entity, JoinColumn, JoinTable, ManyToMany, PrimaryColumn } from 'typeorm'; | ||
import { User } from './user.entity'; | ||
|
||
@Entity('groups') | ||
export class Group { | ||
@PrimaryColumn() | ||
id: string; | ||
|
||
@Column() | ||
name: string; | ||
|
||
@Column() | ||
description: string; | ||
|
||
@Column({ name: 'created_at' }) | ||
createdAt: Date; | ||
|
||
@Column({ name: 'updated_at' }) | ||
updatedAt: Date; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Column, Entity, PrimaryColumn } from 'typeorm'; | ||
|
||
@Entity('roles') | ||
export class User { | ||
@PrimaryColumn() | ||
id: string; | ||
|
||
@Column() | ||
name: string; | ||
|
||
@Column() | ||
description: string; | ||
|
||
@Column({ name: 'created_at' }) | ||
createdAt: Date; | ||
|
||
@Column({ name: 'updated_at' }) | ||
updatedAt: Date; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Column, Entity, PrimaryColumn } from 'typeorm'; | ||
|
||
@Entity('user_group') | ||
export class UserGroup { | ||
@Column({name: "user_id"}) | ||
user_id: string; | ||
|
||
@Column() | ||
group_id: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters