mirror of
https://github.com/AppFlowy-IO/AppFlowy-Cloud.git
synced 2025-04-19 03:24:42 -04:00
* chore: create tables * ci: remove postgres service * chore: separate ci * chore: run cargo clippy with sqlx offline mode * refactor: create docker action * chore: rename * chore: update table * chore: update supabase_admin * chore: update supabase_admin * chore: remove create auth.jwt function
18 lines
No EOL
813 B
SQL
18 lines
No EOL
813 B
SQL
-- af_user_profile_view is a view that contains all the user profiles and their latest workspace_id.
|
|
-- a subquery is first used to find the workspace_id of the workspace with the latest updated_at timestamp for each
|
|
-- user. This subquery is then joined with the af_user table to create the view. Note that a LEFT JOIN is used in
|
|
-- case there are users without workspaces, in which case latest_workspace_id will be NULL for those users.
|
|
CREATE OR REPLACE VIEW af_user_profile_view AS
|
|
SELECT u.*,
|
|
w.workspace_id AS latest_workspace_id
|
|
FROM af_user u
|
|
INNER JOIN (
|
|
SELECT uid,
|
|
workspace_id,
|
|
rank() OVER (
|
|
PARTITION BY uid
|
|
ORDER BY updated_at DESC
|
|
) AS rn
|
|
FROM af_workspace_member
|
|
) w ON u.uid = w.uid
|
|
AND w.rn = 1; |