add migration query for chat history

This commit is contained in:
chungyau97
2023-09-14 14:50:56 +08:00
parent 0c71e62c2d
commit bc7d95cf9d
12 changed files with 75 additions and 8 deletions
+4 -1
View File
@@ -24,8 +24,11 @@ export interface IChatMessage {
role: MessageType
content: string
chatflowid: string
createdDate: Date
sourceDocuments?: string
chatType: string
memoryType?: string
sessionId?: string
createdDate: Date
}
export interface ITool {
@@ -20,6 +20,15 @@ export class ChatMessage implements IChatMessage {
@Column({ nullable: true, type: 'text' })
sourceDocuments?: string
@Column()
chatType: string
@Column({ nullable: true })
memoryType?: string
@Column({ nullable: true })
sessionId?: string
@CreateDateColumn()
createdDate: Date
}
@@ -2,7 +2,8 @@ import { MigrationInterface, QueryRunner } from 'typeorm'
export class AddApiConfig1694099200729 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`chat_flow\` ADD COLUMN \`apiConfig\` TEXT;`)
const columnExists = await queryRunner.hasColumn('chat_flow', 'apiConfig')
if (!columnExists) queryRunner.query(`ALTER TABLE \`chat_flow\` ADD COLUMN \`apiConfig\` TEXT;`)
}
public async down(queryRunner: QueryRunner): Promise<void> {
@@ -2,7 +2,8 @@ import { MigrationInterface, QueryRunner } from 'typeorm'
export class AddAnalytic1694432361423 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`chat_flow\` ADD COLUMN \`analytic\` TEXT;`)
const columnExists = await queryRunner.hasColumn('chat_flow', 'analytic')
if (!columnExists) queryRunner.query(`ALTER TABLE \`chat_flow\` ADD COLUMN \`analytic\` TEXT;`)
}
public async down(queryRunner: QueryRunner): Promise<void> {
@@ -0,0 +1,19 @@
import { MigrationInterface, QueryRunner } from 'typeorm'
export class AddChatHistory1694658767766 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
const chatTypeColumnExists = await queryRunner.hasColumn('chat_message', 'chatType')
if (!chatTypeColumnExists)
await queryRunner.query(`ALTER TABLE \`chat_message\` ADD COLUMN \`chatType\` VARCHAR(255) NOT NULL DEFAULT 'INTERNAL';`)
const memoryTypeColumnExists = await queryRunner.hasColumn('chat_message', 'memoryType')
if (!memoryTypeColumnExists) await queryRunner.query(`ALTER TABLE \`chat_message\` ADD COLUMN \`memoryType\` VARCHAR(255);`)
const sessionIdColumnExists = await queryRunner.hasColumn('chat_message', 'sessionId')
if (!sessionIdColumnExists) await queryRunner.query(`ALTER TABLE \`chat_message\` ADD COLUMN \`sessionId\` VARCHAR(255);`)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE \`chat_message\` DROP COLUMN \`chatType\`, DROP COLUMN \`memoryType\`, DROP COLUMN \`sessionId\`;`
)
}
}
@@ -5,6 +5,7 @@ import { ModifyCredential1693999261583 } from './1693999261583-ModifyCredential'
import { ModifyTool1694001465232 } from './1694001465232-ModifyTool'
import { AddApiConfig1694099200729 } from './1694099200729-AddApiConfig'
import { AddAnalytic1694432361423 } from './1694432361423-AddAnalytic'
import { AddChatHistory1694658767766 } from './1694658767766-AddChatHistory'
export const mysqlMigrations = [
Init1693840429259,
@@ -13,5 +14,6 @@ export const mysqlMigrations = [
ModifyCredential1693999261583,
ModifyTool1694001465232,
AddApiConfig1694099200729,
AddAnalytic1694432361423
AddAnalytic1694432361423,
AddChatHistory1694658767766
]
@@ -2,7 +2,7 @@ import { MigrationInterface, QueryRunner } from 'typeorm'
export class AddApiConfig1694099183389 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "chat_flow" ADD COLUMN "apiConfig" TEXT;`)
await queryRunner.query(`ALTER TABLE "chat_flow" ADD COLUMN IF NOT EXISTS "apiConfig" TEXT;`)
}
public async down(queryRunner: QueryRunner): Promise<void> {
@@ -2,7 +2,7 @@ import { MigrationInterface, QueryRunner } from 'typeorm'
export class AddAnalytic1694432361423 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "chat_flow" ADD COLUMN "analytic" TEXT;`)
await queryRunner.query(`ALTER TABLE "chat_flow" ADD COLUMN IF NOT EXISTS "analytic" TEXT;`)
}
public async down(queryRunner: QueryRunner): Promise<void> {
@@ -0,0 +1,13 @@
import { MigrationInterface, QueryRunner } from 'typeorm'
export class AddChatHistory1694658756136 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "chat_message" ADD COLUMN IF NOT EXISTS "chatType" VARCHAR NOT NULL DEFAULT 'INTERNAL', ADD COLUMN IF NOT EXISTS "memoryType" VARCHAR, ADD COLUMN IF NOT EXISTS "sessionId" VARCHAR;`
)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "chat_message" DROP COLUMN "chatType", DROP COLUMN "memoryType", DROP COLUMN "sessionId";`)
}
}
@@ -5,6 +5,7 @@ import { ModifyCredential1693997070000 } from './1693997070000-ModifyCredential'
import { ModifyTool1693997339912 } from './1693997339912-ModifyTool'
import { AddApiConfig1694099183389 } from './1694099183389-AddApiConfig'
import { AddAnalytic1694432361423 } from './1694432361423-AddAnalytic'
import { AddChatHistory1694658756136 } from './1694658756136-AddChatHistory'
export const postgresMigrations = [
Init1693891895163,
@@ -13,5 +14,6 @@ export const postgresMigrations = [
ModifyCredential1693997070000,
ModifyTool1693997339912,
AddApiConfig1694099183389,
AddAnalytic1694432361423
AddAnalytic1694432361423,
AddChatHistory1694658756136
]
@@ -0,0 +1,15 @@
import { MigrationInterface, QueryRunner } from 'typeorm'
export class AddChatHistory1694657778173 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "chat_message" ADD COLUMN "chatType" VARCHAR NOT NULL DEFAULT 'INTERNAL';`)
await queryRunner.query(`ALTER TABLE "chat_message" ADD COLUMN "memoryType" VARCHAR;`)
await queryRunner.query(`ALTER TABLE "chat_message" ADD COLUMN "sessionId" VARCHAR;`)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "chat_message" DROP COLUMN "chatType";`)
await queryRunner.query(`ALTER TABLE "chat_message" DROP COLUMN "memoryType";`)
await queryRunner.query(`ALTER TABLE "chat_message" DROP COLUMN "sessionId";`)
}
}
@@ -5,6 +5,7 @@ import { ModifyCredential1693923551694 } from './1693923551694-ModifyCredential'
import { ModifyTool1693924207475 } from './1693924207475-ModifyTool'
import { AddApiConfig1694090982460 } from './1694090982460-AddApiConfig'
import { AddAnalytic1694432361423 } from './1694432361423-AddAnalytic'
import { AddChatHistory1694657778173 } from './1694657778173-AddChatHistory'
export const sqliteMigrations = [
Init1693835579790,
@@ -13,5 +14,6 @@ export const sqliteMigrations = [
ModifyCredential1693923551694,
ModifyTool1693924207475,
AddApiConfig1694090982460,
AddAnalytic1694432361423
AddAnalytic1694432361423,
AddChatHistory1694657778173
]