Skip to content

Commit 75260d8

Browse files
CodingAnarchyclaude
andcommitted
fix: Fix PostgreSQL migration SQL parsing with dollar-quoted strings
This release fixes critical bugs in the PostgreSQL migration runner that were causing "unterminated dollar-quoted string" errors when executing migrations containing PL/pgSQL functions with dollar-quoted string literals. ## Key Fixes ### Enhanced SQL Parsing Logic - Fixed `split_sql_respecting_quotes` function to properly handle empty dollar tags (`$$...$$`) - Improved comment filtering to distinguish SQL statements from comment-only blocks - Enhanced parsing of complex nested structures in dollar-quoted contexts ### Migration 014 Fix - Resolved "unterminated dollar-quoted string" error in migration 014 - Fixed parsing of PL/pgSQL function definitions with dollar-quoted bodies - Ensured proper trigger and function creation statements are executed correctly ### Comprehensive Test Coverage - Added `test_migration_012_sql_parsing` to validate complex transaction parsing - Added `test_migration_014_sql_parsing` to validate dollar-quoted function parsing - Added `test_dollar_quoted_string_parsing` for general dollar-quote validation - Ensured `sqlparser-rs` integration works correctly with PostgreSQL features ## Validation - All 22 statements in migration 012 now parse correctly - All 5 statements in migration 014 now parse correctly including PL/pgSQL functions - Complex SQL features validated: CASE expressions, subqueries, UUID arrays, constraints 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 478a3d8 commit 75260d8

File tree

6 files changed

+348
-19
lines changed

6 files changed

+348
-19
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [1.15.2] - 2025-01-25
11+
12+
### Fixed
13+
- **🔧 SQL Migration Parsing Improvements**
14+
- Fixed critical bug in PostgreSQL migration runner where dollar-quoted strings (`$$...$$`) were not properly parsed
15+
- Enhanced `split_sql_respecting_quotes` function to correctly handle empty dollar tags and complex nested structures
16+
- Improved comment filtering logic to properly distinguish between comment-only blocks and executable SQL statements
17+
- Fixed migration 014 execution which was failing with "unterminated dollar-quoted string" errors
18+
- Added comprehensive test coverage for both migration 012 and 014 SQL parsing validation
19+
- Validated complex SQL structures including PL/pgSQL functions, multi-line CASE expressions, and transaction blocks
20+
- Ensured `sqlparser-rs` integration works correctly with PostgreSQL-specific syntax features
21+
1022
## [1.15.1] - 2025-01-23
1123

1224
### Added

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ members = [
99
resolver = "2"
1010

1111
[workspace.package]
12-
version = "1.15.1"
12+
version = "1.15.2"
1313
edition = "2024"
1414
license = "MIT"
1515
repository = "https://github.com/CodingAnarchy/hammerwork"

hammerwork-web/src/api/archive.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,7 @@ where
406406
// If we got exactly the limit, there might be more records
407407
// Run another query to get a better count estimate
408408
match queue
409-
.list_archived_jobs(
410-
filters.queue.as_deref(),
411-
Some(10000),
412-
Some(0),
413-
)
409+
.list_archived_jobs(filters.queue.as_deref(), Some(10000), Some(0))
414410
.await
415411
{
416412
Ok(all_jobs) => all_jobs.len() as u64,
@@ -481,10 +477,7 @@ where
481477
if request.dry_run {
482478
// For dry run, estimate how many jobs would be purged by using list_archived_jobs
483479
// with a large limit to get an accurate count
484-
let count = match queue
485-
.list_archived_jobs(None, Some(10000), Some(0))
486-
.await
487-
{
480+
let count = match queue.list_archived_jobs(None, Some(10000), Some(0)).await {
488481
Ok(jobs) => jobs.len() as u64,
489482
Err(_) => 0, // If we can't get the count, return 0 for safety
490483
};

src/migrations/mysql.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ use sqlx::{MySqlPool, Row};
88
use tracing::{debug, info, warn};
99

1010
/// Parse SQL text into individual statements using sqlparser-rs for MySQL
11-
fn parse_mysql_statements(sql: &str) -> std::result::Result<Vec<String>, sqlparser::parser::ParserError> {
11+
fn parse_mysql_statements(
12+
sql: &str,
13+
) -> std::result::Result<Vec<String>, sqlparser::parser::ParserError> {
1214
let dialect = MySqlDialect {};
1315

1416
match Parser::parse_sql(&dialect, sql) {

0 commit comments

Comments
 (0)