Create notification model/table

This commit is contained in:
Andrey Nering 2016-11-30 20:31:10 -02:00
parent cbcb4361d5
commit 0f1b484e9a
2 changed files with 88 additions and 9 deletions

View File

@ -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 {

54
models/notification.go Normal file
View File

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