package handlers import ( "encoding/json" "log" ) // ParseSchemaVersion extracts the schema_version from a package manifest. func ParseSchemaVersion(manifest any) int { switch m := manifest.(type) { case map[string]any: if v, ok := m["schema_version"].(float64); ok { return int(v) } case json.RawMessage: var s struct { SchemaVersion int `json:"schema_version"` } if err := json.Unmarshal(m, &s); err == nil { return s.SchemaVersion } } return 0 } // RunSchemaMigrations logs a schema version change during package update. // // Only additive schema changes are supported: extensions can ADD columns and // tables via db_tables in the manifest, but cannot modify or delete existing // schema. If a migration between versions requires destructive changes, // uninstall and reinstall the package manually. func RunSchemaMigrations(ctx any, sandbox any, stores any, db any, isPostgres bool, packageID string, manifest any, fromVersion, toVersion int) error { log.Printf("[pkg-migrate] %s: schema version %d → %d (only additive changes are applied automatically; destructive migrations require manual uninstall/reinstall)", packageID, fromVersion, toVersion) return nil }