fix: parse SQL migration comments safely
This commit is contained in:
1 parent
8d37ae9ae0
commit
c4454a292c
3 files changed
+30
-4
No files matched your search
@@ -0,0 +1,18 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { splitSqlStatements } from "./sql-statements";
|
||||
|
||||
describe("splitSqlStatements", () => {
|
||||
it("ignores semicolons inside line comments", () => {
|
||||
const sql = [
|
||||
"-- Existing installs have this; new installs need it.",
|
||||
"ALTER TABLE users ADD COLUMN IF NOT EXISTS example TEXT NULL;",
|
||||
"-- next statement",
|
||||
"CREATE TABLE IF NOT EXISTS example_table (id INT PRIMARY KEY);",
|
||||
].join("\n");
|
||||
|
||||
expect(splitSqlStatements(sql)).toEqual([
|
||||
"ALTER TABLE users ADD COLUMN IF NOT EXISTS example TEXT NULL",
|
||||
"CREATE TABLE IF NOT EXISTS example_table (id INT PRIMARY KEY)",
|
||||
]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user