-- Migration: Refactor todoist_integrations for single Todoist app -- Webhook теперь единый для всего приложения, токены в URL больше не нужны -- Все пользователи используют одно Todoist приложение -- ============================================ -- 1. Добавляем новые поля -- ============================================ ALTER TABLE todoist_integrations ADD COLUMN IF NOT EXISTS todoist_user_id BIGINT; ALTER TABLE todoist_integrations ADD COLUMN IF NOT EXISTS todoist_email VARCHAR(255); ALTER TABLE todoist_integrations ADD COLUMN IF NOT EXISTS access_token TEXT; -- ============================================ -- 2. Удаляем webhook_token (больше не нужен!) -- ============================================ ALTER TABLE todoist_integrations DROP COLUMN IF EXISTS webhook_token; -- ============================================ -- 3. Удаляем старый индекс на webhook_token -- ============================================ DROP INDEX IF EXISTS idx_todoist_integrations_webhook_token; -- ============================================ -- 4. Создаем новые индексы -- ============================================ CREATE UNIQUE INDEX IF NOT EXISTS idx_todoist_integrations_todoist_user_id ON todoist_integrations(todoist_user_id) WHERE todoist_user_id IS NOT NULL; CREATE UNIQUE INDEX IF NOT EXISTS idx_todoist_integrations_todoist_email ON todoist_integrations(todoist_email) WHERE todoist_email IS NOT NULL; -- ============================================ -- 5. Комментарии -- ============================================ COMMENT ON COLUMN todoist_integrations.todoist_user_id IS 'Todoist user ID (from OAuth) - used to identify user in webhooks'; COMMENT ON COLUMN todoist_integrations.todoist_email IS 'Todoist user email (from OAuth)'; COMMENT ON COLUMN todoist_integrations.access_token IS 'Todoist OAuth access token (permanent)';