Seems to be a critical bug. Stumbled upon this, because a live project crashed after trying to apply database changes.
How to reproduce
Assume there is a table:
mysql> DESCRIBE migration;
+----------+------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+------+------+-----+---------+----------------+
| id | int | NO | PRI | NULL | auto_increment |
| column_1 | text | NO | | NULL | |
| column_3 | text | NO | | NULL | |
| column_4 | text | NO | | NULL | |
+----------+------+------+-----+---------+----------------+
4 rows in set (0,00 sec)
Run generate command. The migration file looks like:
mysql> ALTER TABLE migration ADD column_2 TEXT NOT NULL AFTER column_1;
Query OK, 0 rows affected (0,04 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> DESCRIBE migration;
+----------+------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+------+------+-----+---------+----------------+
| id | int | NO | PRI | NULL | auto_increment |
| column_1 | text | NO | | NULL | |
| column_2 | text | NO | | NULL | |
| column_3 | text | NO | | NULL | |
| column_4 | text | NO | | NULL | |
+----------+------+------+-----+---------+----------------+
5 rows in set (0,00 sec)
Use generate command again to track differences (even if it creates a full dump again, which is not ideal IMO), which would create a migration file like this:
As you can see, this file looks good, new column is added in correct place. But when I run this migration on production database now, the column column_3 is replaced with column_2.
First notice: column_3 is not dropped, it is renamed to new column (because in my test case column_2 contains exactly the same content that has been stored in column_3 before).
Second notice: In my test, that happens on TEXT columns only, but not when using INT columns.
BTW: I would appreciate if there is a quick fix, because this is a common use case for us.
Seems to be a critical bug. Stumbled upon this, because a live project crashed after trying to apply database changes.
How to reproduce Assume there is a table:
Run
generate
command. The migration file looks like:Add a new column right after
column_1
Use
generate
command again to track differences (even if it creates a full dump again, which is not ideal IMO), which would create a migration file like this:As you can see, this file looks good, new column is added in correct place. But when I run this migration on production database now, the column
column_3
is replaced withcolumn_2
.First notice:
column_3
is not dropped, it is renamed to new column (because in my test casecolumn_2
contains exactly the same content that has been stored incolumn_3
before). Second notice: In my test, that happens onTEXT
columns only, but not when usingINT
columns.BTW: I would appreciate if there is a quick fix, because this is a common use case for us.