set created & updated dates in database

This commit is contained in:
Brad Rydzewski 2014-10-14 01:49:10 -07:00
parent 42979c5503
commit a55f0f8432
3 changed files with 30 additions and 0 deletions

View file

@ -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)
}

View file

@ -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)
}

View file

@ -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)
}