fix: parse SQL migration comments safely

This commit is contained in:
Simo committed 2026-07-11 21:27:18 +02:00
1 parent 8d37ae9ae0
commit c4454a292c
3 files changed
+30 -4

No files matched your search

+2 -4
View File
@@ -1,6 +1,7 @@
import { readFileSync, readdirSync } from "node:fs";
import { resolve, dirname } from "node:path";
import { fileURLToPath } from "node:url";
import { splitSqlStatements } from "./sql-statements";
const __dirname = dirname(fileURLToPath(import.meta.url));
const MIGRATIONS_DIR = resolve(__dirname, "../prisma/migrations");
@@ -68,10 +69,7 @@ async function apply(migration: MigrationFile): Promise<void> {
const mysql = await import("mysql2/promise");
const conn = await mysql.createConnection(url);
try {
const statements = migration.sql
.split(";")
.map((s) => s.trim())
.filter((s) => s.length > 0 && !s.startsWith("--"));
const statements = splitSqlStatements(migration.sql);
for (const stmt of statements) {
await conn.execute(stmt);