Closed krukru closed 4 years ago
I use InnoDB as my default engine, however there are some tables that are MyISAM.
On Thu, Feb 2, 2017 at 2:41 AM, Insolita notifications@github.com wrote:
I saw in PR, that you use MariaDB, please specify - what type of storage ENGINE you use (Aria,XtraDb,InnoDb etc.)
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Insolita/yii2-migrik/issues/27#issuecomment-276841182, or mute the thread https://github.com/notifications/unsubscribe-auth/AJmyNt6CgTGK4Y_ag3phFF-7cIj6jSQkks5rYTQ_gaJpZM4Lz-MO .
Unfortunately yii2 TableSchema don't provide db-abstract tool for retrieve info about table or column collation. So the search of universal decision can take time, and i not sure that it really neccessary. As a simple solution - you should create migrations for tables with different collations separately; And the common collation you can describe in table options - see example
Yii2 has just recently made this possible to get the collation info, but with a bit of class overriding.
You are right that ColumnSchema does not expose the collation info, but it does contain it in the variable $info['collation'] (see https://github.com/yiisoft/yii2/blob/master/framework/db/mysql/Schema.php#L129). With a bit of class extending and config overriding you could get it.
You start by extending the Schema class used for mysql (see $schemaMap in \yii\db\Connection) and extending the ColumnSchema class (see $columnSchemaClass in \yii\db\Schema).
In the extended ColumnSchema class you add the collation property and in the extended Schema class you override the loadColumnSchema($info) method. Something alone the line
/**
* @param array $info
*
* @return \insolita\migrik\db\ColumnSchema
*/
protected function loadColumnSchema($info)
{
/** @var \insolita\migrik\db\ColumnSchema $column */
$column = parent::loadColumnSchema($info);
$column->collation = $info['collation'];
return $column;
}
I would do it in a PR, but I would like to know if you plan on accepting this.
hmm, but what about non-mysql storages? I think that to make own columnSchema variants - is bad idea, it increase difficult for extension usage, create excessive dependence on this extension, and also create additional difficulties for support it all with actual yii2 , but i can make contract like this
<?php
interface ICollationProvidedColumnSchema
{
public function getCollation():string;
}
And my resolvers will check - if your column schema in application will be implement this contract, the extension can to use collation info. Also you can create your own repository with column shemas that implement this contracts and i make suggestion for it
I tried generating a migration for a database that has mixed utf8 and utf8mb4 collations for it's tables.
In the export, all the tables got exported without respecting the collation in which they were stored.