From 0f1b484e9a0a687a343248d830daa7ffcbcc64c0 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Wed, 30 Nov 2016 20:31:10 -0200 Subject: [PATCH] Create notification model/table --- models/models.go | 43 ++++++++++++++++++++++++++------- models/notification.go | 54 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 9 deletions(-) create mode 100644 models/notification.go diff --git a/models/models.go b/models/models.go index 56306d61f..4b556c5ab 100644 --- a/models/models.go +++ b/models/models.go @@ -68,15 +68,40 @@ var ( func init() { tables = append(tables, - new(User), new(PublicKey), new(AccessToken), - new(Repository), new(DeployKey), new(Collaboration), new(Access), new(Upload), - new(Watch), new(Star), new(Follow), new(Action), - new(Issue), new(PullRequest), new(Comment), new(Attachment), new(IssueUser), - new(Label), new(IssueLabel), new(Milestone), - new(Mirror), new(Release), new(LoginSource), new(Webhook), - new(UpdateTask), new(HookTask), - new(Team), new(OrgUser), new(TeamUser), new(TeamRepo), - new(Notice), new(EmailAddress)) + new(User), + new(PublicKey), + new(AccessToken), + new(Repository), + new(DeployKey), + new(Collaboration), + new(Access), + new(Upload), + new(Watch), + new(Star), + new(Follow), + new(Action), + new(Issue), + new(PullRequest), + new(Comment), + new(Attachment), + new(IssueUser), + new(Label), + new(IssueLabel), + new(Milestone), + new(Mirror), + new(Release), + new(LoginSource), + new(Webhook), + new(UpdateTask), + new(HookTask), + new(Team), + new(OrgUser), + new(TeamUser), + new(TeamRepo), + new(Notice), + new(EmailAddress), + new(Notification), + ) gonicNames := []string{"SSL", "UID"} for _, name := range gonicNames { diff --git a/models/notification.go b/models/notification.go new file mode 100644 index 000000000..296852f23 --- /dev/null +++ b/models/notification.go @@ -0,0 +1,54 @@ +package models + +import ( + "time" +) + +const ( + NotificationStatusUnread = "U" + NotificationStatusRead = "R" + + NotificationSourceIssue = "I" + NotificationSourcePullRequest = "P" + NotificationSourceCommit = "C" +) + +type Notification struct { + ID int64 `xorm:"pk autoincr"` + UserID int64 `xorm:"INDEX NOT NULL"` + RepoID int64 `xorm:"INDEX NOT NULL"` + + Status string `xorm:"VARCHAR(1) INDEX NOT NULL"` + Source string `xorm:"VARCHAR(1) INDEX NOT NULL"` + + IssueID int64 `xorm:"INDEX NOT NULL"` + PullID int64 `xorm:"INDEX"` + CommitID string `xorm:"INDEX"` + + Issue *Issue `xorm:"-"` + PullRequest *PullRequest `xorm:"-"` + + Created time.Time `xorm:"-"` + CreatedUnix int64 `xorm:"INDEX NOT NULL"` + Updated time.Time `xorm:"-"` + UpdatedUnix int64 `xorm:"INDEX NOT NULL"` +} + +func (n *Notification) BeforeInsert() { + var ( + now = time.Now() + nowUnix = now.Unix() + ) + n.Created = now + n.CreatedUnix = nowUnix + n.Updated = now + n.UpdatedUnix = nowUnix +} +func (n *Notification) BeforeUpdate() { + var ( + now = time.Now() + nowUnix = now.Unix() + ) + n.Updated = now + n.UpdatedUnix = nowUnix +}