MatrixDev / Roomigrant

Automated Android Room ORM migrations generator with compile-time code generation
MIT License
373 stars 23 forks source link

Index affinity changes are not supported #16

Closed RBusarow closed 3 years ago

RBusarow commented 3 years ago

If the type/affinity of an indexed field changes between two schema versions, such as from TEXT to INTEGER, the index is not recreated in the migration.

The "index" object in the json doesn't actually include affinity information anywhere. It needs to be cross-referenced from the column info.

MatrixDev commented 3 years ago

@RBusarow, Now that I've merged your PR I have one question. This is generated code for table.field.affinity change:

CREATE TABLE IF NOT EXISTS `indices_MERGE_TABLE` (`id` INTEGER NOT NULL, PRIMARY KEY(`id`))
INSERT INTO `indices_MERGE_TABLE` (`id`) SELECT CAST(`indices`.`id` AS INTEGER) FROM `indices`
DROP TABLE IF EXISTS `indices`
ALTER TABLE `indices_MERGE_TABLE` RENAME TO `indices`
CREATE INDEX IF NOT EXISTS `id_index` ON `indices` (`id`)
### code below comes from IndexDiff
DROP INDEX IF EXISTS id_index
CREATE INDEX IF NOT EXISTS `id_index` ON `indices` (`id`)

Table is dropped when any field affinity changes. Index is dropped with the table automatically and we recreate it afterwards for the new table. Is there really a need for indexed fields affinity check?