m221227_033116_add_gallery_table.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. use yii\db\Migration;
  3. /**
  4. * Class m221227_033116_add_gallery_table
  5. */
  6. class m221227_033116_add_gallery_table extends Migration
  7. {
  8. /**
  9. * {@inheritdoc}
  10. */
  11. public function safeUp()
  12. {
  13. $this->createTable("{{%gallery}}",[
  14. "id"=>$this->primaryKey(),
  15. "name"=>$this->string(),
  16. "description"=>$this->string(),
  17. "created_at"=>$this->dateTime(),
  18. "post_id"=>$this->integer(10)->unsigned()
  19. ]);
  20. $this->createTable("{{%gallery_item}}",[
  21. "id"=>$this->primaryKey(),
  22. "name"=>$this->string(),
  23. "description"=>$this->string(),
  24. "created_at"=>$this->dateTime(),
  25. "gallery_id"=>$this->integer(),
  26. "path"=>$this->string(),
  27. "ext"=>$this->string()
  28. ]);
  29. $this->addForeignKey("gallery_to_post_fk","{{%gallery}}",'post_id','{{%news}}','id','CASCADE','CASCADE');
  30. $this->addForeignKey("gallery_item_to_gallery_fk","{{%gallery_item}}",'gallery_id','{{%gallery}}','id','CASCADE','CASCADE');
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function safeDown()
  36. {
  37. echo "m221227_033116_add_gallery_table cannot be reverted.\n";
  38. return false;
  39. }
  40. /*
  41. // Use up()/down() to run migration code without a transaction.
  42. public function up()
  43. {
  44. }
  45. public function down()
  46. {
  47. echo "m221227_033116_add_gallery_table cannot be reverted.\n";
  48. return false;
  49. }
  50. */
  51. }