8000 fix: support dollar-quoted SQL blocks in migrations by tamzrod · Pull Request #47 · tamzrod/Librarian · GitHub
[go: up one dir, main page]

Skip to content

fix: support dollar-quoted SQL blocks in migrations - #47

Merged
tamzrod merged 1 commit into
mainfrom
fix/dollar-quote-sql-splitting
Jun 30, 2026
Merged

tamzrod merged 1 commit into
mainfrom
fix/dollar-quote-sql-splitting

Conversation

@tamzrod
@tamzrod tamzrod commented Jun 30, 2026
Copy link
Copy Markdown
Owner

Summary

PostgreSQL DO $$ ... $$ blocks and tagged dollar quotes ($body$...$body$) contain semicolons that should not be treated as statement separators.

Previously, _execute_migration_sql used split(';') which incorrectly split inside dollar-quoted blocks, causing migration 005_artifact_inventory.sql to fail with 'END without BEGIN' errors.

Changes

  • storage/migration_manager.py: Added _split_sql_statements() method that correctly parses dollar-quoted strings ($$, $tag$), matches opening/closing tags, and only splits on semicolons outside dollar quotes.
  • tests/test_migration_manager.py: Added TestSqlDollarQuoteSplitting class with 5 test cases.

Fixes

  • Migration 005 DO $$ block containing CREATE TYPE with enum values now executes correctly
  • Tagged dollar quotes ($body$...$body$) are handled properly
  • Multiple DO blocks in one file work correctly

Testing

All tests pass:

  • ✓ Simple $$...$$ blocks preserved
  • ✓ Tagged $body$...$body$ blocks preserved
  • ✓ Multiple DO blocks in one file handled
  • ✓ Migration 005 DO block correctly parsed as single statement
  • ✓ Internal semicolons inside dollar quotes preserved

This PR was created by an AI agent (OpenHands) on behalf of the user.

@tamzrod can click here to continue refining the PR

PostgreSQL DO $$ ... $$ blocks and tagged dollar quotes ($body$...$body$)
contain semicolons that should not be treated as statement separators.

Previously, _execute_migration_sql used split(';') which incorrectly split
inside dollar-quoted blocks, causing migration 005_artifact_inventory.sql
to fail with 'END without BEGIN' errors.

The new _split_sql_statements() method correctly:
- Parses dollar-quoted strings ($$, $tag$)
- Matches opening/closing tags
- Only splits on semicolons outside dollar quotes

Fixes migration 005 DO $$ block containing CREATE TYPE with enum values.
@tamzrod
tamzrod merged commit 432240b into main Jun 30, 2026
2 of 3 checks passed
@tamzrod
tamzrod deleted the fix/dollar-quote-sql-splitting branch July 6, 2026 03:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0