typing and db types

This commit is contained in:
Julian Krauser 2024-09-16 07:24:41 +02:00
parent e455b5c8f6
commit 5fdfdcbd1f
9 changed files with 70 additions and 43 deletions

View file

@ -8,7 +8,7 @@ export class communication {
id: number; id: number;
@Column({ type: "boolean", default: false }) @Column({ type: "boolean", default: false })
preffered: boolean; preferred: boolean;
@Column({ type: "varchar", length: 255 }) @Column({ type: "varchar", length: 255 })
mobile: string; mobile: string;

View file

@ -11,7 +11,19 @@ export class member {
@PrimaryColumn({ generated: "increment", type: "int" }) @PrimaryColumn({ generated: "increment", type: "int" })
id: number; 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; salutation: Salutation;
@Column({ type: "varchar", length: 255 }) @Column({ type: "varchar", length: 255 })

View file

@ -22,7 +22,7 @@ export const MAIL_SECURE = process.env.MAIL_SECURE ?? "false";
export const CLUB_NAME = process.env.CLUB_NAME ?? ""; export const CLUB_NAME = process.env.CLUB_NAME ?? "";
export function configCheck() { 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_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_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"); if (DB_USERNAME == "" ?? typeof DB_USERNAME != "string") throw new Error("set valid value to DB_USERNAME");

View file

@ -1,14 +1,17 @@
import { MigrationInterface, QueryRunner, Table, TableForeignKey } from "typeorm"; import { MigrationInterface, QueryRunner, Table, TableForeignKey } from "typeorm";
import { DB_TYPE } from "../env.defaults";
export class Initial1724317398939 implements MigrationInterface { export class Initial1724317398939 implements MigrationInterface {
name = "Initial1724317398939"; name = "Initial1724317398939";
public async up(queryRunner: QueryRunner): Promise<void> { public async up(queryRunner: QueryRunner): Promise<void> {
const variableType_int = DB_TYPE == "mysql" ? "int" : "integer";
await queryRunner.createTable( await queryRunner.createTable(
new Table({ new Table({
name: "user", name: "user",
columns: [ 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: "mail", type: "varchar", length: "255", isNullable: false },
{ name: "username", type: "varchar", length: "255", isNullable: false }, { name: "username", type: "varchar", length: "255", isNullable: false },
{ name: "secret", 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({ new Table({
name: "refresh", name: "refresh",
columns: [ 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: "token", type: "varchar", length: "255", isNullable: false },
{ name: "expiry", type: "datetime", isNullable: false }, { name: "expiry", type: "datetime", isNullable: false },
{ name: "userId", type: "int", isNullable: false }, { name: "userId", type: variableType_int, isNullable: false },
], ],
}), }),
true true

View file

@ -1,4 +1,5 @@
import { MigrationInterface, QueryRunner, TableColumn } from "typeorm"; import { MigrationInterface, QueryRunner, TableColumn } from "typeorm";
import { DB_TYPE } from "../env.defaults";
export class RefreshPrimaryChange1724573307851 implements MigrationInterface { export class RefreshPrimaryChange1724573307851 implements MigrationInterface {
name = "RefreshPrimaryChange1724573307851"; name = "RefreshPrimaryChange1724573307851";
@ -9,12 +10,14 @@ export class RefreshPrimaryChange1724573307851 implements MigrationInterface {
} }
public async down(queryRunner: QueryRunner): Promise<void> { public async down(queryRunner: QueryRunner): Promise<void> {
const variableType_int = DB_TYPE == "mysql" ? "int" : "integer";
await queryRunner.dropPrimaryKey("refresh"); await queryRunner.dropPrimaryKey("refresh");
await queryRunner.addColumn( await queryRunner.addColumn(
"refresh", "refresh",
new TableColumn({ new TableColumn({
name: "id", name: "id",
type: "int", type: variableType_int,
isPrimary: true, isPrimary: true,
isNullable: false, isNullable: false,
isGenerated: true, isGenerated: true,

View file

@ -1,9 +1,12 @@
import { MigrationInterface, QueryRunner, Table, TableForeignKey } from "typeorm"; import { MigrationInterface, QueryRunner, Table, TableForeignKey } from "typeorm";
import { DB_TYPE } from "../env.defaults";
export class Permissions1724661484664 implements MigrationInterface { export class Permissions1724661484664 implements MigrationInterface {
name = "Permissions1724661484664"; name = "Permissions1724661484664";
public async up(queryRunner: QueryRunner): Promise<void> { public async up(queryRunner: QueryRunner): Promise<void> {
const variableType_int = DB_TYPE == "mysql" ? "int" : "integer";
await queryRunner.createTable( await queryRunner.createTable(
new Table({ new Table({
name: "permission", name: "permission",
@ -15,7 +18,7 @@ export class Permissions1724661484664 implements MigrationInterface {
isPrimary: true, isPrimary: true,
isNullable: false, isNullable: false,
}, },
{ name: "userId", type: "int", isPrimary: true, isNullable: false }, { name: "userId", type: variableType_int, isPrimary: true, isNullable: false },
], ],
}), }),
true true

View file

@ -1,14 +1,17 @@
import { MigrationInterface, QueryRunner, Table, TableForeignKey, TableIndex } from "typeorm"; import { MigrationInterface, QueryRunner, Table, TableForeignKey, TableIndex } from "typeorm";
import { DB_TYPE } from "../env.defaults";
export class RolePermission1724771491085 implements MigrationInterface { export class RolePermission1724771491085 implements MigrationInterface {
name = "RolePermission1724771491085"; name = "RolePermission1724771491085";
public async up(queryRunner: QueryRunner): Promise<void> { public async up(queryRunner: QueryRunner): Promise<void> {
const variableType_int = DB_TYPE == "mysql" ? "int" : "integer";
await queryRunner.createTable( await queryRunner.createTable(
new Table({ new Table({
name: "role", name: "role",
columns: [ 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 }, { name: "role", type: "varchar", length: "255", isNullable: false },
], ],
}), }),
@ -26,7 +29,7 @@ export class RolePermission1724771491085 implements MigrationInterface {
isPrimary: true, isPrimary: true,
isNullable: false, isNullable: false,
}, },
{ name: "roleId", type: "int", isPrimary: true, isNullable: false }, { name: "roleId", type: variableType_int, isPrimary: true, isNullable: false },
], ],
}), }),
true true
@ -38,8 +41,8 @@ export class RolePermission1724771491085 implements MigrationInterface {
new Table({ new Table({
name: "user_roles", name: "user_roles",
columns: [ columns: [
{ name: "userId", type: "int", isPrimary: true, isNullable: false }, { name: "userId", type: variableType_int, isPrimary: true, isNullable: false },
{ name: "roleId", type: "int", isPrimary: true, isNullable: false }, { name: "roleId", type: variableType_int, isPrimary: true, isNullable: false },
], ],
}), }),
true true

View file

@ -1,14 +1,17 @@
import { MigrationInterface, QueryRunner, Table, TableForeignKey } from "typeorm"; import { MigrationInterface, QueryRunner, Table, TableForeignKey } from "typeorm";
import { DB_TYPE } from "../env.defaults";
export class MemberBaseData1725435669492 implements MigrationInterface { export class MemberBaseData1725435669492 implements MigrationInterface {
name = "MemberBaseData1725435669492"; name = "MemberBaseData1725435669492";
public async up(queryRunner: QueryRunner): Promise<void> { public async up(queryRunner: QueryRunner): Promise<void> {
const variableType_int = DB_TYPE == "mysql" ? "int" : "integer";
await queryRunner.createTable( await queryRunner.createTable(
new Table({ new Table({
name: "award", name: "award",
columns: [ 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 }, { name: "award", type: "varchar", length: "255", isNullable: false },
], ],
}), }),
@ -19,7 +22,7 @@ export class MemberBaseData1725435669492 implements MigrationInterface {
new Table({ new Table({
name: "communication_type", name: "communication_type",
columns: [ 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: "type", type: "varchar", length: "255", isNullable: false },
{ name: "useColumns", type: "varchar", length: "255", isNullable: false, default: "''" }, { name: "useColumns", type: "varchar", length: "255", isNullable: false, default: "''" },
], ],
@ -31,15 +34,15 @@ export class MemberBaseData1725435669492 implements MigrationInterface {
new Table({ new Table({
name: "communication", name: "communication",
columns: [ columns: [
{ name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" }, { name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" },
{ name: "preffered", type: "tinyint", isNullable: false, default: 0 }, { name: "preferred", type: "tinyint", isNullable: false, default: 0 },
{ name: "mobile", type: "varchar", length: "255", isNullable: false }, { name: "mobile", type: "varchar", length: "255", isNullable: false },
{ name: "email", type: "varchar", length: "255", isNullable: false }, { name: "email", type: "varchar", length: "255", isNullable: false },
{ name: "city", type: "varchar", length: "255", isNullable: false }, { name: "city", type: "varchar", length: "255", isNullable: false },
{ name: "street", 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: "streetNumberAddition", type: "varchar", length: "255", isNullable: false },
{ name: "typeId", type: "int", isNullable: false }, { name: "typeId", type: variableType_int, isNullable: false },
], ],
}), }),
true true
@ -49,7 +52,7 @@ export class MemberBaseData1725435669492 implements MigrationInterface {
new Table({ new Table({
name: "executive_position", name: "executive_position",
columns: [ 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 }, { name: "position", type: "varchar", length: "255", isNullable: false },
], ],
}), }),
@ -60,7 +63,7 @@ export class MemberBaseData1725435669492 implements MigrationInterface {
new Table({ new Table({
name: "membership_status", name: "membership_status",
columns: [ 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 }, { name: "status", type: "varchar", length: "255", isNullable: false },
], ],
}), }),
@ -71,7 +74,7 @@ export class MemberBaseData1725435669492 implements MigrationInterface {
new Table({ new Table({
name: "qualification", name: "qualification",
columns: [ 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: "qualification", type: "varchar", length: "255", isNullable: false },
{ name: "description", type: "varchar", length: "255", isNullable: true }, { name: "description", type: "varchar", length: "255", isNullable: true },
], ],

View file

@ -1,20 +1,23 @@
import { MigrationInterface, QueryRunner, Table, TableColumn, TableForeignKey } from "typeorm"; import { MigrationInterface, QueryRunner, Table, TableColumn, TableForeignKey } from "typeorm";
import { DB_TYPE } from "../env.defaults";
export class Memberdata1726301836849 implements MigrationInterface { export class Memberdata1726301836849 implements MigrationInterface {
name = "Memberdata1726301836849"; name = "Memberdata1726301836849";
public async up(queryRunner: QueryRunner): Promise<void> { public async up(queryRunner: QueryRunner): Promise<void> {
const variableType_int = DB_TYPE == "mysql" ? "int" : "integer";
await queryRunner.createTable( await queryRunner.createTable(
new Table({ new Table({
name: "membership", name: "membership",
columns: [ 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: "internalId", type: "varchar", length: "255", isNullable: true },
{ name: "start", type: "date", isNullable: false }, { name: "start", type: "date", isNullable: false },
{ name: "end", type: "date", isNullable: true }, { name: "end", type: "date", isNullable: true },
{ name: "terminationReason", type: "varchar", length: "255", isNullable: true }, { name: "terminationReason", type: "varchar", length: "255", isNullable: true },
{ name: "memberId", type: "int", isNullable: false }, { name: "memberId", type: variableType_int, isNullable: false },
{ name: "statusId", type: "int", isNullable: false }, { name: "statusId", type: variableType_int, isNullable: false },
], ],
uniques: [{ name: "IDX_703f499fe3a9892e3a8790cdfc", columnNames: ["internalId"] }], uniques: [{ name: "IDX_703f499fe3a9892e3a8790cdfc", columnNames: ["internalId"] }],
}), }),
@ -25,13 +28,13 @@ export class Memberdata1726301836849 implements MigrationInterface {
new Table({ new Table({
name: "member_qualifications", name: "member_qualifications",
columns: [ 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: "note", type: "varchar", length: "255", isNullable: true },
{ name: "start", type: "date", isNullable: false }, { name: "start", type: "date", isNullable: false },
{ name: "end", type: "date", isNullable: true }, { name: "end", type: "date", isNullable: true },
{ name: "terminationReason", type: "varchar", length: "255", isNullable: true }, { name: "terminationReason", type: "varchar", length: "255", isNullable: true },
{ name: "memberId", type: "int", isNullable: false }, { name: "memberId", type: variableType_int, isNullable: false },
{ name: "qualificationId", type: "int", isNullable: false }, { name: "qualificationId", type: variableType_int, isNullable: false },
], ],
}), }),
true true
@ -41,12 +44,12 @@ export class Memberdata1726301836849 implements MigrationInterface {
new Table({ new Table({
name: "member_executive_positions", name: "member_executive_positions",
columns: [ 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: "note", type: "varchar", length: "255", isNullable: true },
{ name: "start", type: "date", isNullable: false }, { name: "start", type: "date", isNullable: false },
{ name: "end", type: "date", isNullable: true }, { name: "end", type: "date", isNullable: true },
{ name: "memberId", type: "int", isNullable: false }, { name: "memberId", type: variableType_int, isNullable: false },
{ name: "executivePositionId", type: "int", isNullable: false }, { name: "executivePositionId", type: variableType_int, isNullable: false },
], ],
}), }),
true true
@ -56,19 +59,13 @@ export class Memberdata1726301836849 implements MigrationInterface {
new Table({ new Table({
name: "member", name: "member",
columns: [ columns: [
{ name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" }, { name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" },
{ { name: "salutation", type: "varchar", length: "255", default: "'none'", isNullable: false },
name: "salutation",
type: "enum",
enum: ["sir", "madam", "other", "none"],
default: "'none'",
isNullable: false,
},
{ name: "firstname", type: "varchar", length: "255", isNullable: false }, { name: "firstname", type: "varchar", length: "255", isNullable: false },
{ name: "lastname", type: "varchar", length: "255", isNullable: false }, { name: "lastname", type: "varchar", length: "255", isNullable: false },
{ name: "nameaffix", type: "varchar", length: "255", isNullable: false }, { name: "nameaffix", type: "varchar", length: "255", isNullable: false },
{ name: "birthdate", type: "date", 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"] }], uniques: [{ name: "REL_d57e160c4513cd949159217281", columnNames: ["sendNewsletterId"] }],
}), }),
@ -79,18 +76,21 @@ export class Memberdata1726301836849 implements MigrationInterface {
new Table({ new Table({
name: "member_awards", name: "member_awards",
columns: [ 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: "given", type: "tinyint", default: 1, isNullable: false },
{ name: "note", type: "varchar", length: "255", isNullable: true }, { name: "note", type: "varchar", length: "255", isNullable: true },
{ name: "date", type: "date", isNullable: false }, { name: "date", type: "date", isNullable: false },
{ name: "memberId", type: "int", isNullable: false }, { name: "memberId", type: variableType_int, isNullable: false },
{ name: "awardId", type: "int", isNullable: false }, { name: "awardId", type: variableType_int, isNullable: false },
], ],
}), }),
true 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( await queryRunner.createForeignKey(
"membership", "membership",