From e490e8e9b64d8e1ac5ce64d2048e5da952b28f40 Mon Sep 17 00:00:00 2001 From: YASHMAHAKAL Date: Fri, 29 May 2026 02:43:28 +0530 Subject: [PATCH 1/4] feat: generate migration for model Signed-off-by: YASHMAHAKAL --- generators/artifacthub/package.go | 2 +- generators/github/package.go | 2 +- go.mod | 2 +- .../registry/v1beta1/component_filter.go | 2 +- models/registration/dir.go | 2 +- models/registration/register.go | 16 ++++++++++++++-- models/registration/utils.go | 2 +- registry/model.go | 2 +- utils/component/openapi_generator.go | 2 +- 9 files changed, 22 insertions(+), 10 deletions(-) diff --git a/generators/artifacthub/package.go b/generators/artifacthub/package.go index 39b82eeb..57ef7bb0 100644 --- a/generators/artifacthub/package.go +++ b/generators/artifacthub/package.go @@ -11,7 +11,7 @@ import ( "github.com/meshery/meshkit/utils/component" "github.com/meshery/meshkit/utils/manifests" "github.com/meshery/schemas/models/v1beta1/category" - "github.com/meshery/schemas/models/v1beta1/model" + "github.com/meshery/schemas/models/v1beta2/model" _component "github.com/meshery/schemas/models/v1beta3/component" "gopkg.in/yaml.v2" ) diff --git a/generators/github/package.go b/generators/github/package.go index 101782a5..7c3e4a7e 100644 --- a/generators/github/package.go +++ b/generators/github/package.go @@ -10,7 +10,7 @@ import ( "github.com/meshery/meshkit/utils/kubernetes" "github.com/meshery/meshkit/utils/manifests" "github.com/meshery/schemas/models/v1beta1/category" - "github.com/meshery/schemas/models/v1beta1/model" + "github.com/meshery/schemas/models/v1beta2/model" _component "github.com/meshery/schemas/models/v1beta3/component" "gopkg.in/yaml.v3" ) diff --git a/go.mod b/go.mod index 5d84bc5d..94115cd8 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ replace ( github.com/googleapis/gnostic => github.com/googleapis/gnostic v0.5.5 github.com/jaguilar/vt100 => github.com/tonistiigi/vt100 v0.0.0-20190402012908-ad4c4a574305 -//github.com/meshery/schemas => ../schemas + github.com/meshery/schemas => ../schemas ) require ( diff --git a/models/meshmodel/registry/v1beta1/component_filter.go b/models/meshmodel/registry/v1beta1/component_filter.go index 59e869bf..e212d2ce 100644 --- a/models/meshmodel/registry/v1beta1/component_filter.go +++ b/models/meshmodel/registry/v1beta1/component_filter.go @@ -6,7 +6,7 @@ import ( "github.com/meshery/meshkit/models/meshmodel/registry" "github.com/meshery/schemas/models/v1beta1/category" "github.com/meshery/schemas/models/v1beta1/connection" - "github.com/meshery/schemas/models/v1beta1/model" + "github.com/meshery/schemas/models/v1beta2/model" "github.com/meshery/schemas/models/v1beta3/component" "gorm.io/gorm/clause" ) diff --git a/models/registration/dir.go b/models/registration/dir.go index c69c603d..ae30f805 100644 --- a/models/registration/dir.go +++ b/models/registration/dir.go @@ -13,7 +13,7 @@ import ( "github.com/meshery/meshkit/utils" "github.com/meshery/schemas/models/v1alpha3/relationship" - "github.com/meshery/schemas/models/v1beta1/model" + "github.com/meshery/schemas/models/v1beta2/model" "github.com/meshery/schemas/models/v1beta3/component" ) diff --git a/models/registration/register.go b/models/registration/register.go index 2b6bad17..239ac47c 100644 --- a/models/registration/register.go +++ b/models/registration/register.go @@ -6,7 +6,8 @@ import ( meshmodel "github.com/meshery/meshkit/models/meshmodel/registry" "github.com/meshery/schemas/models/v1alpha3/relationship" "github.com/meshery/schemas/models/v1beta1/connection" - "github.com/meshery/schemas/models/v1beta1/model" + modelv1beta1 "github.com/meshery/schemas/models/v1beta1/model" + "github.com/meshery/schemas/models/v1beta2/model" "github.com/meshery/schemas/models/v1beta3/component" ) @@ -137,7 +138,18 @@ func (rh *RegistrationHelper) register(pkg PackagingUnit) { // 3. Register relationships for _, rel := range pkg.Relationships { - rel.Model = model.ToReference() + // Convert v1beta2.ModelReference to v1beta1.ModelReference at the + // v1alpha3/relationship boundary. Both structs have identical fields + // (same names and types); only their package paths differ. + v2ref := model.ToReference() + rel.Model = modelv1beta1.ModelReference{ + DisplayName: v2ref.DisplayName, + ID: v2ref.ID, + Model: modelv1beta1.Model{Version: v2ref.Model.Version}, + Name: v2ref.Name, + Registrant: modelv1beta1.RegistrantReference{Kind: v2ref.Registrant.Kind}, + Version: v2ref.Version, + } rel.ModelId = &model.ID _, _, err := rh.regManager.RegisterEntity(model.Registrant, &rel) if err != nil { diff --git a/models/registration/utils.go b/models/registration/utils.go index 86dadac4..6c510232 100644 --- a/models/registration/utils.go +++ b/models/registration/utils.go @@ -9,7 +9,7 @@ import ( "github.com/meshery/schemas/models/v1alpha3" "github.com/meshery/schemas/models/v1alpha3/relationship" "github.com/meshery/schemas/models/v1beta1" - "github.com/meshery/schemas/models/v1beta1/model" + "github.com/meshery/schemas/models/v1beta2/model" "github.com/meshery/schemas/models/v1beta3" "github.com/meshery/schemas/models/v1beta3/component" ) diff --git a/registry/model.go b/registry/model.go index dea008e7..419e7885 100644 --- a/registry/model.go +++ b/registry/model.go @@ -25,7 +25,7 @@ import ( "github.com/meshery/schemas/models/v1beta1/capability" "github.com/meshery/schemas/models/v1beta1/category" "github.com/meshery/schemas/models/v1beta1/connection" - _model "github.com/meshery/schemas/models/v1beta1/model" + _model "github.com/meshery/schemas/models/v1beta2/model" "github.com/meshery/schemas/models/v1beta1/subcategory" "github.com/meshery/schemas/models/v1beta3" "github.com/meshery/schemas/models/v1beta3/component" diff --git a/utils/component/openapi_generator.go b/utils/component/openapi_generator.go index d0807fa8..612bcbf2 100644 --- a/utils/component/openapi_generator.go +++ b/utils/component/openapi_generator.go @@ -16,7 +16,7 @@ import ( "gopkg.in/yaml.v3" - "github.com/meshery/schemas/models/v1beta1/model" + "github.com/meshery/schemas/models/v1beta2/model" "github.com/meshery/schemas/models/v1beta3" "github.com/meshery/schemas/models/v1beta3/component" ) From b21008447936a11a98b4f04fd9f4b65e8231f916 Mon Sep 17 00:00:00 2001 From: YASHMAHAKAL Date: Fri, 29 May 2026 02:58:14 +0530 Subject: [PATCH 2/4] [registry] Migrate model_filter.go from v1beta1/model to v1beta2/model MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Switches ModelFilter.Get/GetById to return *v1beta2.ModelDefinition entities, consistent with the rest of the meshkit model layer after the v1beta1→v1beta2 migration of component.Model (registry/model.go) and registration/register.go. This ensures type-assertion callers (e.g. component_handler.go) receive the correct concrete type and avoids a runtime panic at the type-assertion site. Signed-off-by: YASHMAHAKAL --- models/meshmodel/registry/v1beta1/model_filter.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/meshmodel/registry/v1beta1/model_filter.go b/models/meshmodel/registry/v1beta1/model_filter.go index 7025f780..90013d8d 100644 --- a/models/meshmodel/registry/v1beta1/model_filter.go +++ b/models/meshmodel/registry/v1beta1/model_filter.go @@ -5,7 +5,7 @@ import ( "github.com/meshery/meshkit/models/meshmodel/entity" "github.com/meshery/meshkit/models/meshmodel/registry" "github.com/meshery/schemas/models/v1alpha3/relationship" - "github.com/meshery/schemas/models/v1beta1/model" + "github.com/meshery/schemas/models/v1beta2/model" "github.com/meshery/schemas/models/v1beta3/component" "gorm.io/gorm/clause" From 8a63e8430a0ca20cfdee76b4ed00ea9e08178936 Mon Sep 17 00:00:00 2001 From: YASHMAHAKAL Date: Fri, 29 May 2026 05:05:24 +0530 Subject: [PATCH 3/4] [registry] Migrate Connection wire format to v1beta3 at model boundary MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three coordinated changes to align model.Registrant with the updated v1beta2/model.ModelDefinition.Registrant type (connectionv1beta3.Connection): registry/model.go: createNewRegistrant() now returns connectionv1beta3.Connection. The v1beta3 Connection struct has full camelCase JSON tags (createdAt, updatedAt, deletedAt, userId, credentialId, subType) which are emitted when WriteModelDefinition() serializes to disk. models/registration/register.go: Adds connV3ToV1() bridge helper (field-copy v1beta3→v1beta1). All three RegisterEntity() call sites use the bridge to satisfy the RegistryManager's stable v1beta1.Connection parameter without changing the internal DB API. Connection import switched from v1beta1 to v1beta3 for model.Registrant.Status. models/meshmodel/registry/v1beta1/component_filter.go: ConnectionDB (GORM-read v1beta1.Connection) is field-copied to connectionv1beta3.Connection when assigned to cd.Model.Registrant. DB column tags are identical in both versions — no schema change. schema/validator.go: Adds RelationshipSchemaVersionV1Beta3 constant. registry/relationship.go: Switches from RelationshipSchemaVersionV1Beta2 to V1Beta3 so model generate emits relationships.meshery.io/v1beta3 — matching model init templates. Signed-off-by: YASHMAHAKAL --- go.mod | 2 +- .../registry/v1beta1/component_filter.go | 14 ++++++++--- models/registration/register.go | 25 ++++++++++++++++--- registry/model.go | 8 +++--- registry/relationship.go | 2 +- schema/validator.go | 5 ++++ 6 files changed, 43 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index 94115cd8..5d84bc5d 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ replace ( github.com/googleapis/gnostic => github.com/googleapis/gnostic v0.5.5 github.com/jaguilar/vt100 => github.com/tonistiigi/vt100 v0.0.0-20190402012908-ad4c4a574305 - github.com/meshery/schemas => ../schemas +//github.com/meshery/schemas => ../schemas ) require ( diff --git a/models/meshmodel/registry/v1beta1/component_filter.go b/models/meshmodel/registry/v1beta1/component_filter.go index e212d2ce..d2cd20f6 100644 --- a/models/meshmodel/registry/v1beta1/component_filter.go +++ b/models/meshmodel/registry/v1beta1/component_filter.go @@ -5,7 +5,8 @@ import ( "github.com/meshery/meshkit/models/meshmodel/entity" "github.com/meshery/meshkit/models/meshmodel/registry" "github.com/meshery/schemas/models/v1beta1/category" - "github.com/meshery/schemas/models/v1beta1/connection" + connectionv1beta1 "github.com/meshery/schemas/models/v1beta1/connection" + connectionv1beta3 "github.com/meshery/schemas/models/v1beta3/connection" "github.com/meshery/schemas/models/v1beta2/model" "github.com/meshery/schemas/models/v1beta3/component" "gorm.io/gorm/clause" @@ -33,7 +34,7 @@ type componentDefinitionWithModel struct { ComponentDefinitionDB component.ComponentDefinition `gorm:"embedded"` ModelDB model.ModelDefinition `gorm:"embedded"` CategoryDB category.CategoryDefinition `gorm:"embedded"` - ConnectionDB connection.Connection `gorm:"embedded"` + ConnectionDB connectionv1beta1.Connection `gorm:"embedded"` } func (cf *ComponentFilter) GetById(db *database.Handler) (entity.Entity, error) { @@ -153,7 +154,14 @@ func (componentFilter *ComponentFilter) Get(db *database.Handler) ([]entity.Enti cd.Model = &cm.ModelDB if cd.Model != nil { cd.Model.Category = cm.CategoryDB - cd.Model.Registrant = reg + cd.Model.Registrant = connectionv1beta3.Connection{ + ID: reg.ID, + Name: reg.Name, + Kind: reg.Kind, + Type: reg.Type, + SubType: reg.SubType, + Status: connectionv1beta3.ConnectionStatus(reg.Status), + } } defs = append(defs, &cd) } diff --git a/models/registration/register.go b/models/registration/register.go index 239ac47c..23f9a913 100644 --- a/models/registration/register.go +++ b/models/registration/register.go @@ -5,7 +5,8 @@ import ( "github.com/meshery/meshkit/models/meshmodel/entity" meshmodel "github.com/meshery/meshkit/models/meshmodel/registry" "github.com/meshery/schemas/models/v1alpha3/relationship" - "github.com/meshery/schemas/models/v1beta1/connection" + connectionv1beta1 "github.com/meshery/schemas/models/v1beta1/connection" + "github.com/meshery/schemas/models/v1beta3/connection" modelv1beta1 "github.com/meshery/schemas/models/v1beta1/model" "github.com/meshery/schemas/models/v1beta2/model" "github.com/meshery/schemas/models/v1beta3/component" @@ -19,6 +20,22 @@ type PackagingUnit struct { _ []v1beta1.PolicyDefinition } +// connV3ToV1 field-copies a v1beta3 Connection to v1beta1 Connection. +// Required at the RegisterEntity boundary: the RegistryManager signature +// expects v1beta1.Connection (stable internal API) while ModelDefinition.Registrant +// is now v1beta3.Connection (canonical wire format). DB column tags are +// identical in both versions so no data is lost or altered. +func connV3ToV1(c connection.Connection) connectionv1beta1.Connection { + return connectionv1beta1.Connection{ + ID: c.ID, + Name: c.Name, + Kind: c.Kind, + Type: c.Type, + SubType: c.SubType, + Status: connectionv1beta1.ConnectionStatus(c.Status), + } +} + type RegistrationHelper struct { regManager *meshmodel.RegistryManager regErrStore RegistrationErrorStore @@ -90,7 +107,7 @@ func (rh *RegistrationHelper) register(pkg PackagingUnit) { } model.Registrant.Status = connection.ConnectionStatusRegistered - _, _, err := rh.regManager.RegisterEntity(model.Registrant, &model) + _, _, err := rh.regManager.RegisterEntity(connV3ToV1(model.Registrant), &model) // If model cannot be registered, don't register anything else if err != nil { @@ -126,7 +143,7 @@ func (rh *RegistrationHelper) register(pkg PackagingUnit) { ) } - _, _, err := rh.regManager.RegisterEntity(model.Registrant, &comp) + _, _, err := rh.regManager.RegisterEntity(connV3ToV1(model.Registrant), &comp) if err != nil { err = ErrRegisterEntity(err, string(comp.Type()), comp.DisplayName) rh.regErrStore.InsertEntityRegError(hostname, model.DisplayName, entity.ComponentDefinition, comp.DisplayName, err) @@ -151,7 +168,7 @@ func (rh *RegistrationHelper) register(pkg PackagingUnit) { Version: v2ref.Version, } rel.ModelId = &model.ID - _, _, err := rh.regManager.RegisterEntity(model.Registrant, &rel) + _, _, err := rh.regManager.RegisterEntity(connV3ToV1(model.Registrant), &rel) if err != nil { err = ErrRegisterEntity(err, string(rel.Type()), string(rel.Kind)) rh.regErrStore.InsertEntityRegError(hostname, model.DisplayName, entity.RelationshipDefinition, rel.ID.String(), err) diff --git a/registry/model.go b/registry/model.go index 419e7885..16bfe1d4 100644 --- a/registry/model.go +++ b/registry/model.go @@ -24,7 +24,7 @@ import ( "github.com/meshery/meshkit/utils/store" "github.com/meshery/schemas/models/v1beta1/capability" "github.com/meshery/schemas/models/v1beta1/category" - "github.com/meshery/schemas/models/v1beta1/connection" + connectionv1beta3 "github.com/meshery/schemas/models/v1beta3/connection" _model "github.com/meshery/schemas/models/v1beta2/model" "github.com/meshery/schemas/models/v1beta1/subcategory" "github.com/meshery/schemas/models/v1beta3" @@ -374,7 +374,7 @@ published: %s markdown = strings.ReplaceAll(markdown, "\r", "\n") return markdown } -func createNewRegistrant(registrantName string) connection.Connection { +func createNewRegistrant(registrantName string) connectionv1beta3.Connection { kind := utils.ReplaceSpacesAndConvertToLowercase(registrantName) switch kind { case "artifacthub": @@ -386,9 +386,9 @@ func createNewRegistrant(registrantName string) connection.Connection { case "kubernetes": registrantName = "Kubernetes" } - newRegistrant := connection.Connection{ + newRegistrant := connectionv1beta3.Connection{ Name: registrantName, - Status: connection.ConnectionStatusDiscovered, + Status: connectionv1beta3.ConnectionStatusDiscovered, Type: "registry", Kind: kind, } diff --git a/registry/relationship.go b/registry/relationship.go index 07a4840d..8d55352c 100644 --- a/registry/relationship.go +++ b/registry/relationship.go @@ -151,7 +151,7 @@ func ProcessRelationships(relationshipCSVHelper *RelationshipCSVHelper, spreadsh } var rel _rel.RelationshipDefinition - rel.SchemaVersion = schema.RelationshipSchemaVersionV1Beta2 + rel.SchemaVersion = schema.RelationshipSchemaVersionV1Beta3 rel.Kind = _rel.RelationshipDefinitionKind(utils.ReplaceSpacesWithHyphenAndConvertToLowercase(relationship.KIND)) rel.RelationshipType = utils.ReplaceSpacesWithHyphenAndConvertToLowercase(relationship.Type) rel.SubType = utils.ReplaceSpacesWithHyphenAndConvertToLowercase(relationship.SubType) diff --git a/schema/validator.go b/schema/validator.go index f8af4a6b..fe2b994d 100644 --- a/schema/validator.go +++ b/schema/validator.go @@ -33,6 +33,11 @@ const ( // the string to keep all packages in sync. const RelationshipSchemaVersionV1Beta2 = "relationships.meshery.io/v1beta2" +// RelationshipSchemaVersionV1Beta3 is the canonical schema version string for +// v1beta3 relationship definitions. model generate uses this version to align +// with the templates used by model init. +const RelationshipSchemaVersionV1Beta3 = "relationships.meshery.io/v1beta3" + // Ref identifies which schema should be used to validate a document. type Ref struct { SchemaVersion string `json:"schemaVersion,omitempty" yaml:"schemaVersion,omitempty"` From 62ee4278373bfcc6f1b35c3bf41fdb90fce6ab4c Mon Sep 17 00:00:00 2001 From: YASHMAHAKAL Date: Mon, 1 Jun 2026 17:37:14 +0530 Subject: [PATCH 4/4] [registry] Fix read path: scan ConnectionDB directly into v1beta3.Connection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, the GORM scan struct read the connection into v1beta1.Connection and then manually field-copied 6 fields into v1beta3.Connection, silently dropping the 'description' and 'url' fields which exist in the DB (connections table was already AutoMigrated with v1beta3.Connection in meshery server). Since db: tags are identical between v1beta1 and v1beta3, GORM can scan directly into v1beta3.Connection without any data loss. The manual bridge and the v1beta1/connection import are removed. The write-path bridge (connV3ToV1 at RegisterEntity call sites) is unchanged — v1beta3.Connection has no Create() method yet. Signed-off-by: YASHMAHAKAL --- .../registry/v1beta1/component_filter.go | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/models/meshmodel/registry/v1beta1/component_filter.go b/models/meshmodel/registry/v1beta1/component_filter.go index d2cd20f6..cc8eac76 100644 --- a/models/meshmodel/registry/v1beta1/component_filter.go +++ b/models/meshmodel/registry/v1beta1/component_filter.go @@ -5,7 +5,6 @@ import ( "github.com/meshery/meshkit/models/meshmodel/entity" "github.com/meshery/meshkit/models/meshmodel/registry" "github.com/meshery/schemas/models/v1beta1/category" - connectionv1beta1 "github.com/meshery/schemas/models/v1beta1/connection" connectionv1beta3 "github.com/meshery/schemas/models/v1beta3/connection" "github.com/meshery/schemas/models/v1beta2/model" "github.com/meshery/schemas/models/v1beta3/component" @@ -34,7 +33,7 @@ type componentDefinitionWithModel struct { ComponentDefinitionDB component.ComponentDefinition `gorm:"embedded"` ModelDB model.ModelDefinition `gorm:"embedded"` CategoryDB category.CategoryDefinition `gorm:"embedded"` - ConnectionDB connectionv1beta1.Connection `gorm:"embedded"` + ConnectionDB connectionv1beta3.Connection `gorm:"embedded"` } func (cf *ComponentFilter) GetById(db *database.Handler) (entity.Entity, error) { @@ -149,19 +148,14 @@ func (componentFilter *ComponentFilter) Get(db *database.Handler) ([]entity.Enti cm.ComponentDefinitionDB.Component.Schema = "" } - reg := cm.ConnectionDB cd := cm.ComponentDefinitionDB cd.Model = &cm.ModelDB if cd.Model != nil { cd.Model.Category = cm.CategoryDB - cd.Model.Registrant = connectionv1beta3.Connection{ - ID: reg.ID, - Name: reg.Name, - Kind: reg.Kind, - Type: reg.Type, - SubType: reg.SubType, - Status: connectionv1beta3.ConnectionStatus(reg.Status), - } + // ConnectionDB is now typed as v1beta3.Connection — assign directly. + // GORM reads all columns (description, url, sub_type, etc.) correctly + // since db: tags are identical to the connections table columns. + cd.Model.Registrant = cm.ConnectionDB } defs = append(defs, &cd) }