feat(*): 云端 Agent - 增强画布上下文读取并接入 Gemini 缓存
This commit is contained in:
@@ -11,7 +11,7 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const CurrentSchemaVersion int64 = 35
|
||||
const CurrentSchemaVersion int64 = 37
|
||||
|
||||
const baselineSchemaChecksum = "sha256:open-ai-canvas-schema-v1-20260830"
|
||||
const schemaMigrationAppliedAtIndexChecksum = "sha256:schema-migrations-applied-at-index-v2-20260830"
|
||||
@@ -23,6 +23,8 @@ const assetLibraryFoldersChecksum = "sha256:asset-library-folders-v6-20260902"
|
||||
const logicalModelActiveCodeChecksum = "sha256:logical-model-active-code-v8-20260905"
|
||||
const creationRuntimeChecksum = "sha256:creation-runtime-v10-20260909"
|
||||
const authNotificationsChecksum = "sha256:auth-notifications-v35-20260924"
|
||||
const cloudAgentGeminiCacheChecksum = "sha256:cloud-agent-gemini-cache-v36-20260924"
|
||||
const cloudAgentGeminiCacheIdentityChecksum = "sha256:cloud-agent-gemini-cache-identity-v37-20260925"
|
||||
|
||||
const postgresSchemaMigrationLockID int64 = 73123910420260830
|
||||
|
||||
@@ -119,6 +121,24 @@ var schemaMigrations = []migration{
|
||||
return nil
|
||||
}},
|
||||
{version: 35, name: "auth_notifications", checksum: authNotificationsChecksum, apply: migrateSchemaV35},
|
||||
{version: 36, name: "cloud_agent_gemini_cache", checksum: cloudAgentGeminiCacheChecksum, apply: func(tx *gorm.DB) error {
|
||||
return tx.AutoMigrate(&model.CloudAgentGeminiCache{})
|
||||
}},
|
||||
{version: 37, name: "cloud_agent_gemini_cache_identity", checksum: cloudAgentGeminiCacheIdentityChecksum, apply: migrateCloudAgentGeminiCacheIdentity},
|
||||
}
|
||||
|
||||
func migrateCloudAgentGeminiCacheIdentity(tx *gorm.DB) error {
|
||||
// v36 accidentally made cache_key globally unique while repository reads and
|
||||
// writes are user-scoped. Remove that index before creating the explicit
|
||||
// (user_id, cache_key) identity used by the model tags.
|
||||
for _, name := range []string{"idx_cloud_agent_gemini_caches_cache_key", "idx_cloud_agent_gemini_cache_cache_key"} {
|
||||
if tx.Migrator().HasIndex(&model.CloudAgentGeminiCache{}, name) {
|
||||
if err := tx.Migrator().DropIndex(&model.CloudAgentGeminiCache{}, name); err != nil {
|
||||
return fmt.Errorf("删除 Gemini 缓存旧唯一索引 %s:%w", name, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return tx.AutoMigrate(&model.CloudAgentGeminiCache{})
|
||||
}
|
||||
|
||||
func migrateChannelModelTags(tx *gorm.DB) error {
|
||||
|
||||
@@ -78,6 +78,9 @@ func TestMigrateSchemaRecordsAndValidatesVersion(t *testing.T) {
|
||||
!db.Migrator().HasColumn(&model.EmailVerificationCode{}, "attempts") {
|
||||
t.Fatal("schema migration v35 did not add authentication verification fields")
|
||||
}
|
||||
if !db.Migrator().HasTable(&model.CloudAgentGeminiCache{}) {
|
||||
t.Fatal("schema migration v36 did not create Gemini cache table")
|
||||
}
|
||||
if err := MigrateSchema(db); err != nil {
|
||||
t.Fatalf("migration should be idempotent: %v", err)
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ func Models() []any {
|
||||
&model.CloudAgentMessageRecord{},
|
||||
&model.CloudAgentCanvasMutation{},
|
||||
&model.CloudAgentResourceLease{},
|
||||
&model.CloudAgentGeminiCache{},
|
||||
&model.AgentProfile{},
|
||||
&model.AgentLesson{},
|
||||
&model.AgentMemorySetting{},
|
||||
|
||||
Reference in New Issue
Block a user