From 89955f6db87eb5d90015c224ba73c2b93273d321 Mon Sep 17 00:00:00 2001 From: hailin Date: Sun, 22 Feb 2026 03:26:37 -0800 Subject: [PATCH] fix: remove SQL comment lines before splitting to prevent filtering CREATE TABLE statements The previous approach split by semicolons then filtered statements starting with '--', which incorrectly removed entire CREATE TABLE blocks that had comment headers (e.g., '-- Agent Sessions\nCREATE TABLE...'). Co-Authored-By: Claude Opus 4.6 --- .../database/src/tenant-provisioning.service.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/shared/database/src/tenant-provisioning.service.ts b/packages/shared/database/src/tenant-provisioning.service.ts index 3115616..5da913a 100644 --- a/packages/shared/database/src/tenant-provisioning.service.ts +++ b/packages/shared/database/src/tenant-provisioning.service.ts @@ -28,11 +28,16 @@ export class TenantProvisioningService { let sql = fs.readFileSync(templatePath, 'utf-8'); sql = sql.replace(/{TENANT_ID}/g, tenantId); - // Split by semicolon and execute statements individually - const statements = sql + // Remove comment lines, then split by semicolon + const cleanedSql = sql + .split('\n') + .filter((line) => !line.trimStart().startsWith('--')) + .join('\n'); + + const statements = cleanedSql .split(';') .map((s) => s.trim()) - .filter((s) => s.length > 0 && !s.startsWith('--')); + .filter((s) => s.length > 0); for (const stmt of statements) { await queryRunner.query(stmt);