mirror of
https://github.com/hanzoai/agents.git
synced 2026-10-30 18:48:36 +00:00
gorm is gone from the module. The schema layer runs on hanzoai/orm/relational over hanzoai/sqlite; the query layer is untouched, because it was already raw SQL on a *sql.DB — 81 such calls against 39 gorm references in one 7000-line file. This also makes the package work cgo-free for the first time. It opened through mattn, whose cgo-free build is a stub that accepts sql.Open and fails at the first statement: `Binary was compiled with 'CGO_ENABLED=0' ... This is a stub`. Measured on the storage suite: 63 failures before, 0 now, on BOTH builds. No test that passed before fails now. The schema is unchanged where it counts. Same 30 tables. Compared index by index on what each one indexes — table, columns, uniqueness — nothing was lost. Index NAMES move to xorm's IDX_/UQE_ convention, and did_registry's uniqueness on root_did becomes a named index instead of an inline table constraint: the same guarantee, differently expressed. No FOREIGN KEY was dropped because this schema declared none. NOT NULL rises from 111 to 133 — stricter, and only on a database created fresh, since Sync2 adopts an existing one rather than rebuilding it.
61 lines
1.6 KiB
Go
61 lines
1.6 KiB
Go
package storage
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/hanzoai/orm/relational"
|
|
)
|
|
|
|
func (ls *LocalStorage) autoMigrateSchema(ctx context.Context) error {
|
|
sess, err := ls.session(ctx)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to prepare session for migrations: %w", err)
|
|
}
|
|
|
|
if ls.mode == "local" {
|
|
if _, err := ls.db.Exec("PRAGMA foreign_keys = OFF"); err != nil {
|
|
return fmt.Errorf("failed to disable foreign keys: %w", err)
|
|
}
|
|
defer func() {
|
|
if _, err := ls.db.Exec("PRAGMA foreign_keys = ON"); err != nil {
|
|
fmt.Printf("failed to re-enable foreign keys: %v\n", err)
|
|
}
|
|
}()
|
|
}
|
|
|
|
models := []interface{}{
|
|
&ExecutionRecordModel{},
|
|
&AgentExecutionModel{},
|
|
&AgentNodeModel{},
|
|
&AgentConfigurationModel{},
|
|
&AgentPackageModel{},
|
|
&WorkflowExecutionModel{},
|
|
&WorkflowExecutionEventModel{},
|
|
&WorkflowRunEventModel{},
|
|
&WorkflowRunModel{},
|
|
&WorkflowStepModel{},
|
|
&WorkflowModel{},
|
|
&SessionModel{},
|
|
&DIDRegistryModel{},
|
|
&AgentDIDModel{},
|
|
&ComponentDIDModel{},
|
|
&ExecutionVCModel{},
|
|
&WorkflowVCModel{},
|
|
&SchemaMigrationModel{},
|
|
&ExecutionWebhookEventModel{},
|
|
&ExecutionWebhookModel{},
|
|
&ObservabilityWebhookModel{},
|
|
&ObservabilityDeadLetterQueueModel{},
|
|
}
|
|
|
|
// Additive only. The indexes this package creates from raw DDL — and the
|
|
// ones migrations/*.sql add — are described by no struct, so letting the
|
|
// engine drop what it does not recognise would delete them on every boot.
|
|
if _, err := sess.SyncWithOptions(relational.SyncOptions{IgnoreDropIndices: true}, models...); err != nil {
|
|
return fmt.Errorf("failed to sync schema: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|