-- V18__Add_api_key_encryption_fields.sql
-- 添加API密钥加密存储所需的字段

ALTER TABLE api_keys ADD COLUMN IF NOT EXISTS encrypted_key VARCHAR(512);
ALTER TABLE api_keys ADD COLUMN IF NOT EXISTS revealed_at TIMESTAMP WITH TIME ZONE;

-- 为新字段添加索引
CREATE INDEX IF NOT EXISTS idx_api_keys_encrypted_key ON api_keys(encrypted_key) WHERE encrypted_key IS NOT NULL;
CREATE INDEX IF NOT EXISTS idx_api_keys_revealed_at ON api_keys(revealed_at);

-- 注意: 这是回滚脚本需要的操作
-- ALTER TABLE api_keys DROP COLUMN IF EXISTS encrypted_key;
-- ALTER TABLE api_keys DROP COLUMN IF EXISTS revealed_at;
-- DROP INDEX IF EXISTS idx_api_keys_encrypted_key;
-- DROP INDEX IF EXISTS idx_api_keys_revealed_at;
