self defined value tables
This commit is contained in:
parent
6286add31c
commit
c85f23ed73
8 changed files with 382 additions and 3 deletions
|
@ -7,14 +7,21 @@ import { user } from "./entity/user";
|
|||
import { refresh } from "./entity/refresh";
|
||||
import { invite } from "./entity/invite";
|
||||
import { userPermission } from "./entity/user_permission";
|
||||
import { role } from "./entity/role";
|
||||
import { rolePermission } from "./entity/role_permission";
|
||||
import { award } from "./entity/award";
|
||||
import { communication } from "./entity/communication";
|
||||
import { communicationType } from "./entity/communicationType";
|
||||
import { executivePosition } from "./entity/executivePosition";
|
||||
import { membershipStatus } from "./entity/membershipStatus";
|
||||
import { qualification } from "./entity/qualification";
|
||||
|
||||
import { Initial1724317398939 } from "./migrations/1724317398939-initial";
|
||||
import { RefreshPrimaryChange1724573307851 } from "./migrations/1724573307851-refreshPrimaryChange";
|
||||
import { Invite1724579024939 } from "./migrations/1724579024939-invite";
|
||||
import { Permissions1724661484664 } from "./migrations/1724661484664-permissions";
|
||||
import { role } from "./entity/role";
|
||||
import { rolePermission } from "./entity/role_permission";
|
||||
import { RolePermission1724771491085 } from "./migrations/1724771491085-role_permission";
|
||||
import { MemberBaseData1725435669492 } from "./migrations/1725435669492-member_base_data";
|
||||
|
||||
const dataSource = new DataSource({
|
||||
type: DB_TYPE as any,
|
||||
|
@ -26,13 +33,27 @@ const dataSource = new DataSource({
|
|||
synchronize: false,
|
||||
logging: process.env.NODE_ENV ? true : ["schema", "error", "warn", "log", "migration"],
|
||||
bigNumberStrings: false,
|
||||
entities: [user, refresh, invite, userPermission, role, rolePermission],
|
||||
entities: [
|
||||
user,
|
||||
refresh,
|
||||
invite,
|
||||
userPermission,
|
||||
role,
|
||||
rolePermission,
|
||||
award,
|
||||
communication,
|
||||
communicationType,
|
||||
executivePosition,
|
||||
membershipStatus,
|
||||
qualification,
|
||||
],
|
||||
migrations: [
|
||||
Initial1724317398939,
|
||||
RefreshPrimaryChange1724573307851,
|
||||
Invite1724579024939,
|
||||
Permissions1724661484664,
|
||||
RolePermission1724771491085,
|
||||
MemberBaseData1725435669492,
|
||||
],
|
||||
migrationsRun: true,
|
||||
migrationsTransactionMode: "each",
|
||||
|
|
16
src/entity/award.ts
Normal file
16
src/entity/award.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
import { Column, Entity, OneToMany, PrimaryColumn } from "typeorm";
|
||||
//import { memberAwards } from "./memberAwards";
|
||||
|
||||
@Entity()
|
||||
export class award {
|
||||
@PrimaryColumn({ generated: "increment", type: "int" })
|
||||
id: number;
|
||||
|
||||
@Column({ type: "varchar", length: 255 })
|
||||
award: string;
|
||||
|
||||
// @OneToMany(() => memberAwards, (member) => member.award, {
|
||||
// onDelete: "RESTRICT",
|
||||
// })
|
||||
// members: memberAwards[];
|
||||
}
|
40
src/entity/communication.ts
Normal file
40
src/entity/communication.ts
Normal file
|
@ -0,0 +1,40 @@
|
|||
import { Column, Entity, JoinColumn, ManyToOne, PrimaryColumn } from "typeorm";
|
||||
//import { member } from "./member";
|
||||
import { communicationType } from "./communicationType";
|
||||
|
||||
@Entity()
|
||||
export class communication {
|
||||
@PrimaryColumn({ generated: "increment", type: "int" })
|
||||
id: number;
|
||||
|
||||
@Column({ type: "boolean", default: false })
|
||||
preffered: boolean;
|
||||
|
||||
@Column({ type: "varchar", length: 255 })
|
||||
mobile: string;
|
||||
|
||||
@Column({ type: "varchar", length: 255 })
|
||||
email: string;
|
||||
|
||||
@Column({ type: "varchar", length: 255 })
|
||||
city: string;
|
||||
|
||||
@Column({ type: "varchar", length: 255 })
|
||||
street: string;
|
||||
|
||||
@Column({ type: "integer" })
|
||||
streetNumber: number;
|
||||
|
||||
@Column({ type: "varchar", length: 255 })
|
||||
streetNumberAddition: string;
|
||||
|
||||
@ManyToOne(() => communicationType, (communicationType) => communicationType.communications, {
|
||||
nullable: false,
|
||||
})
|
||||
type: communicationType;
|
||||
|
||||
// @ManyToOne(() => member, (member) => member.awards, {
|
||||
// onDelete: "RESTRICT",
|
||||
// })
|
||||
// member: member;
|
||||
}
|
31
src/entity/communicationType.ts
Normal file
31
src/entity/communicationType.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
import { Column, Entity, OneToMany, PrimaryColumn } from "typeorm";
|
||||
import { communication } from "./communication";
|
||||
|
||||
@Entity()
|
||||
export class communicationType {
|
||||
@PrimaryColumn({ generated: "increment", type: "int" })
|
||||
id: number;
|
||||
|
||||
@Column({ type: "varchar", length: 255 })
|
||||
type: string;
|
||||
|
||||
@Column({
|
||||
type: "varchar",
|
||||
length: 255,
|
||||
default: "",
|
||||
transformer: {
|
||||
from(value: string): Array<string> {
|
||||
return value.split(",");
|
||||
},
|
||||
to(value: Array<string>): string {
|
||||
return value.join(",");
|
||||
},
|
||||
},
|
||||
})
|
||||
useColumns: Array<string>;
|
||||
|
||||
@OneToMany(() => communication, (communication) => communication.type, {
|
||||
onDelete: "RESTRICT",
|
||||
})
|
||||
communications: communication[];
|
||||
}
|
16
src/entity/executivePosition.ts
Normal file
16
src/entity/executivePosition.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
import { Column, Entity, OneToMany, PrimaryColumn } from "typeorm";
|
||||
//import { memberExecutivePositions } from "./memberExecutivePositions";
|
||||
|
||||
@Entity()
|
||||
export class executivePosition {
|
||||
@PrimaryColumn({ generated: "increment", type: "int" })
|
||||
id: number;
|
||||
|
||||
@Column({ type: "varchar", length: 255 })
|
||||
position: string;
|
||||
|
||||
// @OneToMany(() => memberExecutivePositions, (memberExecutivePositions) => memberExecutivePositions.executivePosition, {
|
||||
// onDelete: "RESTRICT",
|
||||
// })
|
||||
// members: memberExecutivePositions[];
|
||||
}
|
14
src/entity/membershipStatus.ts
Normal file
14
src/entity/membershipStatus.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
import { Column, Entity, OneToMany, PrimaryColumn } from "typeorm";
|
||||
//import { membership } from "./membership";
|
||||
|
||||
@Entity()
|
||||
export class membershipStatus {
|
||||
@PrimaryColumn({ generated: "increment", type: "int" })
|
||||
id: number;
|
||||
|
||||
@Column({ type: "varchar", length: 255 })
|
||||
status: string;
|
||||
|
||||
// @OneToMany(() => membership, (membership) => membership.status)
|
||||
// memberships: membership[];
|
||||
}
|
19
src/entity/qualification.ts
Normal file
19
src/entity/qualification.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
import { Column, Entity, OneToMany, PrimaryColumn } from "typeorm";
|
||||
//import { memberQualifications } from "./memberQualifications";
|
||||
|
||||
@Entity()
|
||||
export class qualification {
|
||||
@PrimaryColumn({ generated: "increment", type: "int" })
|
||||
id: number;
|
||||
|
||||
@Column({ type: "varchar", length: 255 })
|
||||
qualification: string;
|
||||
|
||||
@Column({ type: "varchar", length: 255, nullable: true, default: null })
|
||||
description?: string;
|
||||
|
||||
// @OneToMany(() => memberQualifications, (memberQualifications) => memberQualifications.qualification, {
|
||||
// onDelete: "RESTRICT",
|
||||
// })
|
||||
// members: memberQualifications[];
|
||||
}
|
222
src/migrations/1725435669492-member_base_data.ts
Normal file
222
src/migrations/1725435669492-member_base_data.ts
Normal file
|
@ -0,0 +1,222 @@
|
|||
import { MigrationInterface, QueryRunner, Table, TableForeignKey } from "typeorm";
|
||||
|
||||
export class MemberBaseData1725435669492 implements MigrationInterface {
|
||||
name = "MemberBaseData1725435669492";
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: "award",
|
||||
columns: [
|
||||
{
|
||||
name: "id",
|
||||
type: "int",
|
||||
isPrimary: true,
|
||||
isNullable: false,
|
||||
isGenerated: true,
|
||||
generationStrategy: "increment",
|
||||
},
|
||||
{
|
||||
name: "award",
|
||||
type: "varchar",
|
||||
length: "255",
|
||||
isNullable: false,
|
||||
},
|
||||
],
|
||||
}),
|
||||
true
|
||||
);
|
||||
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: "communication_type",
|
||||
columns: [
|
||||
{
|
||||
name: "id",
|
||||
type: "int",
|
||||
isPrimary: true,
|
||||
isNullable: false,
|
||||
isGenerated: true,
|
||||
generationStrategy: "increment",
|
||||
},
|
||||
{
|
||||
name: "type",
|
||||
type: "varchar",
|
||||
length: "255",
|
||||
isNullable: false,
|
||||
},
|
||||
{
|
||||
name: "useColumns",
|
||||
type: "varchar",
|
||||
length: "255",
|
||||
isNullable: false,
|
||||
default: "''",
|
||||
},
|
||||
],
|
||||
}),
|
||||
true
|
||||
);
|
||||
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: "communication",
|
||||
columns: [
|
||||
{
|
||||
name: "id",
|
||||
type: "int",
|
||||
isPrimary: true,
|
||||
isNullable: false,
|
||||
isGenerated: true,
|
||||
generationStrategy: "increment",
|
||||
},
|
||||
{
|
||||
name: "preffered",
|
||||
type: "tinyint",
|
||||
isNullable: false,
|
||||
default: 0,
|
||||
},
|
||||
{
|
||||
name: "mobile",
|
||||
type: "varchar",
|
||||
length: "255",
|
||||
isNullable: false,
|
||||
},
|
||||
{
|
||||
name: "email",
|
||||
type: "varchar",
|
||||
length: "255",
|
||||
isNullable: false,
|
||||
},
|
||||
{
|
||||
name: "city",
|
||||
type: "varchar",
|
||||
length: "255",
|
||||
isNullable: false,
|
||||
},
|
||||
{
|
||||
name: "street",
|
||||
type: "varchar",
|
||||
length: "255",
|
||||
isNullable: false,
|
||||
},
|
||||
{
|
||||
name: "streetNumber",
|
||||
type: "int",
|
||||
isNullable: false,
|
||||
},
|
||||
{
|
||||
name: "streetNumberAddition",
|
||||
type: "varchar",
|
||||
length: "255",
|
||||
isNullable: false,
|
||||
},
|
||||
{
|
||||
name: "typeId",
|
||||
type: "int",
|
||||
isNullable: false,
|
||||
},
|
||||
],
|
||||
}),
|
||||
true
|
||||
);
|
||||
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: "executive_position",
|
||||
columns: [
|
||||
{
|
||||
name: "id",
|
||||
type: "int",
|
||||
isPrimary: true,
|
||||
isNullable: false,
|
||||
isGenerated: true,
|
||||
generationStrategy: "increment",
|
||||
},
|
||||
{
|
||||
name: "position",
|
||||
type: "varchar",
|
||||
length: "255",
|
||||
isNullable: false,
|
||||
},
|
||||
],
|
||||
}),
|
||||
true
|
||||
);
|
||||
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: "membership_status",
|
||||
columns: [
|
||||
{
|
||||
name: "id",
|
||||
type: "int",
|
||||
isPrimary: true,
|
||||
isNullable: false,
|
||||
isGenerated: true,
|
||||
generationStrategy: "increment",
|
||||
},
|
||||
{
|
||||
name: "status",
|
||||
type: "varchar",
|
||||
length: "255",
|
||||
isNullable: false,
|
||||
},
|
||||
],
|
||||
}),
|
||||
true
|
||||
);
|
||||
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: "qualification",
|
||||
columns: [
|
||||
{
|
||||
name: "id",
|
||||
type: "int",
|
||||
isPrimary: true,
|
||||
isNullable: false,
|
||||
isGenerated: true,
|
||||
generationStrategy: "increment",
|
||||
},
|
||||
{
|
||||
name: "qualification",
|
||||
type: "varchar",
|
||||
length: "255",
|
||||
isNullable: false,
|
||||
},
|
||||
{
|
||||
name: "description",
|
||||
type: "varchar",
|
||||
length: "255",
|
||||
isNullable: true,
|
||||
default: null,
|
||||
},
|
||||
],
|
||||
}),
|
||||
true
|
||||
);
|
||||
|
||||
await queryRunner.createForeignKey(
|
||||
"communication",
|
||||
new TableForeignKey({
|
||||
columnNames: ["typeId"],
|
||||
referencedColumnNames: ["id"],
|
||||
referencedTableName: "communication_type",
|
||||
onDelete: "RESTRICT",
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
const communication = await queryRunner.getTable("communication");
|
||||
const foreignKey = communication.foreignKeys.find((fk) => fk.columnNames.indexOf("typeId") !== -1);
|
||||
await queryRunner.dropForeignKey("communication", foreignKey);
|
||||
|
||||
await queryRunner.dropTable("qualification");
|
||||
await queryRunner.dropTable("membership_status");
|
||||
await queryRunner.dropTable("executive_position");
|
||||
await queryRunner.dropTable("communication");
|
||||
await queryRunner.dropTable("communication_type");
|
||||
await queryRunner.dropTable("award");
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue