From 149b6282920532727424c3bce088f603c429b3d9 Mon Sep 17 00:00:00 2001 From: Wenkai Yin Date: Thu, 9 Nov 2017 13:43:46 +0800 Subject: [PATCH] update --- src/common/dao/replication_job.go | 27 +++++++++++++++++++-------- src/common/models/replication_job.go | 2 +- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/common/dao/replication_job.go b/src/common/dao/replication_job.go index 8771b179c..6fd4e17c6 100644 --- a/src/common/dao/replication_job.go +++ b/src/common/dao/replication_job.go @@ -107,15 +107,26 @@ func AddRepPolicy(policy models.RepPolicy) (int64, error) { if err := policy.Marshal(); err != nil { return 0, err } - now := time.Now() - policy.CreationTime = now - policy.UpdateTime = now - if policy.Enabled == 1 { - policy.StartTime = now - } - policy.Deleted = 0 - return GetOrmer().Insert(&policy) + o := GetOrmer() + sql := `insert into replication_policy (name, project_id, target_id, enabled, description, cron_str, start_time, creation_time, update_time, filters, replicate_deletion) + values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)` + params := []interface{}{} + params = append(params, policy.Name, policy.ProjectID, policy.TargetID, policy.Enabled, policy.Description, policy.TriggerInDB) + now := time.Now() + if policy.Enabled == 1 { + params = append(params, now) + } else { + params = append(params, nil) + } + params = append(params, now, now, policy.FiltersInDB, policy.ReplicateDeletion) + + result, err := o.Raw(sql, params...).Exec() + if err != nil { + return 0, err + } + + return result.LastInsertId() } // GetRepPolicy ... diff --git a/src/common/models/replication_job.go b/src/common/models/replication_job.go index 55d726c99..09cfa2169 100644 --- a/src/common/models/replication_job.go +++ b/src/common/models/replication_job.go @@ -45,7 +45,7 @@ type RepPolicy struct { ProjectID int64 `orm:"column(project_id)" json:"project_id"` ProjectName string `orm:"-" json:"project_name,omitempty"` TargetID int64 `orm:"column(target_id)" json:"target_id"` - TargetName string `orm:"-" json:"target_name,omitempty"` + TargetName string `json:"target_name,omitempty"` Name string `orm:"column(name)" json:"name"` Enabled int `orm:"column(enabled)" json:"enabled"` Description string `orm:"column(description)" json:"description"`