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).
This commit is contained in:
parent
7a17d532c4
commit
9d5830e9a7
2 changed files with 12 additions and 0 deletions
|
@ -0,0 +1 @@
|
||||||
|
DROP VIEW simple_posts;
|
11
migrations/2018-05-01-183232_simplified-post-view/up.sql
Normal file
11
migrations/2018-05-01-183232_simplified-post-view/up.sql
Normal file
|
@ -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;
|
Loading…
Reference in a new issue