- /**
- * 2016-11-04
- * Unfortunalety, MySQL does not allow to rename a database column
- * without repeating the column's definition: http://stackoverflow.com/questions/8553130
- * The Magento 2 core classes do not have such method too.
- * So, we implement such function ourself.
- * @param string $table
- * @param string $from The column should exist in the table!
- * @param string $to
- * @return void
- */
- function df_db_column_rename($table, $from, $to) {
- /**
- * 2016-11-04
- * @uses df_table() call is required here,
- * because @uses \Magento\Framework\DB\Adapter\Pdo\Mysql methods
- * does not add the custom table prefix to the $name.
- * The custom table prefix could be set my a Magento 2 administrator
- * during Magento 2 intallation (see the «table_prefix» key in the app/etc/env.php file).
- */
- $table = df_table($table);
- /** @var array(string => string|int|null) $definitionRaw */
- $definitionRaw = df_db_column_describe($table, $from);
- /**
- * 2016-11-04
- * @var array(string => string|int|null) $definition
- * Got an array like:
- {
- "name": "test_7781",
- "type": "text",
- "length": "255",
- "options": [],
- "comment": "Test 7781"
- }
- */
- $definition = df_conn()->getColumnCreateByDescribe($definitionRaw);
- /**
- * 2016-11-04
- * The @uses \Magento\Framework\DB\Adapter\Pdo\Mysql::getColumnCreateByDescribe() method
- * sets the table's name as the table's comment:
- * https://github.com/magento/magento2/blob/2.1.2/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php#L1600
- * We remove this comment, because the table will be renamed.
- */
- unset($definition['comment']);
- df_conn()->changeColumn($table, $from, $to, $definition);
- /**
- * 2016-11-04
- * @see \Magento\Framework\DB\Adapter\Pdo\Mysql::resetDdlCache() call is not needed here,
- * because it has already been called
- * from @uses \Magento\Framework\DB\Adapter\Pdo\Mysql::changeColumn()
- * https://github.com/magento/magento2/blob/2.1.2/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php#L1010
- */
- }