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:
parent
7ff012cd91
commit
89955f6db8
|
|
@ -28,11 +28,16 @@ export class TenantProvisioningService {
|
||||||
let sql = fs.readFileSync(templatePath, 'utf-8');
|
let sql = fs.readFileSync(templatePath, 'utf-8');
|
||||||
sql = sql.replace(/{TENANT_ID}/g, tenantId);
|
sql = sql.replace(/{TENANT_ID}/g, tenantId);
|
||||||
|
|
||||||
// Split by semicolon and execute statements individually
|
// Remove comment lines, then split by semicolon
|
||||||
const statements = sql
|
const cleanedSql = sql
|
||||||
|
.split('\n')
|
||||||
|
.filter((line) => !line.trimStart().startsWith('--'))
|
||||||
|
.join('\n');
|
||||||
|
|
||||||
|
const statements = cleanedSql
|
||||||
.split(';')
|
.split(';')
|
||||||
.map((s) => s.trim())
|
.map((s) => s.trim())
|
||||||
.filter((s) => s.length > 0 && !s.startsWith('--'));
|
.filter((s) => s.length > 0);
|
||||||
|
|
||||||
for (const stmt of statements) {
|
for (const stmt of statements) {
|
||||||
await queryRunner.query(stmt);
|
await queryRunner.query(stmt);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue