Skip to content

Commit

Permalink
feat: create unique email indexes for 'ect_at_school_periods' and 'me…
Browse files Browse the repository at this point in the history
…ntor_at_school_periods' tables
  • Loading branch information
TobyRet committed Jan 20, 2025
1 parent 8ac157f commit 713cb03
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/models/ect_at_school_period.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class ECTAtSchoolPeriod < ApplicationRecord
notify_email: true,
allow_nil: true

validates :email,
email_uniqueness: true,
allow_nil: true

validates :started_on,
presence: true

Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20250120134632_add_unique_constraint_to_email.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddUniqueConstraintToEmail < ActiveRecord::Migration[8.0]
def change
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"
end
end
4 changes: 3 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[8.0].define(version: 2025_01_20_095631) do
ActiveRecord::Schema[8.0].define(version: 2025_01_20_134632) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_catalog.plpgsql"
enable_extension "pg_trgm"
Expand Down Expand Up @@ -150,6 +150,7 @@
t.enum "working_pattern", enum_type: "working_pattern"
t.string "email"
t.index "teacher_id, ((finished_on IS NULL))", name: "index_ect_at_school_periods_on_teacher_id_finished_on_IS_NULL", unique: true, where: "(finished_on IS NULL)"
t.index ["email"], name: "unique_email_on_ect_at_school_periods", unique: true, where: "(email IS NOT NULL)"
t.index ["school_id", "teacher_id", "started_on"], name: "index_ect_at_school_periods_on_school_id_teacher_id_started_on", unique: true
t.index ["school_id"], name: "index_ect_at_school_periods_on_school_id"
t.index ["teacher_id", "started_on"], name: "index_ect_at_school_periods_on_teacher_id_started_on", unique: true
Expand Down Expand Up @@ -280,6 +281,7 @@
t.uuid "legacy_end_id"
t.string "email"
t.index "school_id, teacher_id, ((finished_on IS NULL))", name: "idx_on_school_id_teacher_id_finished_on_IS_NULL_dd7ee16a28", unique: true, where: "(finished_on IS NULL)"
t.index ["email"], name: "unique_email_on_mentor_at_school_periods", unique: true, where: "(email IS NOT NULL)"
t.index ["school_id", "teacher_id", "started_on"], name: "idx_on_school_id_teacher_id_started_on_17d46e7783", unique: true
t.index ["school_id"], name: "index_mentor_at_school_periods_on_school_id"
t.index ["teacher_id", "started_on"], name: "index_mentor_at_school_periods_on_teacher_id_started_on", unique: true
Expand Down

0 comments on commit 713cb03

Please sign in to comment.