cakephp / cakephp/phinx

Migration snapshot tool creates duplicated index code for UNIQUE indexes

オープン
#1,237 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

bug
主要言語
PHP
スター
4.5k
フォーク
884
PR マージ指標
30日以内にマージされた PR はありません

説明

Goal : create a migration from an existing database (MySQL)

  • Database where migration is being created from : mysqlnd 5.0.12-dev - 20150407 using phpMyAdmin. PHP version: 7.1.9

Indexes looks like this in phpMyAdmin's table view :
indexes of table
Notice how the index user_id is Unique

When following the Official CakePHP's migrations cookbook, doing the command bin/cake bake migration_snapshot Initial works correctly, but then I had problems creating an SQLite database as the error General error 1 : user_id_index already exists in [...] (it was similar to this, I'm writing this from memory) and I banged my head on why was that.

I took a look at the code generated by the snapshot command and I saw this :

// [...]
->addIndex(
    [
        'user_id',
    ],
    ['unique' => true]
)
->addIndex(
    [
        'user_id',
    ]
)
// [...]

Removing the second ->addIndex() solves the problem when creating the SQLite database using the migration(s).

To recap
  • Trying to go from MySQL to SQLite using migrations
  • Command bin/cake bake migration_snapshot Initial generates files without errors
  • then trying the command bin/cake migrations migrate create the SQLite database with errors :
    • General error 1 : user_id_index already exists in [...] in command line
    • only one table exists in SQLite database : phinxlog, which has no rows.
  • Removing duplicated code fixes the problem.

I feel like that duplicated code shouldn't have been generated and I'd consider that a bug.

I haven't done much testing, so I dunno about reproductability.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

説明されている MySQL データベースに対して bin/cake bake migration_snapshot Initial を実行して問題を再現し、その後、生成されたマイグレーションを bin/cake migrations migrate で SQLite に適用します。生成されたマイグレーションの addIndex() 呼び出しを確認し、UNIQUE user_id インデックスを調べます。重複したインデックスのコードがなく、SQLite のマイグレーションが user_id_index already exists エラーなしで完了すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
mysql, php, sqlite
領域
database
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。