Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enh] add tableOptions in Migration #20

Open
pana1990 opened this issue Aug 4, 2017 · 7 comments
Open

[Enh] add tableOptions in Migration #20

pana1990 opened this issue Aug 4, 2017 · 7 comments
Assignees

Comments

@pana1990
Copy link

pana1990 commented Aug 4, 2017

Yii use the following code in multiple places :

public function up()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
        }
        $this->createTable('{{%whatever}}', [
            
        ], $tableOptions);
    }

https://github.com/yiisoft/yii2/blob/master/framework/rbac/migrations/m140506_102106_rbac_init.php#L56

https://github.com/yiisoft/yii2/blob/master/framework/web/migrations/m160313_153426_session_init.php#L26

https://github.com/yiisoft/yii2/blob/master/framework/caching/migrations/m150909_153426_cache_init.php#L44

some extensions as well

https://github.com/dektrium/yii2-user/blob/master/migrations/Migration.php#L39

you like we include this option to global custom tableOptions in configuration file?

what do you think about it?

@githubjeka
Copy link

to db component? How it look like in code?

@samdark
Copy link
Member

samdark commented Aug 4, 2017

In some of my projects I'm using custom Migration class instead:

class Migration extends \yii\db\Migration
{
    /**
     * @inheritdoc
     */
    public function createTable($table, $columns, $options = null)
    {
        if ($options === null && $this->db->driverName === 'mysql') {
            // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
            $options = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
        }
        parent::createTable($table, $columns, $options);
    }
}

@samdark
Copy link
Member

samdark commented Aug 4, 2017

@pana1990 how should it look like in the config file?

@pana1990
Copy link
Author

pana1990 commented Aug 5, 2017

I use that fragment code as well but if you have any third extension that uses migrations it is not as easy, i have move migrations to my migration path and change yii\db\migration for my custom Migration class

i am not sure but i imagine something like this one :

// console.php
'migrate' => [
      'tableOptions => 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB' // my custom tableOptions
],

if tableOptions is null it get value by default of dbms (CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB for mysql for example)

@samdark
Copy link
Member

samdark commented Aug 8, 2017

I'd introduce defaultTableOptions into migration class and a corresponding property into the command so it could be configured.

@samdark samdark self-assigned this Aug 8, 2017
@santilin
Copy link

santilin commented Nov 9, 2017

I think those setting should be configured in a per driver basis. For example, in console.php:

// console.php
'migrate' => [
      'mysql' => [
          'tableOptions => 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB' // my custom tableOptions
     ], 
    'sqlite' => [
         'tableOptions' => 'WITHOUT ROWID';
     ]
],

sicuz referenced this issue in Servicio-Informatica-Comunicaciones-UZ/jonathan Oct 3, 2018
Ver la documentación en
    https://github.com/yiisoft/yii2-queue/blob/master/docs/guide/driver-db.md

En MySQL 5.6 y MariaDB 10.1, por omisión, la longitud máxima de las claves (índices)
en InnoDB es de 767 bytes (191 ch).

En la migración se define como índice "channel", que es un string,
que por omisión se crea como un VARCHAR(255), que con la codificación utf8mb4
supera esa longitud, provocando un Error #1071 - Specified key was too long.

Por ello, en la configuración de la base de datos, `innodb_large_prefix`
necesita estar activo (ON), y así aceptar hasta 3072 bytes.

Además:
* `innodb_file_format` deberá ser Barracuda en vez de Antelope
* `innodb_file_per_table` debería estar activado
* Al crear la tabla, hay que pasar la opción `ROW_FORMAT=DYNAMIC` (ó `COMPRESSED`),
  porque hasta MySQL 5.7/MariaDB 10.2 por omisión es `COMPACT` o `REDUNDANT`.

Ver
* https://mariadb.com/kb/en/library/xtradbinnodb-storage-formats
* https://mariadb.com/kb/en/library/xtradbinnodb-file-format/
* https://github.com/yiisoft/yii2/issues/14594

Otra migración contiene `renameColumn()`, cuya implementación para MySQL/MariaDB
puede no funcionar según el tipo de comillas que devuelva la BD.
Ver yiisoft/yii2#14267
@samdark samdark transferred this issue from yiisoft/yii2 Apr 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants