m230213_234921_views.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. use yii\db\Migration;
  3. /**
  4. * Class m230213_234921_views
  5. */
  6. class m230213_234921_views extends Migration {
  7. /**
  8. * {@inheritdoc}
  9. */
  10. public function safeUp() {
  11. $this->execute('
  12. create view public."ReporteIndividual" as
  13. select
  14. U.nombre,
  15. U.facebook,
  16. U."facebookVerificado",
  17. U.twitter,
  18. U."twitterVerificado",
  19. U.instagram,
  20. U."instagramVerificado",
  21. U.id "idUsuario",
  22. count(E."redSocial") filter ( where E."redSocial" = Facebook and U."facebookVerificado") as "cantidadFacebook",
  23. count(E."redSocial") filter ( where E."redSocial" = Twitter and U."twitterVerificado") as "cantidadTwitter",
  24. count(E."redSocial") filter ( where E."redSocial" = Instagram and U."instagramVerificado") as "cantidadInstagram",
  25. --count(E.id) as "cantidadEventos",
  26. count(R.accion) as "cantidadResultados"
  27. --(count(E.id) - count(R.accion)) as "cantidadPendientes"
  28. from "Evento" E
  29. inner join "EventoGrupo" EG on E.id = EG."idEvento"
  30. inner join "Grupo" G on G.id = EG."idGrupo"
  31. inner join "UsuarioGrupo" UG on G.id = UG."idGrupo"
  32. inner join "Usuario" U on U.id = UG."idUsuario"
  33. left join "Resultado" R on E.id = R."idEvento" and R."idUsuario" = U.id
  34. group by
  35. U.nombre,
  36. U.facebook,
  37. U."facebookVerificado",
  38. U.twitter,
  39. U."twitterVerificado",
  40. U.instagram,
  41. U."instagramVerificado",
  42. U.id
  43. -- order by E.id
  44. ;
  45. ');
  46. }
  47. /**
  48. * {@inheritdoc}
  49. */
  50. public function safeDown() {
  51. $this->execute('drop view "ReporteIndividual";');
  52. }
  53. /*
  54. // Use up()/down() to run migration code without a transaction.
  55. public function up()
  56. {
  57. }
  58. public function down()
  59. {
  60. echo "m230213_234921_views cannot be reverted.\n";
  61. return false;
  62. }
  63. */
  64. }