m150207_210500_i18n_init.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. use yii\db\Migration;
  8. /**
  9. * Initializes i18n messages tables.
  10. *
  11. *
  12. *
  13. * @author Dmitry Naumenko <d.naumenko.a@gmail.com>
  14. * @since 2.0.7
  15. */
  16. class m150207_210500_i18n_init extends Migration
  17. {
  18. public function up()
  19. {
  20. $tableOptions = null;
  21. if ($this->db->driverName === 'mysql') {
  22. // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
  23. $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
  24. }
  25. $this->createTable('{{%source_message}}', [
  26. 'id' => $this->primaryKey(),
  27. 'category' => $this->string(),
  28. 'message' => $this->text(),
  29. ], $tableOptions);
  30. $this->createTable('{{%message}}', [
  31. 'id' => $this->integer()->notNull(),
  32. 'language' => $this->string(16)->notNull(),
  33. 'translation' => $this->text(),
  34. ], $tableOptions);
  35. $this->addPrimaryKey('pk_message_id_language', '{{%message}}', ['id', 'language']);
  36. $onUpdateConstraint = 'RESTRICT';
  37. if ($this->db->driverName === 'sqlsrv') {
  38. // 'NO ACTION' is equivalent to 'RESTRICT' in MSSQL
  39. $onUpdateConstraint = 'NO ACTION';
  40. }
  41. $this->addForeignKey('fk_message_source_message', '{{%message}}', 'id', '{{%source_message}}', 'id', 'CASCADE', $onUpdateConstraint);
  42. $this->createIndex('idx_source_message_category', '{{%source_message}}', 'category');
  43. $this->createIndex('idx_message_language', '{{%message}}', 'language');
  44. }
  45. public function down()
  46. {
  47. $this->dropForeignKey('fk_message_source_message', '{{%message}}');
  48. $this->dropTable('{{%message}}');
  49. $this->dropTable('{{%source_message}}');
  50. }
  51. }