Skip to content

Commit

Permalink
fix: correctly handle statement semicolons in triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
RihanArfan committed Feb 2, 2025
1 parent 954c6c3 commit d9e1da0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/runtime/database/server/utils/migrations/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,10 @@ export function splitSqlQueries(sqlFileContent: string): string[] {
// Process each query to ensure it ends with a single semicolon and filter out empty/semicolon-only
return queries
.map((query) => {
if (!query.endsWith(';')) {
query += ';'
// Handle semicolons in trigger bodies
if (query.includes('TRIGGER') && query.includes('BEGIN')) {
// First, handle the statements inside the trigger
query = query.replace(/;+(?=\s+(?:END|\S|$))/g, ';')
}
return query.replace(/;+$/, ';')
})
Expand Down

0 comments on commit d9e1da0

Please sign in to comment.