Skip to content

fix(migrations): parse arithmetic CHECK constraints - #2178

Open
Zxf-xufeng wants to merge 2 commits into
masterfrom
codex/fix-2160-check-arithmetic
Open

Zxf-xufeng wants to merge 2 commits into
masterfrom
codex/fix-2160-check-arithmetic

Conversation

@Zxf-xufeng

@Zxf-xufeng Zxf-xufeng commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Which issue or RFC does this PR close?

Closes #2160.

Rationale for this change

Schema reflection rejected PowerContext's own pc_recall_effort_daily CHECK (dropped_items = dropped_below_min_bytes + dropped_no_fitting_truncation) as having unbalanced parentheses. The lexer recognized addition, but the expression parser stopped before it, preventing migration status from reaching layout identification.

What changes are included in this PR?

  • Parse binary +, -, *, /, and % with arithmetic precedence above comparisons and boolean operations. Preserve left associativity, unary signs, and nested grouping when rendering validation SQL.
  • Parse balanced subexpressions independently. Unsupported CHECK syntax reports table, named constraint, and construct context without echoing string literals.
  • Execute parameter-free CHECK validation SQL with statement-scoped no_parameters=True, so the MySQL driver preserves remainder operators and percent signs inside literals. Constraint violations still raise data_integrity_error.
  • Add actual seekDB SHOW CREATE TABLE fixtures for three tables recreated from the 1.3.0 tag's metadata and limits, recording source blob IDs, compiler/binding versions, and engine version.
  • Cover expression semantics, malformed/unsupported syntax, historical reflection, and real seekDB execution. Real-driver regressions exercise both MySQLSchema.validate_data() and MySQLMigrationRunner.plan() for remainder and percent-literal CHECKs, including valid, NULL, and invalid stored values.
  • Include the CHECK test module in the existing real seekDB CI job for Python 3.11 and 3.14. Document parser behavior and fixture provenance.

Are there any user-facing changes?

Migration schema inspection can parse the reported arithmetic CHECK and continue to the actual baseline/support decision. Unsupported CHECK expressions report useful schema context; remainder validation no longer fails in driver parameter interpolation.

There are no API, persisted-schema, dependency, or migration-baseline changes. No tables or constraints are excluded. Successful reflection does not enable upgrades of unregistered complete Server layouts or bypass revision verification, recovery eligibility, and data-integrity checks.

How was this change tested?

  • Reproduced TypeError: not enough arguments for format string on the original PR head through the real seekDB aiomysql bridge for both a remainder CHECK and a percent-containing string literal.
  • POWERCONTEXT_TEST_MIGRATION_SEEKDB=1 .venv/bin/python -m pytest -q tests/builtin/persistence/test_mysql_migration_checks.py tests/builtin/persistence/test_mysql_migration_schema.py --tb=short — 58 passed.
  • .venv/bin/python -m pytest -q tests/builtin/persistence/test_*migration*.py tests/test_database_migration*.py tests/test_processing_migration_cli.py --tb=short — 164 passed, 33 skipped (opt-in backend tests).
  • UV_NO_SYNC=1 UV_PYTHON=3.14 make check — passed, including lock consistency, all pre-commit hooks, type checks, workflow/integration consistency, and 50 integration-manifest tests.
  • Confirmed that the CI -k seekdb selector includes both new driver regressions and the historical CHECK tests.

Local validation used macOS, Python 3.14.6, SQLAlchemy 2.0.51, aiomysql 0.3.2, and pylibseekdb 1.4.0.post1. The historical fixture was captured on seekDB v1.4.0.0 using 1.3.0 definitions; it is not a customer database or a reproduction of a complete customer upgrade. No live OceanBase test was run. CI results must be checked separately.

AI usage statement

OpenAI Codex inspected the issue and migration contracts, implemented the parser and driver fixes, added regression coverage and CI selection, and ran local validation and a full diff review.

@Zxf-xufeng
Zxf-xufeng requested a review from hidb4ai October 21, 2026 13:35
@AlexStocks AlexStocks added the 1.4.1 v1.4.1 release tracking label Oct 21, 2026

@hidb4ai hidb4ai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reported addition case is fixed. One issue remains in the newly added remainder support; details inline.

Comment thread src/powercontext/builtin/persistence/migrations/mysql_schema.py

@hidb4ai hidb4ai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1.4.1 v1.4.1 release tracking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(migrations): parse arithmetic CHECK constraints and report actionable schema errors

3 participants