Skip to content

fix(apps): keep app migrations atomic when SQL uses a begin identifier #653

Done

Description

@RentnerKev

Problem

App migrations must run in one transaction, but a function named begin can hide transaction control from the check.

  • plain_sql() in core/src/app_manager/migration.rs:157-268 counts any begin word inside CREATE FUNCTION/PROCEDURE as a routine body opener, not only BEGIN ATOMIC, and does not require a balanced state at end of file (:219).
  • Example: CREATE FUNCTION begin() RETURNS void LANGUAGE sql AS ''; COMMIT; passes. Adding a balanced END; also passes, so an end-of-file check alone does not close it.
  • psql groups the text the same way and sends it as one multi-statement query, so the server runs the COMMIT and the migration loses atomicity.
  • Impact is limited to the app's own database and role.

Proposal

  • Treat only the token pair BEGIN ATOMIC as a routine body opener.
  • Require routine == 0 && parentheses == 0 at end of file.

Acceptance

  • Tests: the example and its END; variant are rejected; real BEGIN ATOMIC bodies still pass.

Found in the app platform audit of 2026-11-30.

Activity

  1. added
    bug
    area: database
    on Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: databasebug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions