From e9678666722719b94fd5ddf372a14c574f748a29 Mon Sep 17 00:00:00 2001 From: Nat Budin Date: Wed, 5 Aug 2026 12:15:03 -0700 Subject: [PATCH] Drop legacy bucket_key/requested_bucket_key columns Fixes #11872. Follow-up to #11871, which kept these columns around through one deploy so a rolling restart couldn't have old code hit a missing-column error while new code was already writing bucket_id/ requested_bucket_id. Verified the bucket_id backfill against a fresh production dump (zero mismatches, only pre-existing orphans below 1%) and confirmed live post-deploy writes are FK-only before running this. Co-Authored-By: Claude Sonnet 5 --- app/models/signup.rb | 24 ++++++++-------- app/models/signup_change.rb | 2 -- app/models/signup_ranked_choice.rb | 1 - app/models/signup_request.rb | 21 +++++++------- ...ignup_ranked_choices_and_signup_changes.rb | 28 +++++++++++++++++++ db/structure.sql | 16 ++++------- test/factories/signup_ranked_choices.rb | 1 - test/factories/signup_requests.rb | 21 +++++++------- test/factories/signups.rb | 24 ++++++++-------- test/models/signup_change_test.rb | 2 -- test/models/signup_ranked_choice_test.rb | 1 - test/models/signup_request_test.rb | 21 +++++++------- test/models/signup_test.rb | 24 ++++++++-------- 13 files changed, 96 insertions(+), 90 deletions(-) create mode 100644 db/migrate/20260805191230_drop_bucket_key_columns_from_signups_signup_requests_signup_ranked_choices_and_signup_changes.rb diff --git a/app/models/signup.rb b/app/models/signup.rb index f071d76a86d..1a143ab5fa5 100644 --- a/app/models/signup.rb +++ b/app/models/signup.rb @@ -4,19 +4,17 @@ # # Table name: signups # -# id :bigint not null, primary key -# bucket_key :string -# counted :boolean -# expires_at :datetime -# requested_bucket_key :string -# state :string default("confirmed"), not null -# created_at :datetime not null -# updated_at :datetime not null -# bucket_id :bigint -# requested_bucket_id :bigint -# run_id :bigint not null -# updated_by_id :bigint -# user_con_profile_id :bigint not null +# id :bigint not null, primary key +# counted :boolean +# expires_at :datetime +# state :string default("confirmed"), not null +# created_at :datetime not null +# updated_at :datetime not null +# bucket_id :bigint +# requested_bucket_id :bigint +# run_id :bigint not null +# updated_by_id :bigint +# user_con_profile_id :bigint not null # # Indexes # diff --git a/app/models/signup_change.rb b/app/models/signup_change.rb index 1850fe14a15..f0a841ef1b8 100644 --- a/app/models/signup_change.rb +++ b/app/models/signup_change.rb @@ -6,10 +6,8 @@ # # id :bigint not null, primary key # action :string not null -# bucket_key :string # bucket_name :string # counted :boolean -# requested_bucket_key :string # requested_bucket_name :string # state :string not null # created_at :datetime not null diff --git a/app/models/signup_ranked_choice.rb b/app/models/signup_ranked_choice.rb index 4e3cddf4f02..a38b48b44dd 100644 --- a/app/models/signup_ranked_choice.rb +++ b/app/models/signup_ranked_choice.rb @@ -6,7 +6,6 @@ # id :bigint not null, primary key # prioritize_waitlist :boolean default(FALSE), not null # priority :integer not null -# requested_bucket_key :string # state :string not null # waitlist_position_cap :integer # created_at :datetime not null diff --git a/app/models/signup_request.rb b/app/models/signup_request.rb index 0a10bbfae3f..cd18217f72a 100644 --- a/app/models/signup_request.rb +++ b/app/models/signup_request.rb @@ -4,17 +4,16 @@ # # Table name: signup_requests # -# id :bigint not null, primary key -# requested_bucket_key :string -# state :string default("pending"), not null -# created_at :datetime not null -# updated_at :datetime not null -# replace_signup_id :bigint -# requested_bucket_id :bigint -# result_signup_id :bigint -# target_run_id :bigint not null -# updated_by_id :bigint -# user_con_profile_id :bigint not null +# id :bigint not null, primary key +# state :string default("pending"), not null +# created_at :datetime not null +# updated_at :datetime not null +# replace_signup_id :bigint +# requested_bucket_id :bigint +# result_signup_id :bigint +# target_run_id :bigint not null +# updated_by_id :bigint +# user_con_profile_id :bigint not null # # Indexes # diff --git a/db/migrate/20260805191230_drop_bucket_key_columns_from_signups_signup_requests_signup_ranked_choices_and_signup_changes.rb b/db/migrate/20260805191230_drop_bucket_key_columns_from_signups_signup_requests_signup_ranked_choices_and_signup_changes.rb new file mode 100644 index 00000000000..7a3430662c5 --- /dev/null +++ b/db/migrate/20260805191230_drop_bucket_key_columns_from_signups_signup_requests_signup_ranked_choices_and_signup_changes.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true +class DropBucketKeyColumnsFromSignupsSignupRequestsSignupRankedChoicesAndSignupChanges < ActiveRecord::Migration[8.1] + def change + reversible do |dir| + dir.up { remove_check_constraint :signups, name: "bucket_key_null_for_non_slot_occupying_states" } + + dir.down do + add_check_constraint :signups, + "(bucket_key IS NULL) OR ((state)::text = ANY (ARRAY['confirmed'::text, 'ticket_purchase_hold'::text]))", # rubocop:disable Layout/LineLength + name: "bucket_key_null_for_non_slot_occupying_states" + end + end + + change_table :signups, bulk: true do |t| + t.remove :bucket_key, type: :string + t.remove :requested_bucket_key, type: :string + end + + remove_column :signup_requests, :requested_bucket_key, :string + + remove_column :signup_ranked_choices, :requested_bucket_key, :string + + change_table :signup_changes, bulk: true do |t| + t.remove :bucket_key, type: :string + t.remove :requested_bucket_key, type: :string + end + end +end diff --git a/db/structure.sql b/db/structure.sql index d56953e38eb..9230f46d9cd 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -2403,9 +2403,7 @@ CREATE TABLE public.signup_changes ( bucket_id bigint, bucket_name character varying, requested_bucket_id bigint, - requested_bucket_name character varying, - requested_bucket_key character varying, - bucket_key character varying + requested_bucket_name character varying ); @@ -2445,8 +2443,7 @@ CREATE TABLE public.signup_ranked_choices ( result_signup_request_id bigint, prioritize_waitlist boolean DEFAULT false NOT NULL, waitlist_position_cap integer, - requested_bucket_id bigint, - requested_bucket_key character varying + requested_bucket_id bigint ); @@ -2483,8 +2480,7 @@ CREATE TABLE public.signup_requests ( updated_by_id bigint, created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, - requested_bucket_id bigint, - requested_bucket_key character varying + requested_bucket_id bigint ); @@ -2562,10 +2558,7 @@ CREATE TABLE public.signups ( expires_at timestamp without time zone, bucket_id bigint, requested_bucket_id bigint, - requested_bucket_key character varying, - bucket_key character varying, - CONSTRAINT bucket_id_null_for_non_slot_occupying_states CHECK (((bucket_id IS NULL) OR ((state)::text = ANY (ARRAY['confirmed'::text, 'ticket_purchase_hold'::text])))), - CONSTRAINT bucket_key_null_for_non_slot_occupying_states CHECK (((bucket_key IS NULL) OR ((state)::text = ANY (ARRAY['confirmed'::text, 'ticket_purchase_hold'::text])))) + CONSTRAINT bucket_id_null_for_non_slot_occupying_states CHECK (((bucket_id IS NULL) OR ((state)::text = ANY (ARRAY['confirmed'::text, 'ticket_purchase_hold'::text])))) ); @@ -6191,6 +6184,7 @@ ALTER TABLE ONLY public.cms_files_pages SET search_path TO "$user", public; INSERT INTO "schema_migrations" (version) VALUES +('20260805191230'), ('20260803190446'), ('20260716155031'), ('20260615192952'), diff --git a/test/factories/signup_ranked_choices.rb b/test/factories/signup_ranked_choices.rb index dd33af07120..ea8d2e1a971 100644 --- a/test/factories/signup_ranked_choices.rb +++ b/test/factories/signup_ranked_choices.rb @@ -6,7 +6,6 @@ # id :bigint not null, primary key # prioritize_waitlist :boolean default(FALSE), not null # priority :integer not null -# requested_bucket_key :string # state :string not null # waitlist_position_cap :integer # created_at :datetime not null diff --git a/test/factories/signup_requests.rb b/test/factories/signup_requests.rb index 14ae2e87162..f898de9a1d6 100644 --- a/test/factories/signup_requests.rb +++ b/test/factories/signup_requests.rb @@ -3,17 +3,16 @@ # # Table name: signup_requests # -# id :bigint not null, primary key -# requested_bucket_key :string -# state :string default("pending"), not null -# created_at :datetime not null -# updated_at :datetime not null -# replace_signup_id :bigint -# requested_bucket_id :bigint -# result_signup_id :bigint -# target_run_id :bigint not null -# updated_by_id :bigint -# user_con_profile_id :bigint not null +# id :bigint not null, primary key +# state :string default("pending"), not null +# created_at :datetime not null +# updated_at :datetime not null +# replace_signup_id :bigint +# requested_bucket_id :bigint +# result_signup_id :bigint +# target_run_id :bigint not null +# updated_by_id :bigint +# user_con_profile_id :bigint not null # # Indexes # diff --git a/test/factories/signups.rb b/test/factories/signups.rb index 41d21d7eb70..8c57b25d0e7 100644 --- a/test/factories/signups.rb +++ b/test/factories/signups.rb @@ -3,19 +3,17 @@ # # Table name: signups # -# id :bigint not null, primary key -# bucket_key :string -# counted :boolean -# expires_at :datetime -# requested_bucket_key :string -# state :string default("confirmed"), not null -# created_at :datetime not null -# updated_at :datetime not null -# bucket_id :bigint -# requested_bucket_id :bigint -# run_id :bigint not null -# updated_by_id :bigint -# user_con_profile_id :bigint not null +# id :bigint not null, primary key +# counted :boolean +# expires_at :datetime +# state :string default("confirmed"), not null +# created_at :datetime not null +# updated_at :datetime not null +# bucket_id :bigint +# requested_bucket_id :bigint +# run_id :bigint not null +# updated_by_id :bigint +# user_con_profile_id :bigint not null # # Indexes # diff --git a/test/models/signup_change_test.rb b/test/models/signup_change_test.rb index 066a9f82320..9215cb77944 100644 --- a/test/models/signup_change_test.rb +++ b/test/models/signup_change_test.rb @@ -5,10 +5,8 @@ # # id :bigint not null, primary key # action :string not null -# bucket_key :string # bucket_name :string # counted :boolean -# requested_bucket_key :string # requested_bucket_name :string # state :string not null # created_at :datetime not null diff --git a/test/models/signup_ranked_choice_test.rb b/test/models/signup_ranked_choice_test.rb index 50eff5bfc9c..fef662e9d9b 100644 --- a/test/models/signup_ranked_choice_test.rb +++ b/test/models/signup_ranked_choice_test.rb @@ -6,7 +6,6 @@ # id :bigint not null, primary key # prioritize_waitlist :boolean default(FALSE), not null # priority :integer not null -# requested_bucket_key :string # state :string not null # waitlist_position_cap :integer # created_at :datetime not null diff --git a/test/models/signup_request_test.rb b/test/models/signup_request_test.rb index 1a89209f7d0..e6294758068 100644 --- a/test/models/signup_request_test.rb +++ b/test/models/signup_request_test.rb @@ -3,17 +3,16 @@ # # Table name: signup_requests # -# id :bigint not null, primary key -# requested_bucket_key :string -# state :string default("pending"), not null -# created_at :datetime not null -# updated_at :datetime not null -# replace_signup_id :bigint -# requested_bucket_id :bigint -# result_signup_id :bigint -# target_run_id :bigint not null -# updated_by_id :bigint -# user_con_profile_id :bigint not null +# id :bigint not null, primary key +# state :string default("pending"), not null +# created_at :datetime not null +# updated_at :datetime not null +# replace_signup_id :bigint +# requested_bucket_id :bigint +# result_signup_id :bigint +# target_run_id :bigint not null +# updated_by_id :bigint +# user_con_profile_id :bigint not null # # Indexes # diff --git a/test/models/signup_test.rb b/test/models/signup_test.rb index 20e5e26edc1..66f6d0a844c 100644 --- a/test/models/signup_test.rb +++ b/test/models/signup_test.rb @@ -3,19 +3,17 @@ # # Table name: signups # -# id :bigint not null, primary key -# bucket_key :string -# counted :boolean -# expires_at :datetime -# requested_bucket_key :string -# state :string default("confirmed"), not null -# created_at :datetime not null -# updated_at :datetime not null -# bucket_id :bigint -# requested_bucket_id :bigint -# run_id :bigint not null -# updated_by_id :bigint -# user_con_profile_id :bigint not null +# id :bigint not null, primary key +# counted :boolean +# expires_at :datetime +# state :string default("confirmed"), not null +# created_at :datetime not null +# updated_at :datetime not null +# bucket_id :bigint +# requested_bucket_id :bigint +# run_id :bigint not null +# updated_by_id :bigint +# user_con_profile_id :bigint not null # # Indexes #