Skip to content

Commit 8b74759

Browse files
committed
remove ALTER TABLE … ADD CONSTRAINT with GORM struct tags
Signed-off-by: kaikaila <[email protected]>
1 parent e4776f6 commit 8b74759

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed

backend/src/apiserver/client_manager/client_manager.go

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,6 @@ func InitDBClient(initConnectionTimeout time.Duration) *storage.DB {
373373
glog.Fatalf("Failed to initialize the databases. Error: %s", response.Error)
374374
}
375375

376-
377376
response = db.Migrator().DropIndex(&model.Experiment{}, "Name")
378377
if response != nil {
379378
glog.Fatalf("Failed to drop unique key on experiment name. Error: %s", response)
@@ -396,23 +395,15 @@ func InitDBClient(initConnectionTimeout time.Duration) *storage.DB {
396395
// – namespace_createatinsec
397396
// – namespace_conditions_finishedatinsec
398397
// – name_namespace_index
399-
// See the `index:` and `uniqueIndex:` tags in model.Run, model.RunDetails, and model.Pipeline.
398+
// See the `index:` and `uniqueIndex:` tags in model.Run and model.Pipeline.
400399

401-
switch driverName {
402-
case "pgx":
403-
db.Exec(`ALTER TABLE run_metrics ADD CONSTRAINT fk_run_metrics_runuuid FOREIGN KEY ("RunUUID") REFERENCES run_details("UUID") ON DELETE CASCADE ON UPDATE CASCADE`)
404-
db.Exec(`ALTER TABLE pipeline_versions ADD CONSTRAINT fk_pipeline_versions_pipelineid FOREIGN KEY ("PipelineId") REFERENCES pipelines("UUID") ON DELETE CASCADE ON UPDATE CASCADE`)
405-
db.Exec(`ALTER TABLE tasks ADD CONSTRAINT fk_tasks_runuuid FOREIGN KEY ("RunUUID") REFERENCES run_details("UUID") ON DELETE CASCADE ON UPDATE CASCADE`)
406-
case "mysql":
407-
db.Exec(`ALTER TABLE run_metrics ADD CONSTRAINT fk_run_metrics_runuuid FOREIGN KEY (RunUUID) REFERENCES run_details(UUID) ON DELETE CASCADE ON UPDATE CASCADE`)
408-
db.Exec(`ALTER TABLE pipeline_versions ADD CONSTRAINT fk_pipeline_versions_pipelineid FOREIGN KEY (PipelineId) REFERENCES pipelines(UUID) ON DELETE CASCADE ON UPDATE CASCADE`)
409-
db.Exec(`ALTER TABLE tasks ADD CONSTRAINT fk_tasks_runuuid FOREIGN KEY (RunUUID) REFERENCES run_details(UUID) ON DELETE CASCADE ON UPDATE CASCADE`)
400+
// Manual ALTER TABLE … ADD CONSTRAINT calls have been removed.
401+
// Foreign key constraints are now defined and managed by GORM via struct tags
402+
// on RunMetric.RunUUID, PipelineVersion.PipelineId, Task.RunUUID, etc.).
403+
// This ensures a single source of truth for schema definitions and avoids duplicate or out-of-sync DDL.
410404

411-
// Removed invalid ModifyColumn on Job.WorkflowSpecManifest.
412-
// This field never existed on Job; original reference likely confused with PipelineSpec.
413-
default:
414-
glog.Fatalf("Driver %v is not supported, use \"mysql\" for MySQL, or \"pgx\" for PostgreSQL", driverName)
415-
}
405+
// Removed invalid ModifyColumn on Job.WorkflowSpecManifest.
406+
// This field never existed on Job; original reference likely confused with PipelineSpec.
416407

417408
// Data backfill for pipeline_versions if this is the first time for
418409
// 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
@@ -26,7 +26,7 @@ type Experiment struct {
2626

2727
// Note: Experiment.StorageState can have values: "STORAGE_STATE_UNSPECIFIED", "AVAILABLE" or "ARCHIVED"
2828

29-
func (e Experiment) GetValueOfPrimaryKey() string {
29+
func (e Experiment) GetValueOfPrimaryKey() string {
3030
return e.UUID
3131
}
3232

backend/src/apiserver/model/task.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type Task struct {
2323
Namespace string `gorm:"column:Namespace; not null;"`
2424
// PipelineName was deprecated. Use RunId instead.
2525
PipelineName string `gorm:"column:PipelineName; not null;"`
26-
RunId string `gorm:"column:RunUUID; not null;"`
26+
RunId string `gorm:"column:RunUUID; type:varchar(191); not null;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
2727
PodName string `gorm:"column:PodName; not null;"`
2828
MLMDExecutionID string `gorm:"column:MLMDExecutionID; not null;"`
2929
CreatedTimestamp int64 `gorm:"column:CreatedTimestamp; not null;"`

0 commit comments

Comments
 (0)