Skip to content

statement: order DeclarativeToImperative output as CREATE → ALTER → DROP#734

Merged
morgo merged 2 commits into
block:mainfrom
morgo:fix-declarative-ordering
Apr 30, 2026
Merged

statement: order DeclarativeToImperative output as CREATE → ALTER → DROP#734
morgo merged 2 commits into
block:mainfrom
morgo:fix-declarative-ordering

Conversation

@morgo
Copy link
Copy Markdown
Collaborator

@morgo morgo commented Apr 30, 2026

Summary

Orders the output of DeclarativeToImperative as 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

  • Split the single changes slice into separate creates and alters slices
  • Combined them as creates + alters + drops at the end
  • Updated the existing ordering test to verify the three-phase ordering

Fixes #671

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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, and drops buckets.
  • 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.

@morgo morgo enabled auto-merge April 30, 2026 23:23
@morgo morgo merged commit 329dbbe into block:main Apr 30, 2026
12 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DeclarativeToImperative: order output as CREATE → ALTER → DROP

3 participants