mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-09-08 17:09:07 +08:00
add the logic for run migrate to process table schema change
This commit is contained in:
@@ -1,18 +1,43 @@
|
|||||||
import { MigrationInterface, QueryRunner } from "typeorm"
|
import { MigrationInterface, QueryRunner, TableColumn } from "typeorm";
|
||||||
|
|
||||||
const dropViewSql = `
|
const viewNames = [
|
||||||
DROP VIEW IF EXISTS "v_boss_library";
|
"v_boss_library",
|
||||||
DROP VIEW IF EXISTS "v_chat_startup_log";
|
"v_chat_startup_log",
|
||||||
DROP VIEW IF EXISTS "v_company_library";
|
"v_company_library",
|
||||||
DROP VIEW IF EXISTS "v_job_library";
|
"v_job_library",
|
||||||
`;
|
];
|
||||||
|
|
||||||
export class UpdateChatStartupLogTable1729182577167 implements MigrationInterface {
|
export class UpdateChatStartupLogTable1729182577167
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
implements MigrationInterface
|
||||||
await queryRunner.query(dropViewSql);
|
{
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
for (const viewName of viewNames) {
|
||||||
|
await queryRunner.query(`DROP VIEW IF EXISTS "${viewName}"`);
|
||||||
}
|
}
|
||||||
|
if (await queryRunner.hasTable("boss_active_status_record")) {
|
||||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
if (await queryRunner.hasColumn("boss_active_status_record", "updateDate")) {
|
||||||
await queryRunner.query(dropViewSql);
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE boss_active_status_record RENAME COLUMN updateDate TO updateTime`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
await queryRunner.changeColumn(
|
||||||
|
'boss_active_status_record',
|
||||||
|
'lastActiveStatus',
|
||||||
|
new TableColumn({
|
||||||
|
name: 'lastActiveStatus',
|
||||||
|
type: 'varchar',
|
||||||
|
isNullable: true
|
||||||
|
})
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
for (const viewName of viewNames) {
|
||||||
|
await queryRunner.query(`DROP VIEW IF EXISTS "${viewName}"`);
|
||||||
|
}
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE boss_active_status_record RENAME COLUMN updateTime TO updateDate`
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user