-- Migration: Add token_version column to users table if it doesn't exist
-- This column is used for global logout functionality

DO $$
BEGIN
    -- Check if token_version column exists, if not add it
    IF NOT EXISTS (
        SELECT 1 
        FROM information_schema.columns 
        WHERE table_name = 'users' 
        AND column_name = 'token_version'
    ) THEN
        ALTER TABLE users 
        ADD COLUMN token_version INT NOT NULL DEFAULT 1;
        
        RAISE NOTICE 'Added token_version column to users table';
    ELSE
        RAISE NOTICE 'token_version column already exists in users table';
    END IF;
END $$;

