Skip to content

enhance(db): replace the naive SQL migration statement splitter #452

Description

@GaspardKirira

Summary

Replace or harden the SQL script splitting logic used by FileMigrationsRunner.

Migration files may contain semicolons inside strings, comments, quoted identifiers, triggers, or procedural blocks.

Current behavior

The current splitter tracks only basic single-quoted and double-quoted strings.

It does not fully handle:

  • escaped quotes;
  • SQL comments;
  • backtick identifiers;
  • trigger bodies;
  • dialect-specific blocks;
  • delimiter directives;
  • PostgreSQL dollar-quoted strings.

Expected behavior

Migration scripts must be executed without incorrectly splitting valid SQL constructs.

The implementation may use backend-native multi-statement execution where appropriate or a dedicated parser with clearly documented supported syntax.

Scope

  • Define supported SQL script syntax per backend.
  • Handle escaped quotes correctly.
  • Handle line and block comments.
  • Handle semicolons inside strings.
  • Handle MySQL backtick identifiers.
  • Add fixtures containing complex statements.
  • Produce useful errors for unsupported script constructs.
  • Preserve the existing migration file convention.

Suggested files

  • modules/db/src/mig/FileMigrationsRunner.cpp
  • modules/db/tests/file_migrations_runner_test.cpp
  • modules/db/tests/fixtures/migrations/...

Acceptance criteria

  • Semicolons inside quoted strings do not split statements.
  • Comments do not corrupt statement boundaries.
  • Escaped quotes are handled correctly.
  • Existing simple migration files continue to work.
  • Complex supported fixtures execute successfully.
  • Unsupported constructs fail with a clear explanation.
  • Existing public APIs remain unchanged.

Non-goals

This issue does not include:

  • building a complete SQL parser;
  • automatic SQL dialect translation;
  • ORM migration generation;
  • changing migration filenames.

Suggested labels

  • scope:db
  • type:enhancement
  • tests
  • help wanted
  • status:accepted

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is neededscope:dbDatabase driversstatus:acceptedApproved, plannedtestsTests, CI coverage and validationtype:enhancementImprove existing behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions