feat(payment): 虎皮椒聚合支付 - 官方插件与跨平台可执行文件
新增 xunhupay 官方包,支付 RPC 与宿主只保留订单和验签边界;官方支付包同时带上各系统 provider,避免把 Linux ELF 当成本机入口。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -11,7 +11,7 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const CurrentSchemaVersion int64 = 18
|
||||
const CurrentSchemaVersion int64 = 19
|
||||
|
||||
const baselineSchemaChecksum = "sha256:open-ai-canvas-schema-v1-20260830"
|
||||
const schemaMigrationAppliedAtIndexChecksum = "sha256:schema-migrations-applied-at-index-v2-20260830"
|
||||
@@ -76,6 +76,7 @@ var schemaMigrations = []migration{
|
||||
{version: 18, name: "agent_memory_settings", checksum: "sha256:agent-memory-settings-v18-20260917", apply: func(tx *gorm.DB) error {
|
||||
return tx.AutoMigrate(&model.AgentMemorySetting{})
|
||||
}},
|
||||
{version: 19, name: "payment_plugin_version", checksum: "sha256:payment-plugin-version-v19-20260917", apply: migrateSchemaV19},
|
||||
}
|
||||
|
||||
func migrateSchemaV14(tx *gorm.DB) error {
|
||||
@@ -239,6 +240,28 @@ func migrateSchemaV5(tx *gorm.DB) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func migrateSchemaV19(tx *gorm.DB) error {
|
||||
for _, value := range []any{&model.PaymentProviderConfig{}, &model.PaymentOrder{}} {
|
||||
if !tx.Migrator().HasTable(value) {
|
||||
continue
|
||||
}
|
||||
if err := addPaymentPluginVersionColumn(tx, value); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func addPaymentPluginVersionColumn(tx *gorm.DB, value any) error {
|
||||
if tx.Migrator().HasColumn(value, "plugin_version") {
|
||||
return nil
|
||||
}
|
||||
if err := tx.Migrator().AddColumn(value, "PluginVersion"); err != nil {
|
||||
return fmt.Errorf("增加支付插件版本列:%w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func migrateSchemaV6(tx *gorm.DB) error {
|
||||
if !tx.Migrator().HasTable(&model.Resource{}) {
|
||||
return fmt.Errorf("资源表不存在")
|
||||
|
||||
@@ -44,6 +44,9 @@ func TestMigrateSchemaRecordsAndValidatesVersion(t *testing.T) {
|
||||
if !db.Migrator().HasTable(&model.AgentMemorySetting{}) {
|
||||
t.Fatal("schema migration v18 did not create agent memory settings")
|
||||
}
|
||||
if !db.Migrator().HasColumn(&model.PaymentProviderConfig{}, "plugin_version") || !db.Migrator().HasColumn(&model.PaymentOrder{}, "plugin_version") {
|
||||
t.Fatal("schema migration v19 did not add payment plugin version columns")
|
||||
}
|
||||
if err := MigrateSchema(db); err != nil {
|
||||
t.Fatalf("migration should be idempotent: %v", err)
|
||||
}
|
||||
@@ -153,6 +156,38 @@ func TestMigrateSchemaV18UpgradesExistingDatabase(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMigrateSchemaV19AddsPaymentPluginVersion(t *testing.T) {
|
||||
db, err := Open(Config{Driver: "sqlite", DSN: "file:migration-payment-plugin-version-v19?mode=memory&cache=shared"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := MigrateSchema(db); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.Migrator().DropColumn(&model.PaymentProviderConfig{}, "PluginVersion"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.Migrator().DropColumn(&model.PaymentOrder{}, "PluginVersion"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.Where("version = ?", 19).Delete(&schemaMigration{}).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := MigrateSchema(db); err != nil {
|
||||
t.Fatalf("upgrade from v18: %v", err)
|
||||
}
|
||||
if !db.Migrator().HasColumn(&model.PaymentProviderConfig{}, "plugin_version") {
|
||||
t.Fatal("v19 upgrade did not add payment_provider_configs.plugin_version")
|
||||
}
|
||||
if !db.Migrator().HasColumn(&model.PaymentOrder{}, "plugin_version") {
|
||||
t.Fatal("v19 upgrade did not add payment_orders.plugin_version")
|
||||
}
|
||||
status, err := ReadSchemaStatus(db)
|
||||
if err != nil || !status.Ready || status.Current != CurrentSchemaVersion {
|
||||
t.Fatalf("unexpected upgraded schema status: %+v, %v", status, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMigrateSchemaV8AllowsReusingArchivedLogicalModelCode(t *testing.T) {
|
||||
db, err := Open(Config{Driver: "sqlite", DSN: "file:migration-logical-model-active-code?mode=memory&cache=shared"})
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user