m230130_184544_tabla_grupos_eventos.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. use yii\db\Migration;
  3. /**
  4. * Class m230130_184544_tabla_grupos_eventos
  5. */
  6. class m230130_184544_tabla_grupos_eventos extends Migration {
  7. /**
  8. * {@inheritdoc}
  9. */
  10. public function safeUp() {
  11. $this->createTable("EventoGrupo", [
  12. "idEvento" => $this->integer(),
  13. "idGrupo" => $this->integer(),
  14. ]);
  15. $this->addPrimaryKey('EventoGrupoPK', 'EventoGrupo', ['idEvento', 'idGrupo']);
  16. $this->alterColumn("Evento", "nombre", $this->string(255)->notNull());
  17. $this->alterColumn("Evento", "descripcion", $this->text());
  18. $this->dropColumn("Evento", "idGrupo");
  19. $this->addForeignKey('EventoGrupoIdEventoFK', 'EventoGrupo', 'idEvento', 'Evento', 'id');
  20. $this->addForeignKey('EventoGrupoIdGrupoFK', 'EventoGrupo', 'idGrupo', 'Grupo', 'id');
  21. }
  22. /**
  23. * {@inheritdoc}
  24. */
  25. public function safeDown() {
  26. $this->dropForeignKey("EventoGrupoIdGrupoFK", "EventoGrupo");
  27. $this->dropForeignKey("EventoGrupoIdEventoFK", "EventoGrupo");
  28. $this->addColumn("Evento", "idGrupo", $this->integer());
  29. $this->alterColumn("Evento", "descripcion", $this->string(255));
  30. $this->alterColumn("Evento", "nombre", $this->string(100)->notNull());
  31. $this->dropPrimaryKey("EventoGrupoPK", "EventoGrupo");
  32. $this->dropTable('EventoGrupo');
  33. }
  34. }