From a55f0f8432811685afca31eaa1bc23ea46ae723d Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Tue, 14 Oct 2014 01:49:10 -0700 Subject: [PATCH] set created & updated dates in database --- server/datastore/database/commit.go | 10 ++++++++++ server/datastore/database/repo.go | 10 ++++++++++ server/datastore/database/user.go | 10 ++++++++++ 3 files changed, 30 insertions(+) diff --git a/server/datastore/database/commit.go b/server/datastore/database/commit.go index 5ad1e46f..19603c97 100644 --- a/server/datastore/database/commit.go +++ b/server/datastore/database/commit.go @@ -1,6 +1,8 @@ package database import ( + "time" + "github.com/drone/drone/shared/model" "github.com/russross/meddler" ) @@ -56,11 +58,19 @@ func (db *Commitstore) GetCommitListUser(user *model.User) ([]*model.CommitRepo, // PostCommit saves a commit in the datastore. func (db *Commitstore) PostCommit(commit *model.Commit) error { + if commit.Created == 0 { + commit.Created = time.Now().UTC().Unix() + } + commit.Updated = time.Now().UTC().Unix() return meddler.Save(db, commitTable, commit) } // PutCommit saves a commit in the datastore. func (db *Commitstore) PutCommit(commit *model.Commit) error { + if commit.Created == 0 { + commit.Created = time.Now().UTC().Unix() + } + commit.Updated = time.Now().UTC().Unix() return meddler.Save(db, commitTable, commit) } diff --git a/server/datastore/database/repo.go b/server/datastore/database/repo.go index 10073f18..464f0589 100644 --- a/server/datastore/database/repo.go +++ b/server/datastore/database/repo.go @@ -1,6 +1,8 @@ package database import ( + "time" + "github.com/drone/drone/shared/model" "github.com/russross/meddler" ) @@ -39,11 +41,19 @@ func (db *Repostore) GetRepoList(user *model.User) ([]*model.Repo, error) { // PostRepo saves a repo in the datastore. func (db *Repostore) PostRepo(repo *model.Repo) error { + if repo.Created == 0 { + repo.Created = time.Now().UTC().Unix() + } + repo.Updated = time.Now().UTC().Unix() return meddler.Save(db, repoTable, repo) } // PutRepo saves a repo in the datastore. func (db *Repostore) PutRepo(repo *model.Repo) error { + if repo.Created == 0 { + repo.Created = time.Now().UTC().Unix() + } + repo.Updated = time.Now().UTC().Unix() return meddler.Save(db, repoTable, repo) } diff --git a/server/datastore/database/user.go b/server/datastore/database/user.go index 8c79fced..25de0802 100644 --- a/server/datastore/database/user.go +++ b/server/datastore/database/user.go @@ -1,6 +1,8 @@ package database import ( + "time" + "github.com/drone/drone/shared/model" "github.com/russross/meddler" ) @@ -47,11 +49,19 @@ func (db *Userstore) GetUserList() ([]*model.User, error) { // PostUser saves a User in the datastore. func (db *Userstore) PostUser(user *model.User) error { + if user.Created == 0 { + user.Created = time.Now().UTC().Unix() + } + user.Updated = time.Now().UTC().Unix() return meddler.Save(db, userTable, user) } // PutUser saves a user in the datastore. func (db *Userstore) PutUser(user *model.User) error { + if user.Created == 0 { + user.Created = time.Now().UTC().Unix() + } + user.Updated = time.Now().UTC().Unix() return meddler.Save(db, userTable, user) }