1
0
mirror of synced 2024-12-03 16:26:02 +03:00

improve user save

This commit is contained in:
DmitryZagorulko 2018-12-27 16:06:08 +03:00
parent 09c70a537e
commit 9e146a540d
4 changed files with 14 additions and 3 deletions

2
go.sum
View File

@ -95,8 +95,6 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/retailcrm/api-client-go v1.1.0 h1:APPO6ccJAeMV7Jz7BhrtDKSOm2r1j5Ft6fuEXNP2ij4=
github.com/retailcrm/api-client-go v1.1.0/go.mod h1:QRoPE2SM6ST7i2g0yEdqm7Iw98y7cYuq3q14Ot+6N8c=
github.com/retailcrm/mg-transport-api-client-go v1.1.20 h1:1aDJ2QVtSkMtSUm50exmzQFSsE+/FQiWYdw2pamUyLc=
github.com/retailcrm/mg-transport-api-client-go v1.1.20/go.mod h1:AWV6BueE28/6SCoyfKURTo4lF0oXYoOKmHTzehd5vAI=
github.com/retailcrm/mg-transport-api-client-go v1.1.21 h1:OKkey9uvB16ucICuO2hp/tfh0wfp3na0CxRiT2Iv3sE=
github.com/retailcrm/mg-transport-api-client-go v1.1.21/go.mod h1:AWV6BueE28/6SCoyfKURTo4lF0oXYoOKmHTzehd5vAI=
github.com/smartystreets/assertions v0.0.0-20180820201707-7c9eb446e3cf h1:6V1qxN6Usn4jy8unvggSJz/NC790tefw8Zdy6OZS5co=

View File

@ -0,0 +1,2 @@
alter table mg_user alter column created_at drop default;
alter table mg_user alter column updated_at drop default;

View File

@ -0,0 +1,2 @@
alter table mg_user alter column created_at set default current_timestamp;
alter table mg_user alter column updated_at set default current_timestamp;

View File

@ -99,7 +99,16 @@ func getConnectionById(id int) *Connection {
}
func (u *User) save() error {
return orm.DB.Save(u).Error
return orm.DB.Exec(
"INSERT INTO mg_user (external_id, user_photo_url, user_photo_id) "+
"VALUES (?, ?, ?) "+
"ON CONFLICT (external_id) DO UPDATE SET "+
"user_photo_url = excluded.user_photo_url, user_photo_id=excluded.user_photo_id, updated_at= ?",
u.ExternalID,
u.UserPhotoURL,
u.UserPhotoID,
time.Now(),
).Error
}
func getUserByExternalID(eid int) *User {