-- Migration 003: Remove code_verifier from auth_state table
-- Reason: PKCE is only needed for authorization servers, not for admin login
-- Phase 1 of IndieAuth authorization server removal
-- Date: 2025-11-24

-- SQLite doesn't support DROP COLUMN directly, so we need to recreate the table
-- Step 1: Create new table without code_verifier
CREATE TABLE auth_state_new (
    state TEXT PRIMARY KEY,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    expires_at TIMESTAMP NOT NULL,
    redirect_uri TEXT
);

-- Step 2: Copy data from old table (excluding code_verifier)
INSERT INTO auth_state_new (state, created_at, expires_at, redirect_uri)
SELECT state, created_at, expires_at, redirect_uri
FROM auth_state;

-- Step 3: Drop old table
DROP TABLE auth_state;

-- Step 4: Rename new table to original name
ALTER TABLE auth_state_new RENAME TO auth_state;

-- Step 5: Recreate index
CREATE INDEX IF NOT EXISTS idx_auth_state_expires ON auth_state(expires_at);
