CREATE VIEW IF NOT EXISTS user_view 
  AS
  SELECT
    user.user_id,
    user.email,
    user_state.user_state_id,
    user_state.user_state,
    role.role_id,
    role.role
  FROM
    user
  INNER JOIN user_state ON user.user_state_id = user_state.user_state_id
  INNER JOIN role ON user.role_id = role.role_id
;

CREATE VIEW IF NOT EXISTS user_session_view
  AS
  SELECT
    user_view.*,
    session.session_id
  FROM
    user_view
  INNER JOIN session on user_view.user_id = session.user_id
;
 
