diff --git a/db/migrations/public/20231128131625_create-users-view.js b/db/migrations/public/20231128131625_create-users-view.js new file mode 100644 index 0000000000..bf443056b4 --- /dev/null +++ b/db/migrations/public/20231128131625_create-users-view.js @@ -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) +} diff --git a/db/migrations/public/20231128133650_create-roles-view.js b/db/migrations/public/20231128133650_create-roles-view.js new file mode 100644 index 0000000000..e73b98f508 --- /dev/null +++ b/db/migrations/public/20231128133650_create-roles-view.js @@ -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) +} diff --git a/db/migrations/public/20231128133938_create-groups-view.js b/db/migrations/public/20231128133938_create-groups-view.js new file mode 100644 index 0000000000..b359216cba --- /dev/null +++ b/db/migrations/public/20231128133938_create-groups-view.js @@ -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) +} diff --git a/db/migrations/public/20231128134441_create-user-roles-view.js b/db/migrations/public/20231128134441_create-user-roles-view.js new file mode 100644 index 0000000000..634b5e4dad --- /dev/null +++ b/db/migrations/public/20231128134441_create-user-roles-view.js @@ -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) +} diff --git a/db/migrations/public/20231128134656_create-user-groups-view.js b/db/migrations/public/20231128134656_create-user-groups-view.js new file mode 100644 index 0000000000..9f836cbb65 --- /dev/null +++ b/db/migrations/public/20231128134656_create-user-groups-view.js @@ -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) +} diff --git a/db/migrations/public/20231128134839_create-group-roles-view.js b/db/migrations/public/20231128134839_create-group-roles-view.js new file mode 100644 index 0000000000..208259d56c --- /dev/null +++ b/db/migrations/public/20231128134839_create-group-roles-view.js @@ -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) +}