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

Create idm schema views #555

merged 7 commits into from
Nov 28, 2023

Conversation

Cruikshanks
Copy link
Member

https://eaflood.atlassian.net/browse/WATER-4057

As part of the work we have been doing on two-part tariff we are going to be creating all our new tables in the default public schema.

We have also decided that when there is a legacy table that we are still going to need we will create a View of it in the public schema. This allows us to correct any issues with naming conventions, strip out unused fields, and join entities that are currently sat in different schemas. The first example of this approach was done in PR #531 .

This change adds the migrations needed to create views for the tables we are currently using from idm schema.

We'll follow this up with new models and test helpers in another change. The final step is then to refactor the existing code to use the new models and delete the old legacy ones.

https://eaflood.atlassian.net/browse/WATER-4057

As part of the work we have been doing on two-part tariff we are going to be creating all our new tables in the default `public` schema.

We have also decided that when there is a legacy table that we are still going to need we will create a [View](https://www.postgresql.org/docs/current/sql-createview.html) of it in the `public` schema. This allows us to correct any issues with naming conventions, strip out unused fields, and join entities that are currently sat in different schemas. The first example of this approach was done in PR #531 .

This change adds the migrations needed to create views for the tables we are currently using from `idm` schema.

> We'll follow this up with new models and test helpers in another change. The final step is then to refactor the existing code to use the new models and delete the old legacy ones.
@Cruikshanks Cruikshanks added the housekeeping Refactoring, tidying up or other work which supports the project label Nov 28, 2023
@Cruikshanks Cruikshanks self-assigned this Nov 28, 2023
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 0000000..9f556a0
--- /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('idm').withSchema('users').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_created_at AS reset_guid_date_created',
+        'users.enabled',
+        'users.date_created AS created_at',
+        'users.date_updated AS updated_at'
+      ]))
+    })
+}
+
+exports.down = function (knex) {
+  return knex
+    .schema
+    .dropViewIfExists(viewName)
+}
@Cruikshanks Cruikshanks force-pushed the create-idm-schema-views branch from 655b650 to 13f0b4f Compare November 28, 2023 13:51
@Cruikshanks Cruikshanks marked this pull request as ready for review November 28, 2023 13:57
Copy link
Contributor

@Jozzey Jozzey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Cruikshanks Cruikshanks merged commit 4b3c99f into main Nov 28, 2023
7 checks passed
@Cruikshanks Cruikshanks deleted the create-idm-schema-views branch November 28, 2023 14:58
Cruikshanks added a commit that referenced this pull request Dec 3, 2023
https://eaflood.atlassian.net/browse/WATER-4057

As part of the work we have been doing on two-part tariff we are going to be creating all our new tables in the default `public` schema.

We have also decided that when there is a legacy table that we are still going to need we will create a [View](https://www.postgresql.org/docs/current/sql-createview.html) of it in the `public` schema. This allows us to correct any issues with naming conventions, strip out unused fields, and join entities that are currently sat in different schemas. The first example of this approach was done in PR #531 .

This change adds the models and helpers for the views in the `idm` schema that were created in PR #555

> The final step will then be to refactor the existing code to use the new models and delete the old legacy ones.
Cruikshanks added a commit that referenced this pull request Dec 4, 2023
https://eaflood.atlassian.net/browse/WATER-4057

As part of the work we have been doing on two-part tariff we are going to be creating all our new tables in the default `public` schema.

We have also decided that when there is a legacy table that we are still going to need we will create a [View](https://www.postgresql.org/docs/current/sql-createview.html) of it in the `public` schema. This allows us to correct any issues with naming conventions, strip out unused fields, and join entities that are currently sat in different schemas. The first example of this approach was done in PR #531 .

This change adds the models and helpers for the views in the `idm` schema that were created in PR #555

> The final step will then be to refactor the existing code to use the new models and delete the old legacy ones.
Cruikshanks added a commit that referenced this pull request Dec 4, 2023
https://eaflood.atlassian.net/browse/WATER-4057

As part of the work we have been doing on two-part tariff we are going to be creating all our new tables in the default `public` schema.

We have also decided that when there is a legacy table that we are still going to need we will create a [View](https://www.postgresql.org/docs/current/sql-createview.html) of it in the `public` schema. This allows us to correct any issues with naming conventions, strip out unused fields, and join entities that are currently sat in different schemas. The first example of this approach was done in PR #531 .

In [Create idm schema views](#555) we created the new views. Then in [Create idm schema models and helpers](#563) we added the new models and helpers that use them.

This is the final step in the process, refactoring any use of the legacy models to use the new ones, and deleted all the legacy based code.
Cruikshanks added a commit that referenced this pull request Dec 5, 2023
https://eaflood.atlassian.net/browse/WATER-4057

As part of the work we have been doing on two-part tariff, we will be creating all our new tables in the default `public` schema.

We have also decided that when there is a legacy table that we are still going to need we will create a [View](https://www.postgresql.org/docs/current/sql-createview.html) of it in the `public` schema. This allows us to correct any issues with naming conventions, strip out unused fields, and join entities currently sat in different schemas. The first example of this approach was done in PR #531 .

We created the new views in [Create IDM schema views](#555). Then in [Create IDM schema models and helpers](#563) we added the new models and helpers that use them.

This is the final step in the process, we are refactoring any use of the legacy models to use the new ones and deleting all the legacy-based code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
housekeeping Refactoring, tidying up or other work which supports the project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants