From a85a6800ddfea0b15c814c488f1d977d3903087b Mon Sep 17 00:00:00 2001 From: Shanice Cumbee Date: Tue, 5 Jul 2022 13:16:42 -0400 Subject: [PATCH 1/4] completed changes for LG-6708 --- app/models/in_person_enrollment.rb | 11 ++++++----- ..._address_and_location_to_in_person_enrollment.rb | 6 ++++++ ...ue_status_constraint_on_in_person_enrollments.rb | 13 +++++++++++++ db/schema.rb | 6 ++++-- 4 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 db/primary_migrate/20220705152334_add_address_and_location_to_in_person_enrollment.rb create mode 100644 db/primary_migrate/20220705164321_change_unique_status_constraint_on_in_person_enrollments.rb diff --git a/app/models/in_person_enrollment.rb b/app/models/in_person_enrollment.rb index 06c07cef226..39d8965bf90 100644 --- a/app/models/in_person_enrollment.rb +++ b/app/models/in_person_enrollment.rb @@ -2,11 +2,12 @@ class InPersonEnrollment < ApplicationRecord belongs_to :user belongs_to :profile enum status: { - pending: 0, - passed: 1, - failed: 2, - expired: 3, - canceled: 4, + establishing: 0, + pending: 1, + passed: 2, + failed: 3, + expired: 4, + canceled: 5, } validate :profile_belongs_to_user diff --git a/db/primary_migrate/20220705152334_add_address_and_location_to_in_person_enrollment.rb b/db/primary_migrate/20220705152334_add_address_and_location_to_in_person_enrollment.rb new file mode 100644 index 00000000000..87e9dd750de --- /dev/null +++ b/db/primary_migrate/20220705152334_add_address_and_location_to_in_person_enrollment.rb @@ -0,0 +1,6 @@ +class AddAddressAndLocationToInPersonEnrollment < ActiveRecord::Migration[6.1] + def change + add_column :in_person_enrollments, :current_address_matches_id, :boolean, comment: "True if the user indicates that their current address matches the address on the ID they're bringing to the Post Office." + add_column :in_person_enrollments, :selected_location_details, :jsonb, comment: "The location details of the Post Office the user selected (including title, address, hours of operation)" + end +end diff --git a/db/primary_migrate/20220705164321_change_unique_status_constraint_on_in_person_enrollments.rb b/db/primary_migrate/20220705164321_change_unique_status_constraint_on_in_person_enrollments.rb new file mode 100644 index 00000000000..315fec5a14c --- /dev/null +++ b/db/primary_migrate/20220705164321_change_unique_status_constraint_on_in_person_enrollments.rb @@ -0,0 +1,13 @@ +class ChangeUniqueStatusConstraintOnInPersonEnrollments < ActiveRecord::Migration[6.1] + disable_ddl_transaction! + + def up + remove_index :in_person_enrollments, name: 'index_in_person_enrollments_on_user_id_and_status', algorithm: :concurrently if index_exists?(:in_person_enrollments, [:user_id, :status], name: "index_in_person_enrollments_on_user_id_and_status") + add_index :in_person_enrollments, [:user_id, :status], unique: true, where: '(status = 1)', algorithm: :concurrently + end + + def down + remove_index :in_person_enrollments, name: 'index_in_person_enrollments_on_user_id_and_status', algorithm: :concurrently if index_exists?(:in_person_enrollments, [:user_id, :status], name: "index_in_person_enrollments_on_user_id_and_status") + add_index :in_person_enrollments, [:user_id, :status], unique: true, where: '(status = 0)', algorithm: :concurrently + end +end diff --git a/db/schema.rb b/db/schema.rb index 246054d30db..0d88e89634e 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: 2022_06_22_232047) do +ActiveRecord::Schema.define(version: 2022_07_05_164321) do # These are extensions that must be enabled in order to support this database enable_extension "pg_stat_statements" @@ -290,8 +290,10 @@ t.integer "status", default: 0, comment: "The status of the enrollment" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.boolean "current_address_matches_id", comment: "True if the user indicates that their current address matches the address on the ID they're bringing to the Post Office." + t.jsonb "selected_location_details", comment: "The location details of the Post Office the user selected (including title, address, hours of operation)" t.index ["profile_id"], name: "index_in_person_enrollments_on_profile_id" - t.index ["user_id", "status"], name: "index_in_person_enrollments_on_user_id_and_status", unique: true, where: "(status = 0)" + t.index ["user_id", "status"], name: "index_in_person_enrollments_on_user_id_and_status", unique: true, where: "(status = 1)" t.index ["user_id"], name: "index_in_person_enrollments_on_user_id" end From 29c14c5fbba4b0825c7b4fba556b6c20ea223365 Mon Sep 17 00:00:00 2001 From: Shanice Cumbee Date: Mon, 11 Jul 2022 11:17:23 -0400 Subject: [PATCH 2/4] updated in_person_enrollment_spec test to match updates to class InPersonEnrollment --- spec/models/in_person_enrollment_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/models/in_person_enrollment_spec.rb b/spec/models/in_person_enrollment_spec.rb index e7af2e38341..bd8ce9cdb5e 100644 --- a/spec/models/in_person_enrollment_spec.rb +++ b/spec/models/in_person_enrollment_spec.rb @@ -9,7 +9,7 @@ describe 'Status' do it 'defines enum correctly' do should define_enum_for(:status). - with_values([:pending, :passed, :failed, :expired, :canceled]) + with_values([:establishing, :pending, :passed, :failed, :expired, :canceled]) end end @@ -27,9 +27,9 @@ user = create(:user) profile = create(:profile, :verification_pending, user: user) profile2 = create(:profile, :verification_pending, user: user) - create(:in_person_enrollment, user: user, profile: profile) + create(:in_person_enrollment, user: user, profile: profile, status: :pending) expect(InPersonEnrollment.pending.count).to eq 1 - expect { create(:in_person_enrollment, user: user, profile: profile2) }. + expect { create(:in_person_enrollment, user: user, profile: profile2, status: :pending) }. to raise_error ActiveRecord::RecordNotUnique expect(InPersonEnrollment.pending.count).to eq 1 end From 02a0dc9d78bec908e882bc83dd68a1bc8614cdbd Mon Sep 17 00:00:00 2001 From: Shanice Cumbee Date: Mon, 11 Jul 2022 11:43:01 -0400 Subject: [PATCH 3/4] changelog: Upcoming Features, In-Person Proofing, Add additional columns to in_person_enrollments From 801c261ef9033ef61493e193dcc1775a724e28c5 Mon Sep 17 00:00:00 2001 From: Tomas Apodaca Date: Wed, 13 Jul 2022 22:12:32 -0700 Subject: [PATCH 4/4] cleanup --- ..._change_unique_status_constraint_on_in_person_enrollments.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/primary_migrate/20220705164321_change_unique_status_constraint_on_in_person_enrollments.rb b/db/primary_migrate/20220705164321_change_unique_status_constraint_on_in_person_enrollments.rb index 315fec5a14c..0515593e68d 100644 --- a/db/primary_migrate/20220705164321_change_unique_status_constraint_on_in_person_enrollments.rb +++ b/db/primary_migrate/20220705164321_change_unique_status_constraint_on_in_person_enrollments.rb @@ -9,5 +9,5 @@ def up def down remove_index :in_person_enrollments, name: 'index_in_person_enrollments_on_user_id_and_status', algorithm: :concurrently if index_exists?(:in_person_enrollments, [:user_id, :status], name: "index_in_person_enrollments_on_user_id_and_status") add_index :in_person_enrollments, [:user_id, :status], unique: true, where: '(status = 0)', algorithm: :concurrently - end + end end