diff --git a/src/entity/communication.ts b/src/entity/communication.ts index 527b685..02c060f 100644 --- a/src/entity/communication.ts +++ b/src/entity/communication.ts @@ -8,7 +8,7 @@ export class communication { id: number; @Column({ type: "boolean", default: false }) - preffered: boolean; + preferred: boolean; @Column({ type: "varchar", length: 255 }) mobile: string; diff --git a/src/entity/member.ts b/src/entity/member.ts index 855b54d..4ca41b4 100644 --- a/src/entity/member.ts +++ b/src/entity/member.ts @@ -11,7 +11,19 @@ export class member { @PrimaryColumn({ generated: "increment", type: "int" }) id: number; - @Column({ type: "enum", enum: Salutation, default: Salutation.none }) + @Column({ + type: "varchar", + length: "255", + default: Salutation.none.toString(), + transformer: { + to(value: Salutation) { + return value.toString(); + }, + from(value: string) { + return Salutation[value as keyof typeof Salutation]; + }, + }, + }) salutation: Salutation; @Column({ type: "varchar", length: 255 }) diff --git a/src/env.defaults.ts b/src/env.defaults.ts index 82f5b75..459baa6 100644 --- a/src/env.defaults.ts +++ b/src/env.defaults.ts @@ -22,7 +22,7 @@ export const MAIL_SECURE = process.env.MAIL_SECURE ?? "false"; export const CLUB_NAME = process.env.CLUB_NAME ?? ""; export function configCheck() { - if (DB_TYPE == "" ?? typeof DB_TYPE != "string") throw new Error("set valid value to DB_TYPE"); + if (DB_TYPE != "mysql" && DB_TYPE != "sqlite") throw new Error("set valid value to DB_TYPE (mysql|sqlite)"); if (DB_HOST == "" ?? typeof DB_HOST != "string") throw new Error("set valid value to DB_HOST"); if (DB_NAME == "" ?? typeof DB_NAME != "string") throw new Error("set valid value to DB_NAME"); if (DB_USERNAME == "" ?? typeof DB_USERNAME != "string") throw new Error("set valid value to DB_USERNAME"); diff --git a/src/migrations/1724317398939-initial.ts b/src/migrations/1724317398939-initial.ts index 437d5b3..bbce107 100644 --- a/src/migrations/1724317398939-initial.ts +++ b/src/migrations/1724317398939-initial.ts @@ -1,14 +1,17 @@ import { MigrationInterface, QueryRunner, Table, TableForeignKey } from "typeorm"; +import { DB_TYPE } from "../env.defaults"; export class Initial1724317398939 implements MigrationInterface { name = "Initial1724317398939"; public async up(queryRunner: QueryRunner): Promise { + const variableType_int = DB_TYPE == "mysql" ? "int" : "integer"; + await queryRunner.createTable( new Table({ name: "user", columns: [ - { name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" }, + { name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" }, { name: "mail", type: "varchar", length: "255", isNullable: false }, { name: "username", type: "varchar", length: "255", isNullable: false }, { name: "secret", type: "varchar", length: "255", isNullable: false }, @@ -21,10 +24,10 @@ export class Initial1724317398939 implements MigrationInterface { new Table({ name: "refresh", columns: [ - { name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" }, + { name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" }, { name: "token", type: "varchar", length: "255", isNullable: false }, { name: "expiry", type: "datetime", isNullable: false }, - { name: "userId", type: "int", isNullable: false }, + { name: "userId", type: variableType_int, isNullable: false }, ], }), true diff --git a/src/migrations/1724573307851-refreshPrimaryChange.ts b/src/migrations/1724573307851-refreshPrimaryChange.ts index a55d194..8da65b3 100644 --- a/src/migrations/1724573307851-refreshPrimaryChange.ts +++ b/src/migrations/1724573307851-refreshPrimaryChange.ts @@ -1,4 +1,5 @@ import { MigrationInterface, QueryRunner, TableColumn } from "typeorm"; +import { DB_TYPE } from "../env.defaults"; export class RefreshPrimaryChange1724573307851 implements MigrationInterface { name = "RefreshPrimaryChange1724573307851"; @@ -9,12 +10,14 @@ export class RefreshPrimaryChange1724573307851 implements MigrationInterface { } public async down(queryRunner: QueryRunner): Promise { + const variableType_int = DB_TYPE == "mysql" ? "int" : "integer"; + await queryRunner.dropPrimaryKey("refresh"); await queryRunner.addColumn( "refresh", new TableColumn({ name: "id", - type: "int", + type: variableType_int, isPrimary: true, isNullable: false, isGenerated: true, diff --git a/src/migrations/1724661484664-permissions.ts b/src/migrations/1724661484664-permissions.ts index 22cc1e8..f14fe3f 100644 --- a/src/migrations/1724661484664-permissions.ts +++ b/src/migrations/1724661484664-permissions.ts @@ -1,9 +1,12 @@ import { MigrationInterface, QueryRunner, Table, TableForeignKey } from "typeorm"; +import { DB_TYPE } from "../env.defaults"; export class Permissions1724661484664 implements MigrationInterface { name = "Permissions1724661484664"; public async up(queryRunner: QueryRunner): Promise { + const variableType_int = DB_TYPE == "mysql" ? "int" : "integer"; + await queryRunner.createTable( new Table({ name: "permission", @@ -15,7 +18,7 @@ export class Permissions1724661484664 implements MigrationInterface { isPrimary: true, isNullable: false, }, - { name: "userId", type: "int", isPrimary: true, isNullable: false }, + { name: "userId", type: variableType_int, isPrimary: true, isNullable: false }, ], }), true diff --git a/src/migrations/1724771491085-role_permission.ts b/src/migrations/1724771491085-role_permission.ts index 4d3915f..dc8df18 100644 --- a/src/migrations/1724771491085-role_permission.ts +++ b/src/migrations/1724771491085-role_permission.ts @@ -1,14 +1,17 @@ import { MigrationInterface, QueryRunner, Table, TableForeignKey, TableIndex } from "typeorm"; +import { DB_TYPE } from "../env.defaults"; export class RolePermission1724771491085 implements MigrationInterface { name = "RolePermission1724771491085"; public async up(queryRunner: QueryRunner): Promise { + const variableType_int = DB_TYPE == "mysql" ? "int" : "integer"; + await queryRunner.createTable( new Table({ name: "role", columns: [ - { name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" }, + { name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" }, { name: "role", type: "varchar", length: "255", isNullable: false }, ], }), @@ -26,7 +29,7 @@ export class RolePermission1724771491085 implements MigrationInterface { isPrimary: true, isNullable: false, }, - { name: "roleId", type: "int", isPrimary: true, isNullable: false }, + { name: "roleId", type: variableType_int, isPrimary: true, isNullable: false }, ], }), true @@ -38,8 +41,8 @@ export class RolePermission1724771491085 implements MigrationInterface { new Table({ name: "user_roles", columns: [ - { name: "userId", type: "int", isPrimary: true, isNullable: false }, - { name: "roleId", type: "int", isPrimary: true, isNullable: false }, + { name: "userId", type: variableType_int, isPrimary: true, isNullable: false }, + { name: "roleId", type: variableType_int, isPrimary: true, isNullable: false }, ], }), true diff --git a/src/migrations/1725435669492-member_base_data.ts b/src/migrations/1725435669492-member_base_data.ts index 054d85a..ba4f870 100644 --- a/src/migrations/1725435669492-member_base_data.ts +++ b/src/migrations/1725435669492-member_base_data.ts @@ -1,14 +1,17 @@ import { MigrationInterface, QueryRunner, Table, TableForeignKey } from "typeorm"; +import { DB_TYPE } from "../env.defaults"; export class MemberBaseData1725435669492 implements MigrationInterface { name = "MemberBaseData1725435669492"; public async up(queryRunner: QueryRunner): Promise { + const variableType_int = DB_TYPE == "mysql" ? "int" : "integer"; + await queryRunner.createTable( new Table({ name: "award", columns: [ - { name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" }, + { name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" }, { name: "award", type: "varchar", length: "255", isNullable: false }, ], }), @@ -19,7 +22,7 @@ export class MemberBaseData1725435669492 implements MigrationInterface { new Table({ name: "communication_type", columns: [ - { name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" }, + { name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" }, { name: "type", type: "varchar", length: "255", isNullable: false }, { name: "useColumns", type: "varchar", length: "255", isNullable: false, default: "''" }, ], @@ -31,15 +34,15 @@ export class MemberBaseData1725435669492 implements MigrationInterface { new Table({ name: "communication", columns: [ - { name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" }, - { name: "preffered", type: "tinyint", isNullable: false, default: 0 }, + { name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" }, + { name: "preferred", 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: "streetNumber", type: variableType_int, isNullable: false }, { name: "streetNumberAddition", type: "varchar", length: "255", isNullable: false }, - { name: "typeId", type: "int", isNullable: false }, + { name: "typeId", type: variableType_int, isNullable: false }, ], }), true @@ -49,7 +52,7 @@ export class MemberBaseData1725435669492 implements MigrationInterface { new Table({ name: "executive_position", columns: [ - { name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" }, + { name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" }, { name: "position", type: "varchar", length: "255", isNullable: false }, ], }), @@ -60,7 +63,7 @@ export class MemberBaseData1725435669492 implements MigrationInterface { new Table({ name: "membership_status", columns: [ - { name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" }, + { name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" }, { name: "status", type: "varchar", length: "255", isNullable: false }, ], }), @@ -71,7 +74,7 @@ export class MemberBaseData1725435669492 implements MigrationInterface { new Table({ name: "qualification", columns: [ - { name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" }, + { name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" }, { name: "qualification", type: "varchar", length: "255", isNullable: false }, { name: "description", type: "varchar", length: "255", isNullable: true }, ], diff --git a/src/migrations/1726301836849-memberdata.ts b/src/migrations/1726301836849-memberdata.ts index c62696a..e49043c 100644 --- a/src/migrations/1726301836849-memberdata.ts +++ b/src/migrations/1726301836849-memberdata.ts @@ -1,20 +1,23 @@ import { MigrationInterface, QueryRunner, Table, TableColumn, TableForeignKey } from "typeorm"; +import { DB_TYPE } from "../env.defaults"; export class Memberdata1726301836849 implements MigrationInterface { name = "Memberdata1726301836849"; public async up(queryRunner: QueryRunner): Promise { + const variableType_int = DB_TYPE == "mysql" ? "int" : "integer"; + await queryRunner.createTable( new Table({ name: "membership", columns: [ - { name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" }, + { name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" }, { name: "internalId", type: "varchar", length: "255", isNullable: true }, { name: "start", type: "date", isNullable: false }, { name: "end", type: "date", isNullable: true }, { name: "terminationReason", type: "varchar", length: "255", isNullable: true }, - { name: "memberId", type: "int", isNullable: false }, - { name: "statusId", type: "int", isNullable: false }, + { name: "memberId", type: variableType_int, isNullable: false }, + { name: "statusId", type: variableType_int, isNullable: false }, ], uniques: [{ name: "IDX_703f499fe3a9892e3a8790cdfc", columnNames: ["internalId"] }], }), @@ -25,13 +28,13 @@ export class Memberdata1726301836849 implements MigrationInterface { new Table({ name: "member_qualifications", columns: [ - { name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" }, + { name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" }, { name: "note", type: "varchar", length: "255", isNullable: true }, { name: "start", type: "date", isNullable: false }, { name: "end", type: "date", isNullable: true }, { name: "terminationReason", type: "varchar", length: "255", isNullable: true }, - { name: "memberId", type: "int", isNullable: false }, - { name: "qualificationId", type: "int", isNullable: false }, + { name: "memberId", type: variableType_int, isNullable: false }, + { name: "qualificationId", type: variableType_int, isNullable: false }, ], }), true @@ -41,12 +44,12 @@ export class Memberdata1726301836849 implements MigrationInterface { new Table({ name: "member_executive_positions", columns: [ - { name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" }, + { name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" }, { name: "note", type: "varchar", length: "255", isNullable: true }, { name: "start", type: "date", isNullable: false }, { name: "end", type: "date", isNullable: true }, - { name: "memberId", type: "int", isNullable: false }, - { name: "executivePositionId", type: "int", isNullable: false }, + { name: "memberId", type: variableType_int, isNullable: false }, + { name: "executivePositionId", type: variableType_int, isNullable: false }, ], }), true @@ -56,19 +59,13 @@ export class Memberdata1726301836849 implements MigrationInterface { new Table({ name: "member", columns: [ - { name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" }, - { - name: "salutation", - type: "enum", - enum: ["sir", "madam", "other", "none"], - default: "'none'", - isNullable: false, - }, + { name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" }, + { name: "salutation", type: "varchar", length: "255", default: "'none'", isNullable: false }, { name: "firstname", type: "varchar", length: "255", isNullable: false }, { name: "lastname", type: "varchar", length: "255", isNullable: false }, { name: "nameaffix", type: "varchar", length: "255", isNullable: false }, { name: "birthdate", type: "date", isNullable: false }, - { name: "sendNewsletterId", type: "int", isNullable: true }, + { name: "sendNewsletterId", type: variableType_int, isNullable: true }, ], uniques: [{ name: "REL_d57e160c4513cd949159217281", columnNames: ["sendNewsletterId"] }], }), @@ -79,18 +76,21 @@ export class Memberdata1726301836849 implements MigrationInterface { new Table({ name: "member_awards", columns: [ - { name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" }, + { name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" }, { name: "given", type: "tinyint", default: 1, isNullable: false }, { name: "note", type: "varchar", length: "255", isNullable: true }, { name: "date", type: "date", isNullable: false }, - { name: "memberId", type: "int", isNullable: false }, - { name: "awardId", type: "int", isNullable: false }, + { name: "memberId", type: variableType_int, isNullable: false }, + { name: "awardId", type: variableType_int, isNullable: false }, ], }), true ); - await queryRunner.addColumn("communication", new TableColumn({ name: "memberId", type: "int", isNullable: false })); + await queryRunner.addColumn( + "communication", + new TableColumn({ name: "memberId", type: variableType_int, isNullable: false }) + ); await queryRunner.createForeignKey( "membership",