m160313_153426_session_init.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 Session tables.
  10. *
  11. * @author Misbahul D Munir <misbahuldmunir@gmail.com>
  12. * @since 2.0.8
  13. */
  14. class m160313_153426_session_init extends Migration
  15. {
  16. /**
  17. * {@inheritdoc}
  18. */
  19. public function up()
  20. {
  21. $dataType = $this->binary();
  22. $tableOptions = null;
  23. switch ($this->db->driverName) {
  24. case 'mysql':
  25. // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
  26. $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
  27. break;
  28. case 'sqlsrv':
  29. case 'mssql':
  30. case 'dblib':
  31. $dataType = $this->text();
  32. break;
  33. }
  34. $this->createTable('{{%session}}', [
  35. 'id' => $this->string()->notNull(),
  36. 'expire' => $this->integer(),
  37. 'data' => $dataType,
  38. 'PRIMARY KEY ([[id]])',
  39. ], $tableOptions);
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function down()
  45. {
  46. $this->dropTable('{{%session}}');
  47. }
  48. }