From 26a8b6a37e354917f01f155e4db44d1dfa94bf7c Mon Sep 17 00:00:00 2001 From: Jingchao Zhong <92573736+perryzjc@users.noreply.github.com> Date: Mon, 15 Apr 2024 11:56:25 -0700 Subject: [PATCH 1/3] Add migration to drop teacher email relevant column --- db/migrate/20240415185536_add_email_to_users.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 db/migrate/20240415185536_add_email_to_users.rb diff --git a/db/migrate/20240415185536_add_email_to_users.rb b/db/migrate/20240415185536_add_email_to_users.rb new file mode 100644 index 00000000..97b56d3b --- /dev/null +++ b/db/migrate/20240415185536_add_email_to_users.rb @@ -0,0 +1,10 @@ +class AdaptTeachersAfterNewEmailAddresses < ActiveRecord::Migration[6.1] + def change + remove_index :teachers, name: "index_teachers_on_email_and_first_name" + remove_index :teachers, name: "index_teachers_on_email_and_personal_email" + remove_index :teachers, name: "index_teachers_on_email" + + remove_column :teachers, :email + remove_column :teachers, :personal_email + end +end From 41dacda9610afe8cf6cefb73c4d87fa10b384ba2 Mon Sep 17 00:00:00 2001 From: Jingchao Zhong <92573736+perryzjc@users.noreply.github.com> Date: Mon, 15 Apr 2024 12:13:39 -0700 Subject: [PATCH 2/3] Add migration to drop teacher email relevant column --- app/models/teacher.rb | 13 ++++--------- ...239_adapt_teachers_after_new_email_addresses.rb} | 0 db/schema.rb | 7 +------ spec/factories/teachers.rb | 11 +++-------- spec/fixtures/teachers.yml | 11 +++-------- spec/models/teacher_spec.rb | 11 +++-------- 6 files changed, 14 insertions(+), 39 deletions(-) rename db/migrate/{20240415185536_add_email_to_users.rb => 20240415190239_adapt_teachers_after_new_email_addresses.rb} (100%) diff --git a/app/models/teacher.rb b/app/models/teacher.rb index 09203aa8..0158363b 100644 --- a/app/models/teacher.rb +++ b/app/models/teacher.rb @@ -8,14 +8,12 @@ # admin :boolean default(FALSE) # application_status :string default("not_reviewed") # education_level :integer default(NULL) -# email :string # first_name :string # ip_history :inet default([]), is an Array # languages :string default(["\"English\""]), is an Array # last_name :string # last_session_at :datetime # more_info :string -# personal_email :string # personal_website :string # session_count :integer default(0) # snap :string @@ -26,12 +24,9 @@ # # Indexes # -# index_teachers_on_email (email) UNIQUE -# index_teachers_on_email_and_first_name (email,first_name) -# index_teachers_on_email_and_personal_email (email,personal_email) UNIQUE -# index_teachers_on_school_id (school_id) -# index_teachers_on_snap (snap) UNIQUE WHERE ((snap)::text <> ''::text) -# index_teachers_on_status (status) +# index_teachers_on_school_id (school_id) +# index_teachers_on_snap (snap) UNIQUE WHERE ((snap)::text <> ''::text) +# index_teachers_on_status (status) # # Foreign Keys # @@ -308,6 +303,6 @@ def personal_emails def non_primary_emails # email_addresses.where(primary: false)&.pluck(:email) # below code is temporary for current PR, to make sure the frontend same as before (only one personal email) - personal_email || email_addresses.where(primary: false)&.pluck(:email)&.first + email_addresses.where(primary: false)&.pluck(:email)&.first end end diff --git a/db/migrate/20240415185536_add_email_to_users.rb b/db/migrate/20240415190239_adapt_teachers_after_new_email_addresses.rb similarity index 100% rename from db/migrate/20240415185536_add_email_to_users.rb rename to db/migrate/20240415190239_adapt_teachers_after_new_email_addresses.rb diff --git a/db/schema.rb b/db/schema.rb index fc5c4fcd..fc12aa05 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2024_04_07_190126) do +ActiveRecord::Schema.define(version: 2024_04_15_190239) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -114,7 +114,6 @@ create_table "teachers", id: :serial, force: :cascade do |t| t.string "first_name" t.string "last_name" - t.string "email" t.string "snap" t.integer "school_id" t.datetime "created_at", default: -> { "now()" } @@ -128,11 +127,7 @@ t.datetime "last_session_at" t.inet "ip_history", default: [], array: true t.integer "session_count", default: 0 - t.string "personal_email" t.string "languages", default: ["English"], array: true - t.index ["email", "first_name"], name: "index_teachers_on_email_and_first_name" - t.index ["email", "personal_email"], name: "index_teachers_on_email_and_personal_email", unique: true - t.index ["email"], name: "index_teachers_on_email", unique: true t.index ["school_id"], name: "index_teachers_on_school_id" t.index ["snap"], name: "index_teachers_on_snap", unique: true, where: "((snap)::text <> ''::text)" t.index ["status"], name: "index_teachers_on_status" diff --git a/spec/factories/teachers.rb b/spec/factories/teachers.rb index 36ce3284..4d2c2cce 100644 --- a/spec/factories/teachers.rb +++ b/spec/factories/teachers.rb @@ -8,14 +8,12 @@ # admin :boolean default(FALSE) # application_status :string default("not_reviewed") # education_level :integer default(NULL) -# email :string # first_name :string # ip_history :inet default([]), is an Array # languages :string default(["\"English\""]), is an Array # last_name :string # last_session_at :datetime # more_info :string -# personal_email :string # personal_website :string # session_count :integer default(0) # snap :string @@ -26,12 +24,9 @@ # # Indexes # -# index_teachers_on_email (email) UNIQUE -# index_teachers_on_email_and_first_name (email,first_name) -# index_teachers_on_email_and_personal_email (email,personal_email) UNIQUE -# index_teachers_on_school_id (school_id) -# index_teachers_on_snap (snap) UNIQUE WHERE ((snap)::text <> ''::text) -# index_teachers_on_status (status) +# index_teachers_on_school_id (school_id) +# index_teachers_on_snap (snap) UNIQUE WHERE ((snap)::text <> ''::text) +# index_teachers_on_status (status) # # Foreign Keys # diff --git a/spec/fixtures/teachers.yml b/spec/fixtures/teachers.yml index 0c7ae2ae..26e5dc6b 100644 --- a/spec/fixtures/teachers.yml +++ b/spec/fixtures/teachers.yml @@ -6,14 +6,12 @@ # admin :boolean default(FALSE) # application_status :string default("not_reviewed") # education_level :integer default(NULL) -# email :string # first_name :string # ip_history :inet default([]), is an Array # languages :string default(["\"English\""]), is an Array # last_name :string # last_session_at :datetime # more_info :string -# personal_email :string # personal_website :string # session_count :integer default(0) # snap :string @@ -24,12 +22,9 @@ # # Indexes # -# index_teachers_on_email (email) UNIQUE -# index_teachers_on_email_and_first_name (email,first_name) -# index_teachers_on_email_and_personal_email (email,personal_email) UNIQUE -# index_teachers_on_school_id (school_id) -# index_teachers_on_snap (snap) UNIQUE WHERE ((snap)::text <> ''::text) -# index_teachers_on_status (status) +# index_teachers_on_school_id (school_id) +# index_teachers_on_snap (snap) UNIQUE WHERE ((snap)::text <> ''::text) +# index_teachers_on_status (status) # # Foreign Keys # diff --git a/spec/models/teacher_spec.rb b/spec/models/teacher_spec.rb index 4f7f90bc..870b7e2e 100644 --- a/spec/models/teacher_spec.rb +++ b/spec/models/teacher_spec.rb @@ -8,14 +8,12 @@ # admin :boolean default(FALSE) # application_status :string default("not_reviewed") # education_level :integer default(NULL) -# email :string # first_name :string # ip_history :inet default([]), is an Array # languages :string default(["\"English\""]), is an Array # last_name :string # last_session_at :datetime # more_info :string -# personal_email :string # personal_website :string # session_count :integer default(0) # snap :string @@ -26,12 +24,9 @@ # # Indexes # -# index_teachers_on_email (email) UNIQUE -# index_teachers_on_email_and_first_name (email,first_name) -# index_teachers_on_email_and_personal_email (email,personal_email) UNIQUE -# index_teachers_on_school_id (school_id) -# index_teachers_on_snap (snap) UNIQUE WHERE ((snap)::text <> ''::text) -# index_teachers_on_status (status) +# index_teachers_on_school_id (school_id) +# index_teachers_on_snap (snap) UNIQUE WHERE ((snap)::text <> ''::text) +# index_teachers_on_status (status) # # Foreign Keys # From 02f32bb3a289d352a6f68ba0789821a26d3a47c5 Mon Sep 17 00:00:00 2001 From: Jingchao Zhong <92573736+perryzjc@users.noreply.github.com> Date: Mon, 15 Apr 2024 14:31:28 -0700 Subject: [PATCH 3/3] Remove other dependencies on old teacher email column --- app/models/teacher.rb | 2 +- db/seeds.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/teacher.rb b/app/models/teacher.rb index 0158363b..73661cf7 100644 --- a/app/models/teacher.rb +++ b/app/models/teacher.rb @@ -292,7 +292,7 @@ def email def primary_email # ||:email this code is temporary for this PR: https://github.com/cs169/BJC-Teacher-Tracker-App/pull/49 # to make sure at least original data in db still work and passed the existing tests - self[:email] || email_addresses.find_by(primary: true)&.email + email_addresses.find_by(primary: true)&.email end def personal_emails diff --git a/db/seeds.rb b/db/seeds.rb index 9497fb63..445115e3 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -10,7 +10,7 @@ SeedData.create_schools SeedData.teachers.each do |teacher_attr| - email_address = EmailAddress.find_or_initialize_by(email: teacher_attr[:email]) + email_address = EmailAddress.find_or_initialize_by(email: teacher_attr.delete(:email)) puts "teacher_attr: #{teacher_attr}" if email_address.new_record?