Migration snapshot tool creates duplicated index code for UNIQUE indexes
Nessuno ha ancora preso questa issue.
- Lingua principale
- PHP
- Stelle
- 4.5k
- Fork
- 884
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
Goal : create a migration from an existing database (MySQL)
- Database where migration is being created from :
mysqlnd 5.0.12-dev - 20150407usingphpMyAdmin.PHP version: 7.1.9
Indexes looks like this in phpMyAdmin's table view :

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 Initialgenerates files without errors - then trying the command
bin/cake migrations migratecreate 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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Riproduci il problema eseguendo bin/cake bake migration_snapshot Initial sul database MySQL descritto, quindi applica la migration generata a SQLite con bin/cake migrations migrate. Ispeziona le chiamate a addIndex() nella migration generata per verificare l’indice UNIQUE user_id; il lavoro è completato quando il codice dell’indice duplicato è assente e la migration SQLite termina senza l’errore user_id_index already exists.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- mysql, php, sqlite
- Ambito
- database
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100