30 lines
920 B
Go
30 lines
920 B
Go
package database
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/uptrace/bun"
|
|
)
|
|
|
|
type Task struct {
|
|
ID int64 `bun:",pk,autoincrement"`
|
|
IssuerID int32 `bun:",notnull" json:"issuerID"`
|
|
Issuer *User `bun:"rel:belongs-to,join:issuer_id=id" json:"issuer"`
|
|
Configuration map[string]interface{} `bun:"type:jsonb" json:"configuration"`
|
|
CreatedAt time.Time `bun:",notnull,default:current_timestamp" json:"createdAt"`
|
|
FinishedAt time.Time `json:"finishedAt"`
|
|
UpdatedAt time.Time `json:"updatedAt"`
|
|
DeletedAt time.Time `bun:",soft_delete,nullzero" json:"deletedAt"`
|
|
}
|
|
|
|
var _ bun.BeforeAppendModelHook = (*Task)(nil)
|
|
|
|
func (s *Task) BeforeAppendModel(ctx context.Context, query bun.Query) error {
|
|
switch query.(type) {
|
|
case *bun.UpdateQuery:
|
|
s.UpdatedAt = time.Now()
|
|
}
|
|
return nil
|
|
}
|