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

Register ECT/Mentors - Create TeacherEmail table to store emails #48

Closed
wants to merge 3 commits into from

Conversation

TobyRet
Copy link
Contributor

@TobyRet TobyRet commented Jan 20, 2025

Ticket

https://github.com/DFE-Digital/register-ects-project-board/issues/1091

Note

This 1 of 2 possible solutions up for discussion. Please also see the other proposed solution.

Changes

  • Create TeacherEmail table to store teacher_id and email. The ect_at_school_period and mentor_at_school_period tables now reference this new table.
  • This allows us to ensure that the combination of teacher_id and email is unique, as well as ensuring that emails by themselves are unique (so that other Mentors and ECTs cannot take an existing address)
  • Validate at both the model and db layers

Validation summary ( teacher_emails table)

Feature Allowed?
Duplicate email for same teacher No
Teacher can have more than one email Yes
Duplicate email across all teachers No
Blank (nil) emails Yes

Copy link

Review app deployed to https://cpd-ec2-review-48-web.test.teacherservices.cloud

@TobyRet TobyRet force-pushed the 1091/migration-email-address-ects-and-mentors branch from 4874df1 to 1f5aada Compare January 20, 2025 10:59
@@ -0,0 +1,5 @@
class AddEmailToECTAtSchoolPeriods < ActiveRecord::Migration[8.0]
def change
add_column :ect_at_school_periods, :email, :string
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we add a unique constraint in some form on these? We might need to add an emails table though and make these references to that table as I'm not sure having them in place would allow it? Any thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @tonyheadford - as discussed have added constraints on the model and db

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed we are leaving constraints alone for now

Comment on lines 3 to 4
add_index :ect_at_school_periods, :email, unique: true, where: "email IS NOT NULL", name: "unique_email_on_ect_at_school_periods"
add_index :mentor_at_school_periods, :email, unique: true, where: "email IS NOT NULL", name: "unique_email_on_mentor_at_school_periods"
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need the where: clause here, nulls aren't considered equal.

Copy link
Contributor Author

@TobyRet TobyRet Jan 21, 2025

Choose a reason for hiding this comment

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

Depends possibly - the default behaviour of the unique index is to disregard null values when enforcing uniqueness but if we are potentially going to have lots of emails with 'null' then adding the WHERE clause will make the index smaller.

Happy to take your recommendation on this!

Copy link
Contributor

Choose a reason for hiding this comment

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

Will this work for teachers:

  1. using their personal email and they move school and want to use the same email
  2. leave a school and then return at some point in the future and wish to keep their original school email

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed we are leaving constraints alone for now

@TobyRet TobyRet force-pushed the 1091/migration-email-address-ects-and-mentors branch from 10ae35c to bcb339a Compare January 21, 2025 13:50
@TobyRet TobyRet changed the title Add email address column to 'ect_at_school_periods' and 'mentor_at_school_periods' tables Register ECT/Mentors - Create TeacherEmail table to store emails Jan 21, 2025
@@ -12,12 +12,16 @@ def build
success = true
school_periods.each do |period|
school = School.find_by!(urn: period.urn)
# Check where the email address may come from
teacher_email = TeacherEmail.find_or_create_by!(teacher_id: teacher.id, email: nil)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tonyheadford - can the email be sourced or should we set to nil for now?

@@ -12,12 +12,16 @@ def build
success = true
school_periods.each do |period|
school = School.find_by!(urn: period.urn)
# Check where the email address may come from
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@TobyRet TobyRet force-pushed the 1091/migration-email-address-ects-and-mentors branch from ce1cc70 to ede5ad3 Compare January 22, 2025 09:14
@TobyRet TobyRet force-pushed the 1091/migration-email-address-ects-and-mentors branch from ede5ad3 to f208924 Compare January 22, 2025 09:19
@TobyRet TobyRet marked this pull request as draft January 22, 2025 11:40
@TobyRet TobyRet force-pushed the 1091/migration-email-address-ects-and-mentors branch from f208924 to 861c2e0 Compare January 24, 2025 09:26
@TobyRet TobyRet force-pushed the 1091/migration-email-address-ects-and-mentors branch from 861c2e0 to 1ca8dac Compare January 24, 2025 09:28
@TobyRet TobyRet marked this pull request as ready for review January 24, 2025 09:28
@TobyRet TobyRet requested a review from a team January 24, 2025 09:29
@TobyRet
Copy link
Contributor Author

TobyRet commented Jan 24, 2025

Closing in favour of #60

Copy link

Review app ECF2 deployed to https://ec2-review-48-web.test.teacherservices.cloud was deleted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants