use 1-based values for collection_privacy enum

This commit is contained in:
Justin Edmund 2025-12-14 01:23:42 -08:00
parent 07f23e2b74
commit 513f8c6a66
2 changed files with 23 additions and 4 deletions

View file

@ -53,11 +53,11 @@ class User < ApplicationRecord
has_secure_password
##### Enums
# Enum for collection privacy levels
# Enum for collection privacy levels (1-based to avoid JavaScript falsy 0 issues)
enum :collection_privacy, {
everyone: 0,
crew_only: 1,
private_collection: 2
everyone: 1,
crew_only: 2,
private_collection: 3
}, prefix: true
##### Instance Methods

View file

@ -0,0 +1,19 @@
# frozen_string_literal: true
class ChangeCollectionPrivacyToOneBased < ActiveRecord::Migration[8.0]
def up
# Shift all values up by 1: 0->1, 1->2, 2->3
execute 'UPDATE users SET collection_privacy = collection_privacy + 1'
# Change default from 0 to 1
change_column_default :users, :collection_privacy, from: 0, to: 1
end
def down
# Shift all values down by 1: 1->0, 2->1, 3->2
execute 'UPDATE users SET collection_privacy = collection_privacy - 1'
# Restore default
change_column_default :users, :collection_privacy, from: 1, to: 0
end
end