Skip to content

fix(migrations): drop double table_prefix in Phinx hasTable/table calls (#276)#277

Merged
biz87 merged 1 commit into
betafrom
fix/276-seed-migration-double-prefix
May 20, 2026
Merged

fix(migrations): drop double table_prefix in Phinx hasTable/table calls (#276)#277
biz87 merged 1 commit into
betafrom
fix/276-seed-migration-double-prefix

Conversation

@biz87
Copy link
Copy Markdown
Member

@biz87 biz87 commented May 20, 2026

Описание

В PR #271 defensive-checks для ms3_grid_fields написаны с ручным префиксом:

$prefix = $this->getAdapter()->getOption('table_prefix') ?? '';
if (!$this->hasTable($prefix . 'ms3_grid_fields')) { return; }

TablePrefixAdapter::hasTable($name) сам добавляет table_prefix внутри — итого Phinx искал modx_modx_ms3_grid_fields, не находил, миграция уходила в no-op. То же касается $this->table($name) / hasColumn.

Тип изменений

  • Исправление бага
  • Новая функциональность
  • Breaking change
  • Рефакторинг

Связанные Issues

Closes #276
Refs #270 (root cause defensive checks для пользователей не работали)

Воздействие

  • Свежие установки MS3 ≥ 1.10.1: ms3_grid_fields создавалась через initial_schema, но из-за двойного префикса в defensive-checks не наполнялась. Гриды (заказы, клиенты, доставки, оплаты, вендоры, позиции, товары категории) загружались без default-конфигурации.
  • Существующие установки с прошедшим seed до fix(migrations): defensive checks for ms3_grid_fields table #271: уже отмечены в phinxlog, не затронуты.
  • initial_schema::addForeignKeys(): тот же баг — FK constraints никогда не создавались на свежих установках.

Состав

Поправлены 10 миграций (9 затронутых #271 + initial_schema):

  • 20251020000000_initial_schema.phpaddForeignKeys() (hasTable + $this->table + addForeignKey target) и down() drop loop.
  • 20251127000002_seed_customers_grid_config.php
  • 20251204140000_seed_orders_grid_config.php
  • 20251215120000_seed_order_products_grid_config.php
  • 20251222120000_seed_deliveries_grid_config.php
  • 20251223130000_seed_vendors_grid_config.php
  • 20251231140000_seed_category_products_grid_config.php
  • 20260107120000_fix_orders_grid_filterable.php
  • 20260119220000_update_orders_grid_status_fields.php
  • 20260317120000_add_duplicate_publish_to_category_products_actions.php

Phinx API-методы (hasTable, \$this->table(), hasColumn, addForeignKey target) теперь получают UNPREFIXED имя. Raw SQL через \$this->execute() / fetchRow() / fetchAll() по-прежнему получает {\$prefix}name (он не префиксируется автоматически).

Тестирование

На dev-сайте (с уже наполненной `ms3_grid_fields`):

  1. `phinx rollback` — ранее затронутые миграции реально выполнили down (вместо silent no-op):
    • SeedDeliveriesGridConfig, SeedVendorsGridConfig, SeedCategoryProductsGridConfig,
    • FixOrdersGridFilterable, UpdateOrdersGridStatusFields,
    • AddDuplicatePublishToCategoryProductsActions
  2. `phinx migrate` — те же миграции реально выполнили up, данные восстановлены.

PHPStan для миграций не применим (Phinx-классы не в paths).

… calls (#276)

PR #271 defensive-checks accidentally passed prefixed names to Phinx API
methods that auto-prefix internally — every check became modx_modx_*
lookup that never matched, so seed migrations silently no-op'd.

Fixed all 9 affected migrations:
- seed_customers/orders/order_products/deliveries/vendors/category_products_grid_config
- fix_orders_grid_filterable
- update_orders_grid_status_fields
- add_duplicate_publish_to_category_products_actions

Plus initial_schema:
- addForeignKeys(): hasTable / $this->table / addForeignKey target — same fix.
  FK constraints were never created on fresh installs because of this.
- down(): drop loop — same fix.

Phinx API now gets UNPREFIXED names. Raw SQL via $this->execute / fetchAll
keeps {$prefix}name (no auto-prefix there). Comment added on the bug for
future readers.

Impact: fresh MS3 ≥ 1.10.1 installs now properly seed ms3_grid_fields
default rows and create FK constraints. Existing installs that ran the
seeds before #271 are unaffected (already in phinxlog).
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.

[Bug] Double table_prefix in PR #271 defensive checks — seed migrations become silent no-op everywhere

2 participants