Skip to content

fix(upgrade): drop morph indexes before columns and baseline 000071 - #2713

Open
wychoong wants to merge 6 commits into
lunarphp:2.xfrom
wychoong:fix/upgrade-v1-schema
Open

fix(upgrade): drop morph indexes before columns and baseline 000071#2713
wychoong wants to merge 6 commits into
lunarphp:2.xfrom
wychoong:fix/upgrade-v1-schema

Conversation

@wychoong

@wychoong wychoong commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Stacked on #2712.

The new upgrade-path workflow currently fails on every driver. This PR is the package-side fix so that workflow can go green.

Attribute morph indexes

v1 indexes attribute_groups.attributable_type and attributes.attribute_type (plus unique (attribute_type, handle)). 2026_06_01_000003 drops those columns without dropping the indexes first.

  • SQLite: DROP COLUMN fails while the index remains
  • MariaDB: error 1072 (Key column doesn't exist in table)
  • MySQL 8 / Postgres: the data step already succeeds

Drop the indexes (when present) immediately before dropColumn.

Product-types tax-class FK

2026_06_01_000011 adds product_types.default_tax_class_id and its foreign key. Core 2026_01_01_000071 only adds the constraint, for fresh installs whose create migration cannot reference tax_classes yet.

000071 is missing from ledger.v2_baseline, so after ledger-rewrite php artisan migrate runs it again and MySQL/Postgres error on a duplicate FK. Same treatment 000059 already gets. This is the one-line change from #2605.

Test plan

Made with Cursor

wychoong and others added 5 commits September 4, 2026 02:26
MariaDB and SQLite refuse DROP COLUMN while the v1 attribute morph
indexes remain. The product-types tax-class FK is already created by
the upgrade data step, so 000071 belongs in v2_baseline like 000059.

Co-authored-by: Cursor <cursoragent@cursor.com>
Schema::hasIndex(..., 'index') misses SQLite, which reports btree.
Core-only v1 never created staff, but v2 still marked create_staff as
run, so later core staff migrations altered a missing table.

Co-authored-by: Cursor <cursoragent@cursor.com>

return Schema::connection($connection)->hasTable(
config('lunar.database.table_prefix').'staff',
);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

in v1 staff is in panel package, so there is a chance someone using lunarphp for core without panel


/**
* Drop a v1 index by its live name. `Schema::hasIndex(..., 'index')` misses
* SQLite, which reports the type as `btree` rather than `index`.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

seems a few more sqlite specific issue, not sure worth handling for upgrade command as unlikely anyone using it for prod

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

1 participant