feat(账号): 添加 Sora 账号双表同步与创建
- 新增 sora_accounts 表与 accounts.extra GIN 索引\n- OpenAI OAuth 支持同时创建 Sora 账号并同步配置\n- Token 刷新同步关联 Sora 账号凭证与扩展表\n- 增加 Sora 账号连通性测试与前端开关文案
This commit is contained in:
13
backend/migrations/045_add_accounts_extra_index.sql
Normal file
13
backend/migrations/045_add_accounts_extra_index.sql
Normal file
@@ -0,0 +1,13 @@
|
||||
-- Migration: 045_add_accounts_extra_index
|
||||
-- 为 accounts.extra 字段添加 GIN 索引,优化 FindByExtraField 查询性能
|
||||
-- 用于支持通过 extra 字段中的 linked_openai_account_id 快速查找关联的 Sora 账号
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_accounts_extra_gin
|
||||
ON accounts USING GIN (extra);
|
||||
|
||||
-- 查询示例(使用 @> 操作符)
|
||||
-- EXPLAIN ANALYZE
|
||||
-- SELECT * FROM accounts
|
||||
-- WHERE platform = 'sora'
|
||||
-- AND extra @> '{"linked_openai_account_id": 123}'::jsonb
|
||||
-- AND deleted_at IS NULL;
|
||||
24
backend/migrations/046_add_sora_accounts.sql
Normal file
24
backend/migrations/046_add_sora_accounts.sql
Normal file
@@ -0,0 +1,24 @@
|
||||
-- Migration: 046_add_sora_accounts
|
||||
-- 新增 sora_accounts 扩展表,存储 Sora 账号的 OAuth 凭证
|
||||
-- 与 accounts 主表形成双表结构:
|
||||
-- - accounts: 统一账号管理和调度
|
||||
-- - sora_accounts: Sora gateway 快速读取和资格校验
|
||||
--
|
||||
-- 设计说明:
|
||||
-- - account_id 为主键,外键关联 accounts.id
|
||||
-- - ON DELETE CASCADE 确保删除账号时自动清理扩展表
|
||||
-- - access_token/refresh_token 与 accounts.credentials 保持同步
|
||||
|
||||
CREATE TABLE IF NOT EXISTS sora_accounts (
|
||||
account_id BIGINT PRIMARY KEY,
|
||||
access_token TEXT NOT NULL,
|
||||
refresh_token TEXT NOT NULL,
|
||||
session_token TEXT,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
CONSTRAINT fk_sora_accounts_account_id
|
||||
FOREIGN KEY (account_id) REFERENCES accounts(id)
|
||||
ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- 索引说明:主键已自动创建唯一索引,无需额外创建 idx_sora_accounts_account_id
|
||||
Reference in New Issue
Block a user