about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@gmail.com>2018-05-01T18·48+0200
committerVincent Ambo <github@tazj.in>2018-05-01T22·33+0200
commit9d5830e9a724d04b2f6fd410c7ae2b56ceea576f (patch)
treed13d11103b9700ae613e0f9189288c5ae7ca7549
parent7a17d532c4ff256b4e8ef4c712135c0e5dd44a4f (diff)
feat(migrations): Add a view for simplified post querying
Adds a view to avoid having to query and join the users & posts table
inside of the application (which isn't particularly convenient in Diesel).
-rw-r--r--migrations/2018-05-01-183232_simplified-post-view/down.sql1
-rw-r--r--migrations/2018-05-01-183232_simplified-post-view/up.sql11
2 files changed, 12 insertions, 0 deletions
diff --git a/migrations/2018-05-01-183232_simplified-post-view/down.sql b/migrations/2018-05-01-183232_simplified-post-view/down.sql
new file mode 100644
index 000000000000..0f14732f3845
--- /dev/null
+++ b/migrations/2018-05-01-183232_simplified-post-view/down.sql
@@ -0,0 +1 @@
+DROP VIEW simple_posts;
diff --git a/migrations/2018-05-01-183232_simplified-post-view/up.sql b/migrations/2018-05-01-183232_simplified-post-view/up.sql
new file mode 100644
index 000000000000..280fef87003e
--- /dev/null
+++ b/migrations/2018-05-01-183232_simplified-post-view/up.sql
@@ -0,0 +1,11 @@
+-- Creates a view for listing posts akin to the post table before
+-- splitting out users. This exists to avoid having to do joining
+-- logic and such inside of the application.
+
+CREATE VIEW simple_posts AS
+  SELECT p.id AS id,
+         thread_id, body, posted, user_id,
+         users.name AS author_name,
+         users.email AS author_email
+  FROM posts p
+  JOIN users ON users.id = p.user_id;