statement: order DeclarativeToImperative output as CREATE → ALTER → DROP#734
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates DeclarativeToImperative statement ordering to emit DDL in three deterministic phases—CREATE → ALTER → DROP—to avoid dependency issues when sequentially executing diffs (notably when ALTERs reference newly created tables).
Changes:
- Split accumulated statements into
creates,alters, anddropsbuckets. - Emit the final result as
creates + alters + drops(each bucket already deterministic via name sorting). - Update the existing ordering test to assert strict three-phase ordering.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/statement/declarative.go | Changes output ordering to CREATE-first, then ALTER, then DROP. |
| pkg/statement/declarative_test.go | Updates ordering test to validate CREATE → ALTER → DROP sequencing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
aparajon
approved these changes
Apr 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Orders the output of
DeclarativeToImperativeas CREATE → ALTER → DROP instead of the previous behavior where CREATEs and ALTERs were interleaved alphabetically.Motivation
When a diff produces both CREATE TABLE and ALTER TABLE statements, the ALTER may reference the newly-created table (e.g., adding a foreign key to a new table). By ensuring CREATEs come first, the output is safe to execute sequentially without dependency issues.
Changes
changesslice into separatecreatesandaltersslicescreates + alters + dropsat the endFixes #671