summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhorus2020-04-08 19:09:42 +0200
committerhorus2020-04-08 19:09:42 +0200
commit282cf037d94ef2b4f1e664d8fdf13d590fc8eb8d (patch)
tree2db11fcfe518d6d6553103bb74c541da60449de2
parent10c4cf1ce2fb5b9bb487eb80470b0237b3857368 (diff)
downloadsenpai-282cf037d94ef2b4f1e664d8fdf13d590fc8eb8d.tar.gz
Adds database view for anime index page.
-rw-r--r--database/migrations/2020_04_08_022413_add_view_anime_index.php55
1 files changed, 55 insertions, 0 deletions
diff --git a/database/migrations/2020_04_08_022413_add_view_anime_index.php b/database/migrations/2020_04_08_022413_add_view_anime_index.php
new file mode 100644
index 0000000..0ef516e
--- /dev/null
+++ b/database/migrations/2020_04_08_022413_add_view_anime_index.php
@@ -0,0 +1,55 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\DB;
+
+class AddViewAnimeIndex extends Migration
+{
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ DB::statement(
+ "CREATE VIEW view_anime_index AS
+ SELECT DISTINCT
+ a.mal_id,
+ url,
+ image_url,
+ title_pref as title,
+ title_pref,
+ anime_type,
+ a.created_at,
+ a.updated_at,
+ episodes,
+ is_airing,
+ synopsis,
+ hashtag,
+ (SELECT score FROM stats as b WHERE b.mal_id = a.mal_id ORDER BY created_at ASC LIMIT 1) as score_begin,
+ (SELECT score FROM stats as b WHERE b.mal_id = a.mal_id ORDER BY created_at DESC LIMIT 1) as score_today
+ FROM
+ anime as a
+ JOIN
+ stats as s ON a.mal_id = s.mal_id
+ WHERE
+ score IS NOT null
+ ORDER BY
+ abs(score_today-score_begin) DESC,
+ is_airing DESC
+ ;"
+ );
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ DB::statement("DROP VIEW view_anime_index");
+ }
+}