changeColumn make columns `not null`
Consider if want to change length of a nullable column. using ['length' => MysqlAdapter::INT_TINY] make the column not null. I have to specify 'null'=>true] options to prevent that. I think Phinx should not change unspecified options.
Similar situation with comment. If it is not specified, comment will be deleted.
A reasonable solution would be to get the column description from the DB and populate the change column params with that, and then override them with the user supplied ones.
Not all columns provide/require the same options (http://docs.phinx.org/en/latest/migrations.html#valid-column-options), so each adaptor / column combo would need to be tuned accordingly.
As changColumn is not reversible, the up and down would/should operate in the same way, only changing the attributes that need changing, rather than supplying those that are not changed, but need to be included.
As changing a column is handled by \Phinx\Db\Table::changeColumn(), I wonder how much work to interact with \Phinx\Db\Adapter\AdapterInterface::getColumns() to get the current setup, and then override it with the user supplied one.
Care to have a go at creating a PR for this?
I'd be happy to look it over/help you through it?
The adapter level getColumns() do not SEEMS to work consistently with regard to comments (first glance at least), so, if it is an issue, would need fixing also.
This is not optimized but this is what I am doing at the moment since if changeColumn is given a Column Class it will not create a new Column instance.
$table->changeColumn('user_id', $this->getColumn('user_id', ['after' => 'id']));
private function getColumn($columnName, $options)
{
$columns = new \Cake\Collection\Collection($this->table('Orders')->getColumns());
$column = $columns->filter(function ($column) use ($columnName){
return $column->getName() == $columnName;
})->first();
$column->setOptions($options);
return $column;
}
Are you able to provide a patch with your suggested changes as PR?
Check out https://github.com/cakephp/migrations/pull/941 - if thats sth to be ported to phinx directly, I think the separate method allows BC here for the attributes.