mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-07-07 07:11:22 +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 = `
|
||||
DROP VIEW IF EXISTS "v_boss_library";
|
||||
DROP VIEW IF EXISTS "v_chat_startup_log";
|
||||
DROP VIEW IF EXISTS "v_company_library";
|
||||
DROP VIEW IF EXISTS "v_job_library";
|
||||
`;
|
||||
const viewNames = [
|
||||
"v_boss_library",
|
||||
"v_chat_startup_log",
|
||||
"v_company_library",
|
||||
"v_job_library",
|
||||
];
|
||||
|
||||
export class UpdateChatStartupLogTable1729182577167 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(dropViewSql);
|
||||
export class UpdateChatStartupLogTable1729182577167
|
||||
implements MigrationInterface
|
||||
{
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
for (const viewName of viewNames) {
|
||||
await queryRunner.query(`DROP VIEW IF EXISTS "${viewName}"`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(dropViewSql);
|
||||
if (await queryRunner.hasTable("boss_active_status_record")) {
|
||||
if (await queryRunner.hasColumn("boss_active_status_record", "updateDate")) {
|
||||
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