Skip to content

fix(db): generate table indexes when creating a new MySQL table #454

Description

@GaspardKirira

Summary

Ensure indexes declared on a newly created schema table are included in generated MySQL migrations.

Current behavior

When a table exists only in the target schema, the diff engine emits a single CreateTable operation.

The MySQL create-table generator emits columns and one primary key, but does not emit the table's declared indexes.

Because the diff stops after CreateTable, separate CreateIndex operations are not generated for that new table.

Expected behavior

Creating a new table must also create all indexes declared in its schema definition.

Generated down migrations must continue to remove the table safely.

Scope

  • Generate normal indexes for newly created tables.
  • Generate unique indexes.
  • Support multi-column indexes.
  • Preserve deterministic index ordering.
  • Add golden SQL tests.
  • Preserve the existing schema and migration APIs.

Suggested files

  • modules/db/src/mig/sql/MySqlGenerator.cpp
  • modules/db/tests/mysql_generator_test.cpp
  • modules/db/tests/golden/...

Acceptance criteria

  • A new table with one index creates that index.
  • A new table with multiple indexes creates all of them.
  • Unique indexes use valid MySQL syntax.
  • Multi-column index order is preserved.
  • Tables without indexes retain valid output.
  • Down migration remains valid.
  • Existing public APIs remain unchanged.

Non-goals

This issue does not include:

  • foreign keys;
  • full-text indexes;
  • index prefixes;
  • expression indexes;
  • SQLite SQL generation.

Suggested labels

  • scope:db
  • type:bug
  • tests
  • good first issue
  • status:ready

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomersscope:dbDatabase driversstatus:readyIssue is fully specified and ready for implementationtestsTests, CI coverage and validationtype:bugIncorrect behavior, crash, or regression

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions