diff --git a/app/models/referral/attribution.rb b/app/models/referral/attribution.rb index 03157f03d2..fa7dbbf54d 100644 --- a/app/models/referral/attribution.rb +++ b/app/models/referral/attribution.rb @@ -7,7 +7,7 @@ # id :bigint not null, primary key # created_at :datetime not null # updated_at :datetime not null -# referral_link_id :bigint +# referral_link_id :bigint not null # referral_program_id :bigint not null # user_id :bigint not null # diff --git a/app/models/referral/program.rb b/app/models/referral/program.rb index 4362971937..41bbbc71f7 100644 --- a/app/models/referral/program.rb +++ b/app/models/referral/program.rb @@ -12,7 +12,7 @@ # name :string not null # created_at :datetime not null # updated_at :datetime not null -# creator_id :bigint +# creator_id :bigint not null # # Indexes # diff --git a/db/migrate/20251205042110_make_referral_link_id_not_null_on_referral_attributions.rb b/db/migrate/20251205042110_make_referral_link_id_not_null_on_referral_attributions.rb new file mode 100644 index 0000000000..b729cbf1bc --- /dev/null +++ b/db/migrate/20251205042110_make_referral_link_id_not_null_on_referral_attributions.rb @@ -0,0 +1,5 @@ +class MakeReferralLinkIdNotNullOnReferralAttributions < ActiveRecord::Migration[8.0] + def change + add_check_constraint :referral_attributions, "referral_link_id IS NOT NULL", name: "referral_attributions_referral_link_id_null", validate: false + end +end diff --git a/db/migrate/20251205042130_make_creator_id_not_null_on_referral_programs.rb b/db/migrate/20251205042130_make_creator_id_not_null_on_referral_programs.rb new file mode 100644 index 0000000000..232fcb4e0c --- /dev/null +++ b/db/migrate/20251205042130_make_creator_id_not_null_on_referral_programs.rb @@ -0,0 +1,5 @@ +class MakeCreatorIdNotNullOnReferralPrograms < ActiveRecord::Migration[8.0] + def change + add_check_constraint :referral_programs, "creator_id IS NOT NULL", name: "referral_programs_creator_id_null", validate: false + end +end diff --git a/db/migrate/20251205044354_validate_make_referral_link_id_not_null_on_referral_attributions.rb b/db/migrate/20251205044354_validate_make_referral_link_id_not_null_on_referral_attributions.rb new file mode 100644 index 0000000000..41085f5bf2 --- /dev/null +++ b/db/migrate/20251205044354_validate_make_referral_link_id_not_null_on_referral_attributions.rb @@ -0,0 +1,12 @@ +class ValidateMakeReferralLinkIdNotNullOnReferralAttributions < ActiveRecord::Migration[8.0] + def up + validate_check_constraint :referral_attributions, name: "referral_attributions_referral_link_id_null" + change_column_null :referral_attributions, :referral_link_id, false + remove_check_constraint :referral_attributions, name: "referral_attributions_referral_link_id_null" + end + + def down + add_check_constraint :referral_attributions, "referral_link_id IS NOT NULL", name: "referral_attributions_referral_link_id_null", validate: false + change_column_null :referral_attributions, :referral_link_id, true + end +end diff --git a/db/migrate/20251205044631_validate_make_creator_id_not_null_on_referral_programs.rb b/db/migrate/20251205044631_validate_make_creator_id_not_null_on_referral_programs.rb new file mode 100644 index 0000000000..9302254383 --- /dev/null +++ b/db/migrate/20251205044631_validate_make_creator_id_not_null_on_referral_programs.rb @@ -0,0 +1,12 @@ +class ValidateMakeCreatorIdNotNullOnReferralPrograms < ActiveRecord::Migration[8.0] + def up + validate_check_constraint :referral_programs, name: "referral_programs_creator_id_null" + change_column_null :referral_programs, :creator_id, false + remove_check_constraint :referral_programs, name: "referral_programs_creator_id_null" + end + + def down + add_check_constraint :referral_programs, "creator_id IS NOT NULL", name: "referral_programs_creator_id_null", validate: false + change_column_null :referral_programs, :creator_id, true + end +end diff --git a/db/schema.rb b/db/schema.rb index 4b44024cc9..b3508af5d7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -12,7 +12,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.0].define(version: 2025_12_05_035167) do +ActiveRecord::Schema[8.0].define(version: 2025_12_05_044631) do create_schema "google_sheets" # These are extensions that must be enabled in order to support this database @@ -1981,7 +1981,7 @@ create_table "referral_attributions", force: :cascade do |t| t.datetime "created_at", null: false - t.bigint "referral_link_id" + t.bigint "referral_link_id", null: false t.bigint "referral_program_id", null: false t.datetime "updated_at", null: false t.bigint "user_id", null: false @@ -2005,7 +2005,7 @@ create_table "referral_programs", force: :cascade do |t| t.string "background_image_url" t.datetime "created_at", null: false - t.bigint "creator_id" + t.bigint "creator_id", null: false t.text "login_body_text" t.string "login_header_text" t.string "login_text_color"