From 9d5830e9a724d04b2f6fd410c7ae2b56ceea576f Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Tue, 1 May 2018 20:48:35 +0200 Subject: [PATCH] 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). --- .../2018-05-01-183232_simplified-post-view/down.sql | 1 + .../2018-05-01-183232_simplified-post-view/up.sql | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 migrations/2018-05-01-183232_simplified-post-view/down.sql create mode 100644 migrations/2018-05-01-183232_simplified-post-view/up.sql 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 000000000..0f14732f3 --- /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 000000000..280fef870 --- /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;