feat: implement topological dependency planner#14
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Free Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Note 🎁 Summarized by CodeRabbit FreeYour organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login. Comment |
This pull request introduces new logic for handling table dependency resolution in the presence of foreign key cycles and blocked tables in the planner package. The changes implement robust algorithms (including Tarjan's strongly connected components and Kahn's topological sort) to analyze and resolve cycles, identify blocked tables, and determine a valid generation order for tables based on their dependencies.
The most important changes are:
Cycle Detection and Resolution:
cycles.gowith functions to detect strongly connected components (cycles) using Tarjan's algorithm, determine true cycles, and resolve them by identifying nullable foreign key breakpoints and producing table generation plans that defer certain foreign keys when necessary.Topological Sorting and Blocked Table Handling:
topsort.goimplementing Kahn’s algorithm for topological sorting of tables by their foreign key dependencies, and for identifying tables that are blocked or involved in cycles.blocked.goto process tables that are blocked (not in a true cycle but dependent on unresolved cycles), allowing them to be generated once their dependencies are resolved, and reporting errors if any remain unresolvable.## What does this PR do?Why is it needed?
Closes #
How was it tested?
Does it change any existing behavior?
Checklist
make testpasses (go test ./... -race)make lintpasses (golangci-lint run ./...)time.Now()or unseeded randomness in the generation pipelinemake test-golden UPDATE=true)