From beeaed0c3e0e377f188edbda2da24d0676a45df6 Mon Sep 17 00:00:00 2001 From: gkcalat <35157096+gkcalat@users.noreply.github.com> Date: Thu, 16 Feb 2023 13:22:37 -0800 Subject: [PATCH] fix(backend): Add default values to timestamps. Fixes #8845 (#8857) * Add default values to timestamps * Force not-null create, null-able other timestamps --- backend/src/apiserver/model/job.go | 2 +- backend/src/apiserver/model/task.go | 4 ++-- backend/src/apiserver/storage/experiment_store.go | 4 ++-- backend/src/apiserver/storage/job_store.go | 10 +++++----- backend/src/apiserver/storage/pipeline_store.go | 5 ++--- backend/src/apiserver/storage/run_store.go | 8 ++++---- backend/src/apiserver/storage/task_store.go | 8 ++++---- 7 files changed, 20 insertions(+), 21 deletions(-) diff --git a/backend/src/apiserver/model/job.go b/backend/src/apiserver/model/job.go index a12ab2d8cf3..c47576cbb80 100644 --- a/backend/src/apiserver/model/job.go +++ b/backend/src/apiserver/model/job.go @@ -95,7 +95,7 @@ type Job struct { MaxConcurrency int64 `gorm:"column:MaxConcurrency; not null;"` NoCatchup bool `gorm:"column:NoCatchup; not null;"` CreatedAtInSec int64 `gorm:"column:CreatedAtInSec; not null;"` /* The time this record is stored in DB*/ - UpdatedAtInSec int64 `gorm:"column:UpdatedAtInSec; not null;"` + UpdatedAtInSec int64 `gorm:"column:UpdatedAtInSec; default:0;"` Enabled bool `gorm:"column:Enabled; not null;"` ExperimentId string `gorm:"column:ExperimentUUID; not null;"` // ResourceReferences are deprecated. Use Namespace, ExperimentId diff --git a/backend/src/apiserver/model/task.go b/backend/src/apiserver/model/task.go index 25d6091d3e2..08897989ce4 100644 --- a/backend/src/apiserver/model/task.go +++ b/backend/src/apiserver/model/task.go @@ -22,8 +22,8 @@ type Task struct { RunId string `gorm:"column:RunUUID; not null;"` MLMDExecutionID string `gorm:"column:MLMDExecutionID; not null;"` CreatedTimestamp int64 `gorm:"column:CreatedTimestamp; not null;"` - StartedTimestamp int64 `gorm:"column:StartedTimestamp;"` - FinishedTimestamp int64 `gorm:"column:FinishedTimestamp;"` + StartedTimestamp int64 `gorm:"column:StartedTimestamp; default:0;"` + FinishedTimestamp int64 `gorm:"column:FinishedTimestamp; default:0;"` Fingerprint string `gorm:"column:Fingerprint; not null;"` Name string `gorm:"column:Name; default:null"` ParentTaskId string `gorm:"column:ParentTaskUUID; default:null"` diff --git a/backend/src/apiserver/storage/experiment_store.go b/backend/src/apiserver/storage/experiment_store.go index a44b76fe196..01b6dc1cfd7 100644 --- a/backend/src/apiserver/storage/experiment_store.go +++ b/backend/src/apiserver/storage/experiment_store.go @@ -192,7 +192,7 @@ func (s *ExperimentStore) scanRows(rows *sql.Rows) ([]*model.Experiment, error) var experiments []*model.Experiment for rows.Next() { var uuid, name, description, namespace, storageState string - var createdAtInSec int64 + var createdAtInSec sql.NullInt64 err := rows.Scan(&uuid, &name, &description, &createdAtInSec, &namespace, &storageState) if err != nil { return experiments, err @@ -201,7 +201,7 @@ func (s *ExperimentStore) scanRows(rows *sql.Rows) ([]*model.Experiment, error) UUID: uuid, Name: name, Description: description, - CreatedAtInSec: createdAtInSec, + CreatedAtInSec: createdAtInSec.Int64, Namespace: namespace, StorageState: model.StorageState(storageState).ToV2(), } diff --git a/backend/src/apiserver/storage/job_store.go b/backend/src/apiserver/storage/job_store.go index 788d093f03f..7c25b2a48cb 100644 --- a/backend/src/apiserver/storage/job_store.go +++ b/backend/src/apiserver/storage/job_store.go @@ -230,12 +230,12 @@ func (s *JobStore) scanRows(r *sql.Rows) ([]*model.Job, error) { for r.Next() { var uuid, displayName, name, namespace, pipelineId, pipelineName, conditions, serviceAccount, description, parameters, pipelineSpecManifest, workflowSpecManifest string - var cronScheduleStartTimeInSec, cronScheduleEndTimeInSec, - periodicScheduleStartTimeInSec, periodicScheduleEndTimeInSec, intervalSecond sql.NullInt64 + var cronScheduleStartTimeInSec, cronScheduleEndTimeInSec, createdAtInSec, + periodicScheduleStartTimeInSec, periodicScheduleEndTimeInSec, intervalSecond, updatedAtInSec sql.NullInt64 var cron, resourceReferencesInString, runtimeParameters, pipelineRoot sql.NullString var experimentId, pipelineVersionId sql.NullString var enabled, noCatchup bool - var createdAtInSec, updatedAtInSec, maxConcurrency int64 + var maxConcurrency int64 err := r.Scan( &uuid, &displayName, &name, &namespace, &serviceAccount, &description, &maxConcurrency, &noCatchup, &createdAtInSec, &updatedAtInSec, &enabled, @@ -299,8 +299,8 @@ func (s *JobStore) scanRows(r *sql.Rows) ([]*model.Job, error) { Parameters: parameters, RuntimeConfig: runtimeConfig, }, - CreatedAtInSec: createdAtInSec, - UpdatedAtInSec: updatedAtInSec, + CreatedAtInSec: createdAtInSec.Int64, + UpdatedAtInSec: updatedAtInSec.Int64, } job = job.ToV1().ToV2() jobs = append(jobs, job) diff --git a/backend/src/apiserver/storage/pipeline_store.go b/backend/src/apiserver/storage/pipeline_store.go index 2000a9497a8..b8765ab5bc6 100644 --- a/backend/src/apiserver/storage/pipeline_store.go +++ b/backend/src/apiserver/storage/pipeline_store.go @@ -379,10 +379,9 @@ func (s *PipelineStore) scanJoinedRows(rows *sql.Rows) ([]*model.Pipeline, []*mo for rows.Next() { var uuid, name, description string var namespace sql.NullString - var createdAtInSec int64 var status model.PipelineStatus var versionUUID, versionName, versionParameters, versionPipelineId, versionCodeSourceUrl, versionStatus, versionDescription, pipelineSpec, pipelineSpecURI sql.NullString - var versionCreatedAtInSec sql.NullInt64 + var createdAtInSec, versionCreatedAtInSec sql.NullInt64 if err := rows.Scan( &uuid, &createdAtInSec, @@ -407,7 +406,7 @@ func (s *PipelineStore) scanJoinedRows(rows *sql.Rows) ([]*model.Pipeline, []*mo pipelines, &model.Pipeline{ UUID: uuid, - CreatedAtInSec: createdAtInSec, + CreatedAtInSec: createdAtInSec.Int64, Name: name, Description: description, Status: status, diff --git a/backend/src/apiserver/storage/run_store.go b/backend/src/apiserver/storage/run_store.go index 6789b07c802..2bd3e990c70 100644 --- a/backend/src/apiserver/storage/run_store.go +++ b/backend/src/apiserver/storage/run_store.go @@ -292,7 +292,7 @@ func (s *RunStore) scanRowsToRuns(rows *sql.Rows) ([]*model.Run, error) { var uuid, experimentUUID, displayName, name, storageState, namespace, serviceAccount, conditions, description, pipelineId, pipelineName, pipelineSpecManifest, workflowSpecManifest, parameters, pipelineRuntimeManifest, workflowRuntimeManifest string - var createdAtInSec, scheduledAtInSec, finishedAtInSec int64 + var createdAtInSec, scheduledAtInSec, finishedAtInSec sql.NullInt64 var metricsInString, resourceReferencesInString, runtimeParameters, pipelineRoot, jobId, state, stateHistory, pipelineVersionId sql.NullString err := rows.Scan( &uuid, @@ -370,9 +370,9 @@ func (s *RunStore) scanRowsToRuns(rows *sql.Rows) ([]*model.Run, error) { Description: description, RecurringRunId: jId, RunDetails: model.RunDetails{ - CreatedAtInSec: createdAtInSec, - ScheduledAtInSec: scheduledAtInSec, - FinishedAtInSec: finishedAtInSec, + CreatedAtInSec: createdAtInSec.Int64, + ScheduledAtInSec: scheduledAtInSec.Int64, + FinishedAtInSec: finishedAtInSec.Int64, Conditions: conditions, State: model.RuntimeState(state.String), PipelineRuntimeManifest: pipelineRuntimeManifest, diff --git a/backend/src/apiserver/storage/task_store.go b/backend/src/apiserver/storage/task_store.go index 167c8b0dfc6..b0e51d3af68 100644 --- a/backend/src/apiserver/storage/task_store.go +++ b/backend/src/apiserver/storage/task_store.go @@ -119,7 +119,7 @@ func (s *TaskStore) scanRows(rows *sql.Rows) ([]*model.Task, error) { for rows.Next() { var uuid, namespace, pipelineName, runUUID, mlmdExecutionID, fingerprint string var name, parentTaskId, state, stateHistory, inputs, outputs sql.NullString - var createdTimestamp, startedTimestamp, finishedTimestamp int64 + var createdTimestamp, startedTimestamp, finishedTimestamp sql.NullInt64 err := rows.Scan( &uuid, &namespace, @@ -147,9 +147,9 @@ func (s *TaskStore) scanRows(rows *sql.Rows) ([]*model.Task, error) { PipelineName: pipelineName, RunId: runUUID, MLMDExecutionID: mlmdExecutionID, - CreatedTimestamp: createdTimestamp, - StartedTimestamp: startedTimestamp, - FinishedTimestamp: finishedTimestamp, + CreatedTimestamp: createdTimestamp.Int64, + StartedTimestamp: startedTimestamp.Int64, + FinishedTimestamp: finishedTimestamp.Int64, Fingerprint: fingerprint, Name: name.String, ParentTaskId: parentTaskId.String,