Skip to content

Commit

Permalink
Merge pull request #198 from dhis2/fix/users-with-org-view
Browse files Browse the repository at this point in the history
fix: users-with-organisation view
  • Loading branch information
varl authored Apr 16, 2020
2 parents fd1a314 + 4e67b74 commit c4fb69d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions migrations/20200203182043_fix_view_users_with_organisations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
exports.up = async knex => {
await knex.raw('DROP VIEW users_with_organisations')
await knex.raw(`
CREATE VIEW users_with_organisations
AS SELECT u.id AS user_id, u.name as user_name, u.email, o.name AS organisation_name, o.id AS organisation_id FROM users AS u
INNER JOIN user_organisation AS dorg
ON dorg.user_id = u.id
INNER JOIN organisation AS o
ON o.id = dorg.organisation_id
`)
}

exports.down = async knex => {
await knex.raw('DROP VIEW users_with_organisations')
await knex.raw(`
CREATE VIEW users_with_organisations
AS SELECT u.id AS user_id, u.name as user_name, u.email, o.name AS organisation_name, o.id AS organisation_id FROM users AS u
INNER JOIN user_organisation AS dorg
ON dorg.user_id = user_id
INNER JOIN organisation AS o
ON o.id = dorg.organisation_id
`)
}

0 comments on commit c4fb69d

Please sign in to comment.