-- Setup default project with environment variables
-- This script should be run after setting up the database

-- Update existing default project or insert if not exists
INSERT INTO projects (name, jwt_secret, anon_key, service_role_key, created_at, updated_at)
VALUES (
    'default',
    :'JWT_SECRET',
    :'MADBASE_ANON_KEY',
    :'MADBASE_SERVICE_ROLE_KEY',
    NOW(),
    NOW()
)
ON CONFLICT (name) DO UPDATE SET
    jwt_secret = EXCLUDED.jwt_secret,
    anon_key = EXCLUDED.anon_key,
    service_role_key = EXCLUDED.service_role_key,
    updated_at = NOW();

-- Verify the update
SELECT name, 
       substring(jwt_secret, 1, 8) || '...' as jwt_secret_preview,
       substring(anon_key, 1, 20) || '...' as anon_key_preview,
       substring(service_role_key, 1, 20) || '...' as service_role_key_preview
FROM projects 
WHERE name = 'default';
