12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- use yii\db\Migration;
- class m150207_210500_i18n_init extends Migration
- {
- public function up()
- {
- $tableOptions = null;
- if ($this->db->driverName === 'mysql') {
-
- $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
- }
- $this->createTable('{{%source_message}}', [
- 'id' => $this->primaryKey(),
- 'category' => $this->string(),
- 'message' => $this->text(),
- ], $tableOptions);
- $this->createTable('{{%message}}', [
- 'id' => $this->integer()->notNull(),
- 'language' => $this->string(16)->notNull(),
- 'translation' => $this->text(),
- ], $tableOptions);
- $this->addPrimaryKey('pk_message_id_language', '{{%message}}', ['id', 'language']);
- $onUpdateConstraint = 'RESTRICT';
- if ($this->db->driverName === 'sqlsrv') {
-
- $onUpdateConstraint = 'NO ACTION';
- }
- $this->addForeignKey('fk_message_source_message', '{{%message}}', 'id', '{{%source_message}}', 'id', 'CASCADE', $onUpdateConstraint);
- $this->createIndex('idx_source_message_category', '{{%source_message}}', 'category');
- $this->createIndex('idx_message_language', '{{%message}}', 'language');
- }
- public function down()
- {
- $this->dropForeignKey('fk_message_source_message', '{{%message}}');
- $this->dropTable('{{%message}}');
- $this->dropTable('{{%source_message}}');
- }
- }
|