feat(sync): full code sync from release
This commit is contained in:
@@ -1,45 +1,36 @@
|
||||
-- Add gemini-3.1-flash-image and gemini-3.1-flash-image-preview to model_mapping
|
||||
-- Add gemini-3.1-flash-image mapping keys without wiping existing custom mappings.
|
||||
--
|
||||
-- Background:
|
||||
-- Antigravity now supports gemini-3.1-flash-image as the latest image generation model,
|
||||
-- replacing the previous gemini-3-pro-image.
|
||||
-- Antigravity now supports gemini-3.1-flash-image as the latest image generation model.
|
||||
-- Existing accounts may still contain gemini-3-pro-image aliases.
|
||||
--
|
||||
-- Strategy:
|
||||
-- Directly overwrite the entire model_mapping with updated mappings
|
||||
-- This ensures consistency with DefaultAntigravityModelMapping in constants.go
|
||||
-- Incrementally upsert only image-related keys in credentials.model_mapping:
|
||||
-- 1) add canonical 3.1 image keys
|
||||
-- 2) keep legacy 3-pro-image keys but remap them to 3.1 image for compatibility
|
||||
-- This preserves user custom mappings and avoids full mapping overwrite.
|
||||
|
||||
UPDATE accounts
|
||||
SET credentials = jsonb_set(
|
||||
credentials,
|
||||
'{model_mapping}',
|
||||
'{
|
||||
"claude-opus-4-6-thinking": "claude-opus-4-6-thinking",
|
||||
"claude-opus-4-6": "claude-opus-4-6-thinking",
|
||||
"claude-opus-4-5-thinking": "claude-opus-4-6-thinking",
|
||||
"claude-opus-4-5-20251101": "claude-opus-4-6-thinking",
|
||||
"claude-sonnet-4-6": "claude-sonnet-4-6",
|
||||
"claude-sonnet-4-5": "claude-sonnet-4-5",
|
||||
"claude-sonnet-4-5-thinking": "claude-sonnet-4-5-thinking",
|
||||
"claude-sonnet-4-5-20250929": "claude-sonnet-4-5",
|
||||
"claude-haiku-4-5": "claude-sonnet-4-5",
|
||||
"claude-haiku-4-5-20251001": "claude-sonnet-4-5",
|
||||
"gemini-2.5-flash": "gemini-2.5-flash",
|
||||
"gemini-2.5-flash-lite": "gemini-2.5-flash-lite",
|
||||
"gemini-2.5-flash-thinking": "gemini-2.5-flash-thinking",
|
||||
"gemini-2.5-pro": "gemini-2.5-pro",
|
||||
"gemini-3-flash": "gemini-3-flash",
|
||||
"gemini-3-pro-high": "gemini-3-pro-high",
|
||||
"gemini-3-pro-low": "gemini-3-pro-low",
|
||||
"gemini-3-flash-preview": "gemini-3-flash",
|
||||
"gemini-3-pro-preview": "gemini-3-pro-high",
|
||||
"gemini-3.1-pro-high": "gemini-3.1-pro-high",
|
||||
"gemini-3.1-pro-low": "gemini-3.1-pro-low",
|
||||
"gemini-3.1-pro-preview": "gemini-3.1-pro-high",
|
||||
"gemini-3.1-flash-image": "gemini-3.1-flash-image",
|
||||
"gemini-3.1-flash-image-preview": "gemini-3.1-flash-image",
|
||||
"gpt-oss-120b-medium": "gpt-oss-120b-medium",
|
||||
"tab_flash_lite_preview": "tab_flash_lite_preview"
|
||||
}'::jsonb
|
||||
jsonb_set(
|
||||
jsonb_set(
|
||||
jsonb_set(
|
||||
credentials,
|
||||
'{model_mapping,gemini-3.1-flash-image}',
|
||||
'"gemini-3.1-flash-image"'::jsonb,
|
||||
true
|
||||
),
|
||||
'{model_mapping,gemini-3.1-flash-image-preview}',
|
||||
'"gemini-3.1-flash-image"'::jsonb,
|
||||
true
|
||||
),
|
||||
'{model_mapping,gemini-3-pro-image}',
|
||||
'"gemini-3.1-flash-image"'::jsonb,
|
||||
true
|
||||
),
|
||||
'{model_mapping,gemini-3-pro-image-preview}',
|
||||
'"gemini-3.1-flash-image"'::jsonb,
|
||||
true
|
||||
)
|
||||
WHERE platform = 'antigravity'
|
||||
AND deleted_at IS NULL
|
||||
|
||||
2
backend/migrations/060_add_usage_log_openai_ws_mode.sql
Normal file
2
backend/migrations/060_add_usage_log_openai_ws_mode.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
-- Add openai_ws_mode flag to usage_logs to persist exact OpenAI WS transport type.
|
||||
ALTER TABLE usage_logs ADD COLUMN IF NOT EXISTS openai_ws_mode BOOLEAN NOT NULL DEFAULT FALSE;
|
||||
29
backend/migrations/061_add_usage_log_request_type.sql
Normal file
29
backend/migrations/061_add_usage_log_request_type.sql
Normal file
@@ -0,0 +1,29 @@
|
||||
-- Add request_type enum for usage_logs while keeping legacy stream/openai_ws_mode compatibility.
|
||||
ALTER TABLE usage_logs
|
||||
ADD COLUMN IF NOT EXISTS request_type SMALLINT NOT NULL DEFAULT 0;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM pg_constraint
|
||||
WHERE conname = 'usage_logs_request_type_check'
|
||||
) THEN
|
||||
ALTER TABLE usage_logs
|
||||
ADD CONSTRAINT usage_logs_request_type_check
|
||||
CHECK (request_type IN (0, 1, 2, 3));
|
||||
END IF;
|
||||
END
|
||||
$$;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_usage_logs_request_type_created_at
|
||||
ON usage_logs (request_type, created_at);
|
||||
|
||||
-- Backfill from legacy fields. openai_ws_mode has higher priority than stream.
|
||||
UPDATE usage_logs
|
||||
SET request_type = CASE
|
||||
WHEN openai_ws_mode = TRUE THEN 3
|
||||
WHEN stream = TRUE THEN 2
|
||||
ELSE 1
|
||||
END
|
||||
WHERE request_type = 0;
|
||||
@@ -0,0 +1,15 @@
|
||||
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_accounts_schedulable_hot
|
||||
ON accounts (platform, priority)
|
||||
WHERE deleted_at IS NULL AND status = 'active' AND schedulable = true;
|
||||
|
||||
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_accounts_active_schedulable
|
||||
ON accounts (priority, status)
|
||||
WHERE deleted_at IS NULL AND schedulable = true;
|
||||
|
||||
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_user_subscriptions_user_status_expires_active
|
||||
ON user_subscriptions (user_id, status, expires_at)
|
||||
WHERE deleted_at IS NULL;
|
||||
|
||||
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_usage_logs_group_created_at_not_null
|
||||
ON usage_logs (group_id, created_at)
|
||||
WHERE group_id IS NOT NULL;
|
||||
56
backend/migrations/063_add_sora_client_tables.sql
Normal file
56
backend/migrations/063_add_sora_client_tables.sql
Normal file
@@ -0,0 +1,56 @@
|
||||
-- Migration: 063_add_sora_client_tables
|
||||
-- Sora 客户端功能所需的数据库变更:
|
||||
-- 1. 新增 sora_generations 表:记录 Sora 客户端 UI 的生成历史
|
||||
-- 2. users 表新增存储配额字段
|
||||
-- 3. groups 表新增存储配额字段
|
||||
|
||||
-- ============================================================
|
||||
-- 1. sora_generations 表(生成记录)
|
||||
-- ============================================================
|
||||
CREATE TABLE IF NOT EXISTS sora_generations (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
user_id BIGINT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
api_key_id BIGINT,
|
||||
|
||||
-- 生成参数
|
||||
model VARCHAR(64) NOT NULL,
|
||||
prompt TEXT NOT NULL DEFAULT '',
|
||||
media_type VARCHAR(16) NOT NULL DEFAULT 'video', -- video / image
|
||||
|
||||
-- 结果
|
||||
status VARCHAR(16) NOT NULL DEFAULT 'pending', -- pending / generating / completed / failed / cancelled
|
||||
media_url TEXT NOT NULL DEFAULT '',
|
||||
media_urls JSONB, -- 多图时的 URL 数组
|
||||
file_size_bytes BIGINT NOT NULL DEFAULT 0,
|
||||
storage_type VARCHAR(16) NOT NULL DEFAULT 'none', -- s3 / local / upstream / none
|
||||
s3_object_keys JSONB, -- S3 object key 数组
|
||||
|
||||
-- 上游信息
|
||||
upstream_task_id VARCHAR(128) NOT NULL DEFAULT '',
|
||||
error_message TEXT NOT NULL DEFAULT '',
|
||||
|
||||
-- 时间
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
completed_at TIMESTAMPTZ
|
||||
);
|
||||
|
||||
-- 按用户+时间查询(作品库列表、历史记录)
|
||||
CREATE INDEX IF NOT EXISTS idx_sora_gen_user_created
|
||||
ON sora_generations(user_id, created_at DESC);
|
||||
|
||||
-- 按用户+状态查询(恢复进行中任务)
|
||||
CREATE INDEX IF NOT EXISTS idx_sora_gen_user_status
|
||||
ON sora_generations(user_id, status);
|
||||
|
||||
-- ============================================================
|
||||
-- 2. users 表新增 Sora 存储配额字段
|
||||
-- ============================================================
|
||||
ALTER TABLE users
|
||||
ADD COLUMN IF NOT EXISTS sora_storage_quota_bytes BIGINT NOT NULL DEFAULT 0,
|
||||
ADD COLUMN IF NOT EXISTS sora_storage_used_bytes BIGINT NOT NULL DEFAULT 0;
|
||||
|
||||
-- ============================================================
|
||||
-- 3. groups 表新增 Sora 存储配额字段
|
||||
-- ============================================================
|
||||
ALTER TABLE groups
|
||||
ADD COLUMN IF NOT EXISTS sora_storage_quota_bytes BIGINT NOT NULL DEFAULT 0;
|
||||
@@ -12,6 +12,26 @@ Format: `NNN_description.sql`
|
||||
|
||||
Example: `017_add_gemini_tier_id.sql`
|
||||
|
||||
### `_notx.sql` 命名与执行语义(并发索引专用)
|
||||
|
||||
当迁移包含 `CREATE INDEX CONCURRENTLY` 或 `DROP INDEX CONCURRENTLY` 时,必须使用 `_notx.sql` 后缀,例如:
|
||||
|
||||
- `062_add_accounts_priority_indexes_notx.sql`
|
||||
- `063_drop_legacy_indexes_notx.sql`
|
||||
|
||||
运行规则:
|
||||
|
||||
1. `*.sql`(不带 `_notx`)按事务执行。
|
||||
2. `*_notx.sql` 按非事务执行,不会包裹在 `BEGIN/COMMIT` 中。
|
||||
3. `*_notx.sql` 仅允许并发索引语句,不允许混入事务控制语句或其他 DDL/DML。
|
||||
|
||||
幂等要求(必须):
|
||||
|
||||
- 创建索引:`CREATE INDEX CONCURRENTLY IF NOT EXISTS ...`
|
||||
- 删除索引:`DROP INDEX CONCURRENTLY IF EXISTS ...`
|
||||
|
||||
这样可以保证灾备重放、重复执行时不会因对象已存在/不存在而失败。
|
||||
|
||||
## Migration File Structure
|
||||
|
||||
```sql
|
||||
|
||||
Reference in New Issue
Block a user