From 67e14e357c80aa03936fabe2f585d811538f2d3e Mon Sep 17 00:00:00 2001 From: wangziqi Date: Wed, 5 Aug 2026 22:26:14 +0800 Subject: [PATCH] =?UTF-8?q?fix(imports):=20=E5=AF=BC=E5=85=A5=E5=90=91?= =?UTF-8?q?=E5=AF=BC=20sheets=5Fjson=20=E6=89=A9=E5=AE=B9=E4=B8=BA=20MEDIU?= =?UTF-8?q?MTEXT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit start_import_wizard 存整表行数据,TEXT(64KB) 在 430 行文件上触发 Data too long for column 'sheets_json',扩容至 MEDIUMTEXT(16MB) 并补迁移 (实际表名 import_runs,原迁移误写 import_run 导致空跑) --- .../src/imports/entities/import-run.entity.ts | 2 +- .../1786000000000-WidenImportSheetsJson.ts | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 apps/server/src/migrations/1786000000000-WidenImportSheetsJson.ts diff --git a/apps/server/src/imports/entities/import-run.entity.ts b/apps/server/src/imports/entities/import-run.entity.ts index d7d03c7..6654311 100644 --- a/apps/server/src/imports/entities/import-run.entity.ts +++ b/apps/server/src/imports/entities/import-run.entity.ts @@ -20,7 +20,7 @@ export class ImportRun { fileName: string; /** Serialized sheet data — parsed rows are kept here for v1. */ - @Column({ name: 'sheets_json', type: 'text' }) + @Column({ name: 'sheets_json', type: 'mediumtext' }) sheetsJson: string; /** Serialized ImportRunSettings — confirmed mapping/policies from AI preflight. */ diff --git a/apps/server/src/migrations/1786000000000-WidenImportSheetsJson.ts b/apps/server/src/migrations/1786000000000-WidenImportSheetsJson.ts new file mode 100644 index 0000000..715fee8 --- /dev/null +++ b/apps/server/src/migrations/1786000000000-WidenImportSheetsJson.ts @@ -0,0 +1,25 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +/** + * 导入向导的 sheets_json 存整表行数据(最多 6 张工作表、数百行), + * TEXT(64KB)不够用会导致 start_import_wizard 报 + * “Data too long for column 'sheets_json'”,扩容为 MEDIUMTEXT(16MB)。 + */ +export class WidenImportSheetsJson1786000000000 implements MigrationInterface { + async up(queryRunner: QueryRunner): Promise { + if (!(await queryRunner.hasTable('import_runs'))) return; + const rows = await queryRunner.query( + `SELECT DATA_TYPE FROM information_schema.COLUMNS + WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'import_runs' AND COLUMN_NAME = 'sheets_json'`, + ); + const current = rows?.[0]?.DATA_TYPE as string | undefined; + if (current && current.toLowerCase() !== 'mediumtext') { + await queryRunner.query('ALTER TABLE `import_runs` MODIFY COLUMN `sheets_json` MEDIUMTEXT'); + } + } + + async down(queryRunner: QueryRunner): Promise { + if (!(await queryRunner.hasTable('import_runs'))) return; + await queryRunner.query('ALTER TABLE `import_runs` MODIFY COLUMN `sheets_json` TEXT'); + } +}