2 Commits

Author SHA1 Message Date
Aster Fialla
ee4dca2ae3 added migration to populate system with user id data from member table 2026-03-17 09:17:43 -04:00
Aster Fialla
ff4dba3dfd added system model and migration 2026-03-17 09:17:15 -04:00
3 changed files with 74 additions and 0 deletions

47
database/entity/System.ts Normal file
View File

@@ -0,0 +1,47 @@
import {Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, Unique} from "typeorm"
@Entity({name: "System", synchronize: true})
@Unique("UQ_System_userid", ['userid'])
@Unique("UQ_System_shortid", ['shortid'])
export class System {
@PrimaryGeneratedColumn()
id: number
@Column({
nullable: true,
})
shortid: string
@Column()
userid: string
@Column({
length: 100,
nullable: true
})
name: string
@Column({
type: "varchar",
nullable: true,
length: 100
})
fronter: string
@Column({
nullable: true,
})
grouptag: string
@Column({
nullable: true,
})
autoproxy: string
@CreateDateColumn({ type: 'timestamptz' })
createdAt: Date
@UpdateDateColumn({ type: 'timestamptz' })
updatedAt: Date
}

View File

@@ -0,0 +1,14 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class Update1773670748825 implements MigrationInterface {
name = 'Update1773670748825'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE "System" ("id" SERIAL NOT NULL, "shortid" character varying, "userid" character varying NOT NULL, "name" character varying(100), "fronter" character varying(100), "grouptag" character varying, "autoproxy" character varying, "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), CONSTRAINT "UQ_System_shortid" UNIQUE ("shortid"), CONSTRAINT "UQ_System_userid" UNIQUE ("userid"), CONSTRAINT "PK_b8e3f6855de5a4758fcb59e5567" PRIMARY KEY ("id"))`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP TABLE "System"`);
}
}

View File

@@ -0,0 +1,13 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class Update1773749921832 implements MigrationInterface {
name = 'Update1773749921832'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`INSERT INTO "System" ("userid") SELECT DISTINCT "userid" FROM "Member";`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DELETE from "System" USING "Member" WHERE "System".userid = "Member".userid;`);
}
}