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

Introduce registration version column instead of uses_v2_registrations #10132

Merged
merged 11 commits into from
Oct 28, 2024
6 changes: 4 additions & 2 deletions app/models/competition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ class Competition < ApplicationRecord
restricted: 2,
}, prefix: true

enum :registration_version, [:v1, :v2, :v3], prefix: true

CLONEABLE_ATTRIBUTES = %w(
cityName
countryId
Expand Down Expand Up @@ -739,11 +741,11 @@ def trainee_delegate_ids
end

def enable_v2_registrations!
update_column :uses_v2_registrations, true
update_column :registration_version, 'v2'
FinnIckler marked this conversation as resolved.
Show resolved Hide resolved
end

def uses_new_registration_service?
self.uses_v2_registrations
self.registration_version_v2?
end

def should_render_register_v2?(user)
Expand Down
24 changes: 24 additions & 0 deletions db/migrate/20241025161404_make_registration_version_an_enum.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

class MakeRegistrationVersionAnEnum < ActiveRecord::Migration[7.2]
def up
add_column :Competitions, :registration_version, :integer, default: 0, null: false

# Update values based on the old boolean column
Competition.where(uses_v2_registrations: true).update_all(registration_version: 1)

# Remove the old column
remove_column :Competitions, :uses_v2_registrations
end

def down
# Add back the original boolean column
add_column :Competitions, :uses_v2_registrations, :boolean, default: false, null: false

# Map back enum values to the boolean
Competition.where(registration_version: 1).update_all(uses_v2_registrations: true)

# Remove the enum column and rename the boolean column back
remove_column :Competitions, :registration_version
end
end
4 changes: 2 additions & 2 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[7.2].define(version: 2024_10_09_111904) do
ActiveRecord::Schema[7.2].define(version: 2024_10_25_161404) do
create_table "Competitions", id: { type: :string, limit: 32, default: "" }, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t|
t.string "name", limit: 50, default: "", null: false
t.string "cityName", limit: 50, default: "", null: false
Expand Down Expand Up @@ -79,9 +79,9 @@
t.integer "events_per_registration_limit"
t.boolean "force_comment_in_registration"
t.integer "posting_by"
t.boolean "uses_v2_registrations", default: false, null: false
t.boolean "forbid_newcomers", default: false, null: false
t.string "forbid_newcomers_reason"
t.string "registration_version", default: "v1", null: false
t.index ["cancelled_at"], name: "index_Competitions_on_cancelled_at"
t.index ["countryId"], name: "index_Competitions_on_countryId"
t.index ["end_date"], name: "index_Competitions_on_end_date"
Expand Down
2 changes: 1 addition & 1 deletion lib/database_dumper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def self.actions_to_column_sanitizers(columns_by_action)
competition_series_id
use_wca_live_for_scoretaking
allow_registration_without_qualification
uses_v2_registrations
registration_version
forbid_newcomers
forbid_newcomers_reason
),
Expand Down
Loading