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 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-02-22 03:26:37 -08:00
parent 7ff012cd91
commit 89955f6db8
1 changed files with 8 additions and 3 deletions

View File

@ -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);