Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set default timestamps before insert #670

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions internal/models/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ type times struct {

func (t *times) BeforeAppendModel(ctx context.Context, query schema.Query) error {
switch query.(type) {
case *bun.InsertQuery:
t.CreatedAt = time.Now()
t.UpdatedAt = time.Now()
case *bun.UpdateQuery:
//q := query.(*bun.UpdateQuery)
//m := q.GetModel().Value()
Expand Down
6 changes: 3 additions & 3 deletions pkg/database/migrations/20240902082008_create_admin_photo.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (

type User struct {
ID int64 `bun:",pk,autoincrement" json:"id"`
Nickname string `bun:",notnull" json:"nickname"`
Name string `bun:",notnull,unique" json:"name"`
Email string `bun:",notnull,unique" json:"email"`
Nickname string `bun:"," json:"nickname"`
Name string `bun:"," json:"name"`
Email string `bun:"," json:"email"`
LoginIdentity string `bun:",pk,notnull" json:"login_identity"`
Gender string `bun:"," json:"gender"`
RolesMask int `bun:"," json:"roles_mask"`
Expand Down
Loading