From 81351102a9cc8b48f9bb9b7f2dcc83492fd0c6a6 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 29 Jan 2022 03:53:21 +0100 Subject: [PATCH] migration to rename login_pending_tasks_admin to admin_pending_creations also remove old table login_pending_tasks --- .../AdminPendingCreation.ts | 25 +++++++++++++ database/entity/AdminPendingCreation.ts | 1 + database/entity/LoginPendingTasksAdmin.ts | 1 - database/entity/index.ts | 4 +-- .../0015-admin_pending_creations.ts | 35 +++++++++++++++++++ 5 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 database/entity/0015-admin_pending_creations/AdminPendingCreation.ts create mode 100644 database/entity/AdminPendingCreation.ts delete mode 100644 database/entity/LoginPendingTasksAdmin.ts create mode 100644 database/migrations/0015-admin_pending_creations.ts diff --git a/database/entity/0015-admin_pending_creations/AdminPendingCreation.ts b/database/entity/0015-admin_pending_creations/AdminPendingCreation.ts new file mode 100644 index 000000000..1c3027867 --- /dev/null +++ b/database/entity/0015-admin_pending_creations/AdminPendingCreation.ts @@ -0,0 +1,25 @@ +import { BaseEntity, Column, Entity, PrimaryGeneratedColumn } from 'typeorm' + +@Entity('admin_pending_creations') +export class AdminPendingCreation extends BaseEntity { + @PrimaryGeneratedColumn('increment', { unsigned: true }) + id: number + + @Column({ unsigned: true, nullable: false }) + userId: number + + @Column({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP' }) + created: Date + + @Column({ type: 'datetime', nullable: false }) + date: Date + + @Column({ length: 256, nullable: true, default: null }) + memo: string + + @Column({ type: 'bigint', nullable: false }) + amount: BigInt + + @Column() + moderator: number +} diff --git a/database/entity/AdminPendingCreation.ts b/database/entity/AdminPendingCreation.ts new file mode 100644 index 000000000..03eeab883 --- /dev/null +++ b/database/entity/AdminPendingCreation.ts @@ -0,0 +1 @@ +export { AdminPendingCreation } from './0015-admin_pending_creations/AdminPendingCreation' diff --git a/database/entity/LoginPendingTasksAdmin.ts b/database/entity/LoginPendingTasksAdmin.ts deleted file mode 100644 index f766b74dd..000000000 --- a/database/entity/LoginPendingTasksAdmin.ts +++ /dev/null @@ -1 +0,0 @@ -export { LoginPendingTasksAdmin } from './0005-admin_tables/LoginPendingTasksAdmin' diff --git a/database/entity/index.ts b/database/entity/index.ts index 9d3b10ea7..331e797df 100644 --- a/database/entity/index.ts +++ b/database/entity/index.ts @@ -13,9 +13,10 @@ import { TransactionSendCoin } from './TransactionSendCoin' import { User } from './User' import { UserSetting } from './UserSetting' import { UserTransaction } from './UserTransaction' -import { LoginPendingTasksAdmin } from './LoginPendingTasksAdmin' +import { AdminPendingCreation } from './AdminPendingCreation' export const entities = [ + AdminPendingCreation, Balance, LoginElopageBuys, LoginEmailOptIn, @@ -31,5 +32,4 @@ export const entities = [ User, UserSetting, UserTransaction, - LoginPendingTasksAdmin, ] diff --git a/database/migrations/0015-admin_pending_creations.ts b/database/migrations/0015-admin_pending_creations.ts new file mode 100644 index 000000000..d15bd84a7 --- /dev/null +++ b/database/migrations/0015-admin_pending_creations.ts @@ -0,0 +1,35 @@ +/* MIGRATION TO PROPERLY STORE PENDING CREATIONS + * + * There were two tables for the pending tasks, + * since the login_server used some crypto to store its + * tasks there. It was easier to create a new table. + * This migration drops the old unused table and renames + * the new table to properly describe what it does + */ + +export async function upgrade(queryFn: (query: string, values?: any[]) => Promise>) { + // drop duplicate table, it was unused + await queryFn('DROP TABLE `login_pending_tasks`;') + + // rename the new pending creations table to a proper table name + await queryFn('RENAME TABLE `login_pending_tasks_admin` TO `admin_pending_creations`;') +} + +export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { + await queryFn('RENAME TABLE `admin_pending_creations` TO `login_pending_tasks_admin`;') + await queryFn(` + CREATE TABLE \`login_pending_tasks\` ( + \`id\` int(10) unsigned NOT NULL AUTO_INCREMENT, + \`user_id\` int(10) unsigned DEFAULT 0, + \`request\` varbinary(2048) NOT NULL, + \`created\` datetime NOT NULL, + \`finished\` datetime DEFAULT '2000-01-01 00:00:00', + \`result_json\` text DEFAULT NULL, + \`param_json\` text DEFAULT NULL, + \`task_type_id\` int(10) unsigned NOT NULL, + \`child_pending_task_id\` int(10) unsigned DEFAULT 0, + \`parent_pending_task_id\` int(10) unsigned DEFAULT 0, + PRIMARY KEY (\`id\`) + ) ENGINE=InnoDB AUTO_INCREMENT=795 DEFAULT CHARSET=utf8mb4 + `) +}