58 lines
2.4 KiB
TypeScript
58 lines
2.4 KiB
TypeScript
import { MigrationInterface, QueryRunner } from 'typeorm';
|
|
|
|
export class CreateDashboardSnapshots1781800000000 implements MigrationInterface {
|
|
name = 'CreateDashboardSnapshots1781800000000';
|
|
|
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
if (!(await queryRunner.hasTable('daily_dashboard_snapshots'))) {
|
|
await queryRunner.query(`
|
|
CREATE TABLE \`daily_dashboard_snapshots\` (
|
|
\`id\` varchar(36) NOT NULL,
|
|
\`userId\` varchar(36) NOT NULL,
|
|
\`dateKey\` varchar(10) NOT NULL,
|
|
\`timezone\` varchar(80) NOT NULL,
|
|
\`selectedLists\` json NOT NULL,
|
|
\`requestPayload\` json NOT NULL,
|
|
\`responsePayload\` json NULL,
|
|
\`errorMessage\` text NULL,
|
|
\`createdAt\` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
\`updatedAt\` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
|
|
INDEX \`IDX_daily_dashboard_snapshots_user_id\` (\`userId\`),
|
|
UNIQUE INDEX \`IDX_daily_dashboard_snapshots_user_date\` (\`userId\`, \`dateKey\`),
|
|
PRIMARY KEY (\`id\`)
|
|
) ENGINE=InnoDB
|
|
`);
|
|
}
|
|
|
|
if (!(await queryRunner.hasTable('weekly_list_suggestion_snapshots'))) {
|
|
await queryRunner.query(`
|
|
CREATE TABLE \`weekly_list_suggestion_snapshots\` (
|
|
\`id\` varchar(36) NOT NULL,
|
|
\`userId\` varchar(36) NOT NULL,
|
|
\`weekKey\` varchar(10) NOT NULL,
|
|
\`timezone\` varchar(80) NOT NULL,
|
|
\`suggestions\` json NOT NULL,
|
|
\`requestPayload\` json NOT NULL,
|
|
\`responsePayload\` json NULL,
|
|
\`errorMessage\` text NULL,
|
|
\`createdAt\` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
\`updatedAt\` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
|
|
INDEX \`IDX_weekly_list_suggestion_snapshots_user_id\` (\`userId\`),
|
|
UNIQUE INDEX \`IDX_weekly_list_suggestion_snapshots_user_week\` (\`userId\`, \`weekKey\`),
|
|
PRIMARY KEY (\`id\`)
|
|
) ENGINE=InnoDB
|
|
`);
|
|
}
|
|
}
|
|
|
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
if (await queryRunner.hasTable('weekly_list_suggestion_snapshots')) {
|
|
await queryRunner.query('DROP TABLE `weekly_list_suggestion_snapshots`');
|
|
}
|
|
|
|
if (await queryRunner.hasTable('daily_dashboard_snapshots')) {
|
|
await queryRunner.query('DROP TABLE `daily_dashboard_snapshots`');
|
|
}
|
|
}
|
|
}
|