-- Migration: Add member_since field to users table
--
-- This field allows admins to manually set historical membership dates
-- for users imported from the old WordPress site.
--
-- For new users, it can be left NULL and will default to created_at when displayed.
-- For imported users, admins can set it to the actual date they became a member.

-- Add member_since column (nullable timestamp with timezone)
ALTER TABLE users
ADD COLUMN member_since TIMESTAMP WITH TIME ZONE;

-- Backfill existing active members: use created_at as default
-- This is reasonable since they became members when they created their account
UPDATE users
SET member_since = created_at
WHERE status = 'active' AND member_since IS NULL;

-- Success message
SELECT 'Migration completed: member_since field added to users table' AS result;
