Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create idm schema views #555

Merged
merged 7 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions db/migrations/public/20231128131625_create-users-view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict'

const viewName = 'users'

exports.up = function (knex) {
return knex
.schema
.createView(viewName, (view) => {
// NOTE: We have commented out unused columns from the source table
view.as(knex('users').withSchema('idm').select([
'users.user_id AS id',
'users.user_name AS username',
'users.password',
// 'users.user_data', // inconsistently set and in most cases is {}
'users.reset_guid',
'users.reset_required',
'users.last_login',
'users.bad_logins',
'users.application',
// 'users.role', // was made redundant when roles were moved to be stored separately in tables
// 'users.external_id', // was set during a migration of users from the crm schema but is never used
'users.reset_guid_date_created AS reset_guid_created_at',
'users.enabled',
'users.date_created AS created_at',
'users.date_updated AS updated_at'
]))
})
}

exports.down = function (knex) {
return knex
.schema
.dropViewIfExists(viewName)
}
25 changes: 25 additions & 0 deletions db/migrations/public/20231128133650_create-roles-view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict'

const viewName = 'roles'

exports.up = function (knex) {
return knex
.schema
.createView(viewName, (view) => {
// NOTE: We have commented out unused columns from the source table
view.as(knex('roles').withSchema('idm').select([
'roles.role_id AS id',
// 'roles.application', // is always water_admin
'roles.role',
'roles.description',
'roles.date_created AS created_at',
'roles.date_updated AS updated_at'
]))
})
}

exports.down = function (knex) {
return knex
.schema
.dropViewIfExists(viewName)
}
25 changes: 25 additions & 0 deletions db/migrations/public/20231128133938_create-groups-view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict'

const viewName = 'groups'

exports.up = function (knex) {
return knex
.schema
.createView(viewName, (view) => {
// NOTE: We have commented out unused columns from the source table
view.as(knex('groups').withSchema('idm').select([
'groups.group_id AS id',
// 'groups.application', // is always water_admin
'groups.group',
'groups.description',
'groups.date_created AS created_at',
'groups.date_updated AS updated_at'
]))
})
}

exports.down = function (knex) {
return knex
.schema
.dropViewIfExists(viewName)
}
23 changes: 23 additions & 0 deletions db/migrations/public/20231128134441_create-user-roles-view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict'

const viewName = 'user_roles'

exports.up = function (knex) {
return knex
.schema
.createView(viewName, (view) => {
view.as(knex('user_roles').withSchema('idm').select([
'user_roles.user_role_id AS id',
'user_roles.user_id',
'user_roles.role_id',
'user_roles.date_created AS created_at',
'user_roles.date_updated AS updated_at'
]))
})
}

exports.down = function (knex) {
return knex
.schema
.dropViewIfExists(viewName)
}
23 changes: 23 additions & 0 deletions db/migrations/public/20231128134656_create-user-groups-view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict'

const viewName = 'user_groups'

exports.up = function (knex) {
return knex
.schema
.createView(viewName, (view) => {
view.as(knex('user_groups').withSchema('idm').select([
'user_groups.user_group_id AS id',
'user_groups.user_id',
'user_groups.group_id',
'user_groups.date_created AS created_at',
'user_groups.date_updated AS updated_at'
]))
})
}

exports.down = function (knex) {
return knex
.schema
.dropViewIfExists(viewName)
}
23 changes: 23 additions & 0 deletions db/migrations/public/20231128134839_create-group-roles-view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict'

const viewName = 'group_roles'

exports.up = function (knex) {
return knex
.schema
.createView(viewName, (view) => {
view.as(knex('group_roles').withSchema('idm').select([
'group_roles.group_role_id AS id',
'group_roles.group_id',
'group_roles.role_id',
'group_roles.date_created AS created_at',
'group_roles.date_updated AS updated_at'
]))
})
}

exports.down = function (knex) {
return knex
.schema
.dropViewIfExists(viewName)
}
Loading