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

187384622/new email model - PR3 - Add schema migration to drop old email columns and Adjust Relevant Dependencies #52

Merged
merged 3 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions app/models/teacher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
#
Expand Down Expand Up @@ -297,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
Expand All @@ -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
Original file line number Diff line number Diff line change
@@ -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
7 changes: 1 addition & 6 deletions 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.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"
Expand Down Expand Up @@ -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()" }
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
11 changes: 3 additions & 8 deletions spec/factories/teachers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
#
Expand Down
11 changes: 3 additions & 8 deletions spec/fixtures/teachers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
#
Expand Down
11 changes: 3 additions & 8 deletions spec/models/teacher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
#
Expand Down
Loading