Create notification model/table
This commit is contained in:
parent
cbcb4361d5
commit
0f1b484e9a
|
@ -68,15 +68,40 @@ var (
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
tables = append(tables,
|
tables = append(tables,
|
||||||
new(User), new(PublicKey), new(AccessToken),
|
new(User),
|
||||||
new(Repository), new(DeployKey), new(Collaboration), new(Access), new(Upload),
|
new(PublicKey),
|
||||||
new(Watch), new(Star), new(Follow), new(Action),
|
new(AccessToken),
|
||||||
new(Issue), new(PullRequest), new(Comment), new(Attachment), new(IssueUser),
|
new(Repository),
|
||||||
new(Label), new(IssueLabel), new(Milestone),
|
new(DeployKey),
|
||||||
new(Mirror), new(Release), new(LoginSource), new(Webhook),
|
new(Collaboration),
|
||||||
new(UpdateTask), new(HookTask),
|
new(Access),
|
||||||
new(Team), new(OrgUser), new(TeamUser), new(TeamRepo),
|
new(Upload),
|
||||||
new(Notice), new(EmailAddress))
|
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"}
|
gonicNames := []string{"SSL", "UID"}
|
||||||
for _, name := range gonicNames {
|
for _, name := range gonicNames {
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
Loading…
Reference in New Issue