WIP: Split up moon counter from the database #489

Draft
Vylpes wants to merge 16 commits from feature/300-moon-set into develop
3 changed files with 61 additions and 0 deletions
Showing only changes of commit 789d5d6410 - Show all commits

View file

@ -0,0 +1,11 @@
CREATE TABLE `user_setting` (
`Id` varchar(255) NOT NULL,
`WhenCreated` datetime NOT NULL,
`WhenUpdated` datetime NOT NULL,
`UserId` varchar(255) NOT NULL,
`Key` varchar(255) NOT NULL,
`Value` varchar(255) NOT NULL,
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
ALTER TABLE `user_setting`
ADD PRIMARY KEY (`Id`);

View file

@ -0,0 +1,35 @@
import { Column, Entity} from "typeorm";
import AppDataSource from "../dataSources/appDataSource";
import BaseEntity from "../../contracts/BaseEntity";
@Entity()
export default class UserSetting extends BaseEntity {
constructor(userId: string, key: string, value: string) {
super();
this.UserId = userId;
this.Key = key;
this.Value = value;
}
@Column()
UserId: string;
@Column()
Key: string;
@Column()
Value: string;
public UpdateValue(value: string) {
this.Value = value;
}
public static async FetchOneByKey(userId: string, key: string, relations?: string[]): Promise<UserSetting | null> {
const repository = AppDataSource.getRepository(UserSetting);
const single = await repository.findOne({ where: { UserId: userId, Key: key }, relations: relations || {} });
return single;
}
}

View file

@ -0,0 +1,15 @@
import { MigrationInterface, QueryRunner } from "typeorm";
import MigrationHelper from "../../../helpers/MigrationHelper";
export class CreateUserSetting1727286976268 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
MigrationHelper.Up('1727286976268-CreateUserSetting', '3.3.0', [
"01-UserSetting",
], queryRunner);
}
public async down(queryRunner: QueryRunner): Promise<void> {
}
}