Purpose
Make table discovery and metadata validation follow the DDL body actually rendered after AST mutation. For example, adding a column to an ALTER action that still stores an earlier foreign key renders ADD added INT, but currently table discovery and validation still use the inactive foreign table and key columns.
Current design (As-is)
Rendering selects one body, while traversal and metadata validation independently visit stored definitions, defaults and column options. This leaks inactive state into consumers. A CHECK option changed to FOREIGN_OPTIONS can also retain its old constraint node and incorrectly traverse that expression.
Target design (To-be)
- Share active-definition selection through
getActiveTableDefinition() and the body-selection hooks introduced in Fix ALTER deparser dispatch for inactive column metadata #2770.
- Traverse active defaults, columns, constraints and indexes, while preserving the expression/table children of specialized ALTER bodies.
- Validate only the selected structured definitions and key columns. Keep stored metadata accessible through existing getters.
- Respect the active
ColumnOption.Kind, partial legacy constraint headers, identity actions and dedicated primary-key/partition/relation bodies.
- Document the stored-versus-active distinction and dispatch hooks for custom subclasses.
This refactoring changes consumer behavior after AST mutation; it adds no SQL syntax or database validity rules.
Rebase
#2770, which this PR previously included, and #2776 are now merged. The branch is rebased onto master (bdf8ac31) and contains only its own commit.
Validation
- Regression tests compare rendered SQL, custom traversal callbacks, table-name discovery and metadata validation after mutations. Active foreign keys and specialized bodies retain their required children; inactive definitions stay accessible without being visited.
- Java 17 offline Gradle
spotlessApply check after rebasing onto master (bdf8ac31): 10,368 tests, 10,343 passed, 25 skipped, zero failures/errors. Grammar, Checkstyle, PMD, SpotBugs and coverage checks pass.
- Default PMD comparison against the previous base (
066f581e): existing findings decrease from 13 to 8, with no new findings or suppression/threshold changes.
Integration validation
Applied #2770, #2771 and all four follow-ups (#2775–#2778) together on master (066f581e), resolving overlapping validator edits while preserving their respective behavior. The integrated build passes Java 17 offline Gradle spotlessApply check: 10,141 tests, 10,116 passed, 25 skipped, zero failures/errors. The combined ALTER validator has zero findings under the default PMD complexity and field-placement rules.
Replayed 882 previously DB-validated MySQL/PostgreSQL DDL fixtures: 875 pass and the same seven existing parse gaps remain. SQL output, reparsing and AST node-type sets match the preceding integration baseline, with no new differences. This replay did not rerun the databases.
The published head passes grammar checks, Gradle and Maven on Ubuntu/Windows/macOS, and Codacy. Deployment-only jobs are skipped as expected for a PR.