m240927_010701_Tabla_Incidente_e_IncidenteEmpleado.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. use yii\db\Migration;
  3. /**
  4. * Class m240927_010701_Tabla_Incidente_e_IncidenteEmpleado
  5. */
  6. class m240927_010701_Tabla_Incidente_e_IncidenteEmpleado extends Migration
  7. {
  8. /**
  9. * {@inheritdoc}
  10. */
  11. public function safeUp()
  12. {
  13. $this->createTable('Incidente', [
  14. "id" => $this->string(36),
  15. "nombre" => $this->string(100)->notNull(),
  16. "fechaIncidente" => $this->timestamp()->append(" with time zone"),
  17. "idObra" => $this->string(36),
  18. "descripcion" => $this->string(100)->notNull(),
  19. "creado" => $this->timestamp()->append(" with time zone"),
  20. "modificado" => $this->timestamp()->append(" with time zone"),
  21. "eliminado" => $this->timestamp()->append(" with time zone"),
  22. ]);
  23. $this->addForeignKey("IncidenteObraFK", "Incidente", "idObra", "Obra", "id");
  24. $this->addPrimaryKey('IncidentePK', 'Incidente', 'id');
  25. $this->createTable("IncidenteEmpleado", [
  26. "id" => $this->string(36),
  27. "idIncidente" => $this->string(36),
  28. "idEmpleado" => $this->string(36),
  29. "creado" => $this->timestamp()->append("with time zone"),
  30. "modificado" => $this->timestamp()->append("with time zone"),
  31. "eliminado" => $this->timestamp()->append("with time zone"),
  32. ]);
  33. $this->addPrimaryKey('IncidenteEmpleadoPK', 'IncidenteEmpleado', 'id');
  34. $this->addForeignKey('IncidenteEmpleadoIncidenteFK', 'IncidenteEmpleado', 'idIncidente', 'Incidente', 'id');
  35. $this->addForeignKey('IncidenteEmpleadoEmpleadoFK', 'IncidenteEmpleado', 'idEmpleado', 'Empleado', 'id');
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function safeDown()
  41. {
  42. $this->dropForeignKey("IncidenteObraFK", "Incidente");
  43. $this->dropTable('Incidente');
  44. $this->dropForeignKey('IncidenteEmpleadoIncidenteFK', "IncidenteEmpleado");
  45. $this->dropForeignKey('IncidenteEmpleadoEmpleadoFK', "IncidenteEmpleado");
  46. $this->dropTable('IncidenteEmpleado');
  47. }
  48. /*
  49. // Use up()/down() to run migration code without a transaction.
  50. public function up()
  51. {
  52. }
  53. public function down()
  54. {
  55. echo "m240927_010701_Tabla_Incidente_e_IncidenteEmpleado cannot be reverted.\n";
  56. return false;
  57. }
  58. */
  59. }