m230314_094410_person.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. use yii\db\Migration;
  3. /**
  4. * Class m230314_094410_person
  5. */
  6. class m230314_094410_person extends Migration
  7. {
  8. /**
  9. * {@inheritdoc}
  10. */
  11. public function safeUp()
  12. {
  13. $sql = "CREATE TABLE `person` (
  14. `name` tinytext COLLATE utf8mb4_general_ci NOT NULL,
  15. `alias` varchar(255) COLLATE utf8mb4_general_ci NOT NULL,
  16. `jobtitle` text COLLATE utf8mb4_general_ci NOT NULL,
  17. `birthdate` date DEFAULT NULL,
  18. `description` text COLLATE utf8mb4_general_ci NOT NULL,
  19. `phone` tinytext COLLATE utf8mb4_general_ci NOT NULL,
  20. `email` tinytext COLLATE utf8mb4_general_ci NOT NULL,
  21. `id` int UNSIGNED NOT NULL,
  22. `show` enum('N','Y') COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'N'
  23. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='Эксперты и соавторы';";
  24. $this->execute($sql);
  25. $sql = "ALTER TABLE `person` ADD PRIMARY KEY (`id`),ADD UNIQUE KEY `url` (`alias`); ALTER TABLE `person` ADD FULLTEXT KEY `search` (`name`); COMMIT;";
  26. $this->execute($sql);
  27. $sql = "ALTER TABLE `person` MODIFY `id` int UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=0; COMMIT; COMMIT;";
  28. $this->execute($sql);
  29. }
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public function safeDown()
  34. {
  35. echo "m230314_094410_person cannot be reverted.\n";
  36. return false;
  37. }
  38. /*
  39. // Use up()/down() to run migration code without a transaction.
  40. public function up()
  41. {
  42. }
  43. public function down()
  44. {
  45. echo "m230314_094410_person cannot be reverted.\n";
  46. return false;
  47. }
  48. */
  49. }