Skip to content

Commit 78c3dd2

Browse files
committed
cleaning ups before PR review - 1
Signed-off-by: kaikaila <[email protected]>
1 parent f6c1931 commit 78c3dd2

File tree

4 files changed

+16
-29
lines changed

4 files changed

+16
-29
lines changed

backend/src/apiserver/client_manager/client_manager.go

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -388,14 +388,6 @@ func ensureUniqueCompositeIndex(db *gorm.DB, model interface{}, indexName string
388388
}
389389
}
390390

391-
// This helper function enforces a composite unique index on a given model.
392-
// Refer to ensureUniqueCompositeIndex for details.
393-
// func ensureIndex(db *gorm.DB, model interface{}, indexName string) {
394-
// if err := db.Migrator().CreateIndex(model, indexName); err != nil {
395-
// glog.Fatalf("Failed to create index %s. Error: %s", indexName, err)
396-
// }
397-
// }
398-
399391
func InitDBClient(initConnectionTimeout time.Duration) *storage.DB {
400392
// Allowed driverName values:
401393
// 1) To use MySQL, use `mysql`
@@ -486,22 +478,18 @@ func InitDBClient(initConnectionTimeout time.Duration) *storage.DB {
486478
glog.Fatalf("Failed to update the resource reference payload type. Error: %s", response)
487479
}
488480

481+
// Manual AddForeignKey() and AddIndex() calls have been removed.
482+
// Both Methods are GORM v1 legacy which no longer exist in GORM v2.
483+
// Foreign key constraints are now defined and managed by GORM via struct tags 'constraint' and 'index'.
484+
// This ensures a single source of truth for schema definitions and avoids duplicate or out-of-sync DDL.
485+
486+
// The ensureUniqueCompositeIndex() method is called to replace the GORM v1 legacy AddUniqueIndex method.
489487
ensureUniqueCompositeIndex(db, &model.Pipeline{}, "namespace_name")
490488
ensureUniqueCompositeIndex(db, &model.Experiment{}, "idx_name_namespace")
491489
ensureUniqueCompositeIndex(db, &model.PipelineVersion{}, "idx_pipelineid_name")
492490

493-
// ensureIndex(db, &model.Run{}, "experimentuuid_createatinsec")
494-
// ensureIndex(db, &model.Run{}, "experimentuuid_conditions_finishedatinsec")
495-
// ensureIndex(db, &model.Run{}, "namespace_createatinsec")
496-
// ensureIndex(db, &model.Run{}, "namespace_conditions_finishedatinsec")
497-
498-
// Manual AddForeignKey() calls have been removed.
499-
// Foreign key constraints are now defined and managed by GORM via struct tags 'constraint'
500-
// on RunMetric.RunUUID, PipelineVersion.PipelineId, Task.RunUUID, etc.).
501-
// This ensures a single source of truth for schema definitions and avoids duplicate or out-of-sync DDL.
502-
503491
// Removed invalid ModifyColumn on Job.WorkflowSpecManifest.
504-
// This field never existed on Job; original reference likely confused with PipelineSpec.
492+
// This field does not exist on Job; original reference likely confused with PipelineSpec.
505493

506494
// Data backfill for pipeline_versions if this is the first time for
507495
// pipeline_versions to enter mlpipeline DB.

backend/src/apiserver/model/experiment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type Experiment struct {
2020
Description string `gorm:"column:Description; not null;"`
2121
CreatedAtInSec int64 `gorm:"column:CreatedAtInSec; not null;"`
2222
LastRunCreatedAtInSec int64 `gorm:"column:LastRunCreatedAtInSec; not null;"`
23-
Namespace string `gorm:"column:Namespace; not null; uniqueIndex:idx_name_namespace; type:varchar(255)"`
23+
Namespace string `gorm:"column:Namespace; not null; uniqueIndex:idx_name_namespace; type:varchar(63)"`
2424
StorageState StorageState `gorm:"column:StorageState; not null;"`
2525
}
2626

backend/src/apiserver/model/pipeline.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ const (
3333
type Pipeline struct {
3434
UUID string `gorm:"column:UUID; not null; primaryKey;"`
3535
CreatedAtInSec int64 `gorm:"column:CreatedAtInSec; not null;"`
36-
Name string `gorm:"column:Name; not null; uniqueIndex:namespace_name; size:191"` // Index improves performance of the List ang Get queries
36+
Name string `gorm:"column:Name; not null; uniqueIndex:namespace_name; type:varchar(191);"` // Index improves performance of the List ang Get queries
3737
DisplayName string `gorm:"column:DisplayName; not null"`
3838
Description string `gorm:"column:Description; type:text;"` // Use type:longtext instead of size to ensure sufficient capacity
3939
// TODO(gkcalat): this is deprecated. Consider removing and adding data migration logic at the server startup.
4040
Parameters string `gorm:"column:Parameters; type:text;"`
4141
Status PipelineStatus `gorm:"column:Status; not null;"`
4242
// TODO(gkcalat): this is deprecated. Consider removing and adding data migration logic at the server startup.
4343
DefaultVersionId string `gorm:"column:DefaultVersionId;"` // deprecated
44-
Namespace string `gorm:"column:Namespace; uniqueIndex:namespace_name; size:63;"`
44+
Namespace string `gorm:"column:Namespace; uniqueIndex:namespace_name; type:varchar(63);"`
4545
}
4646

4747
func (p Pipeline) GetValueOfPrimaryKey() string {
@@ -78,11 +78,6 @@ func (p *Pipeline) APIToModelFieldMap() map[string]string {
7878
return pipelineAPIToModelFieldMap
7979
}
8080

81-
// TableName overrides GORM default table name inference
82-
func (Pipeline) TableName() string {
83-
return "pipelines"
84-
}
85-
8681
// GetModelName returns table name used as sort field prefix.
8782
func (p *Pipeline) GetModelName() string {
8883
return "pipelines"

backend/src/apiserver/model/pipeline_version.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@ const (
3131
type PipelineVersion struct {
3232
UUID string `gorm:"column:UUID; not null; primaryKey;"`
3333
CreatedAtInSec int64 `gorm:"column:CreatedAtInSec; not null; index;"`
34-
Name string `gorm:"column:Name; not null; type:varchar(255); uniqueIndex:idx_pipelineid_name;"`
35-
DisplayName string `gorm:"column:DisplayName; not null"`
34+
// Explicitly specify type:varchar(255) to ensure MySQL can create index on this column.
35+
// In GORM v1, omitting type still allowed index creation due to default behavior.
36+
// However, GORM v2 requires explicit type declaration for indexed string fields,
37+
// otherwise it may default to longtext, which is not indexable in MySQL.
38+
Name string `gorm:"column:Name; not null; type:varchar(255); uniqueIndex:idx_pipelineid_name;"`
39+
DisplayName string `gorm:"column:DisplayName; not null"`
3640
// TODO(gkcalat): this is deprecated. Consider removing and adding data migration logic at the server startup.
3741
Parameters string `gorm:"column:Parameters; not null; type:text;"` // deprecated
3842
// PipelineVersion belongs to Pipeline. If a pipeline with a specific UUID

0 commit comments

Comments
 (0)