Skip to content

fix diff for auto named indexes#646

Merged
morgo merged 1 commit intoblock:mainfrom
morgo:fix-diff-indexes
Mar 2, 2026
Merged

fix diff for auto named indexes#646
morgo merged 1 commit intoblock:mainfrom
morgo:fix-diff-indexes

Conversation

@morgo
Copy link
Collaborator

@morgo morgo commented Mar 2, 2026

A Pull Request should be associated with an Issue.

We wish to have discussions in Issues. A single issue may be targeted by multiple PRs.
If you're offering a new feature or fixing anything, we'd like to know beforehand in Issues,
and potentially we'll be able to point development in a particular direction.
Further notes in https://github.com/block/spirit/blob/main/.github/CONTRIBUTING.md

Fixes #645

Copy link
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 fixes schema diff generation when indexes are declared without an explicit name (e.g., INDEX (col)), by normalizing them to MySQL’s default auto-naming behavior so diffs match what SHOW CREATE TABLE returns.

Changes:

  • Auto-assign names to unnamed (non-PRIMARY) indexes during CREATE TABLE parsing using MySQL’s “first column + optional _2/_3…” convention.
  • Adjust ALTER TABLE ... ADD INDEX formatting to safely omit index names when empty (as a fallback).
  • Add/adjust tests to validate unnamed-index normalization and diff behavior (including duplicates and UNIQUE).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
pkg/statement/parse_create_table.go Auto-names unnamed indexes during parsing to match MySQL normalization.
pkg/statement/parse_create_table_test.go Updates expectations for unnamed index names in parsing tests.
pkg/statement/diff.go Updates ADD INDEX formatting to not emit empty backticked names.
pkg/statement/diff_test.go Adds coverage for unnamed index normalization and diff stability.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@morgo morgo requested a review from aparajon March 2, 2026 21:41
@morgo morgo merged commit b4c6e6e into block:main Mar 2, 2026
14 checks passed
@morgo morgo deleted the fix-diff-indexes branch March 2, 2026 22:01
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.

Diff on auto-named indexes is incorrect

3 participants