From 8599857124b0401cf4e379d1133add6218c05317 Mon Sep 17 00:00:00 2001 From: meskio <meskio@sindominio.net> Date: Wed, 28 Oct 2020 18:03:35 +0100 Subject: [PATCH] Make num and code the primary keys --- api/db/member.go | 23 +++++++++++++---------- api/db/product.go | 14 +++++++++----- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/api/db/member.go b/api/db/member.go index 62ea7e6..4d3f738 100644 --- a/api/db/member.go +++ b/api/db/member.go @@ -17,16 +17,19 @@ const ( ) type Member struct { - gorm.Model `json:"-"` - Num int `json:"num" gorm:"unique;index"` - Login string `json:"login" gorm:"unique;index"` - Name string `json:"name"` - Email string `json:"email"` - Phone string `json:"phone"` - Balance int `json:"balance"` - Role string `json:"role"` - PassHash []byte `json:"-"` - Salt []byte `json:"-"` + CreatedAt time.Time `json:"-"` + UpdatedAt time.Time `json:"-"` + DeletedAt gorm.DeletedAt `json:"-" gorm:"index"` + + Num int `json:"num" gorm:"primaryKey"` + Login string `json:"login" gorm:"unique;index"` + Name string `json:"name"` + Email string `json:"email"` + Phone string `json:"phone"` + Balance int `json:"balance"` + Role string `json:"role"` + PassHash []byte `json:"-"` + Salt []byte `json:"-"` } type PasswordReset struct { diff --git a/api/db/product.go b/api/db/product.go index 238af81..30f183a 100644 --- a/api/db/product.go +++ b/api/db/product.go @@ -2,16 +2,20 @@ package db import ( "errors" + "time" "gorm.io/gorm" ) type Product struct { - gorm.Model `json:"-"` - Code int `json:"code" gorm:"unique;index"` - Name string `json:"name" gorm:"unique;index"` - Price int `json:"price"` - Stock int `json:"stock"` + CreatedAt time.Time `json:"-"` + UpdatedAt time.Time `json:"-"` + DeletedAt gorm.DeletedAt `json:"-" gorm:"index"` + + Code int `json:"code" gorm:"primaryKey"` + Name string `json:"name" gorm:"unique;index"` + Price int `json:"price"` + Stock int `json:"stock"` } func (d *DB) AddProduct(product *Product) error { -- GitLab