Skip to content
Snippets Groups Projects
Commit 52b493e7 authored by Jake Taylor's avatar Jake Taylor :lips:
Browse files

Merge branch 'hotfix/unique' into 'release'

Fix relationship from users to ephemerals

See merge request elixxir/notifications-bot!14
parents fc3ed7cc 203acc3f
No related branches found
No related tags found
2 merge requests!15Release,!14Fix relationship from users to ephemerals
......@@ -17,7 +17,7 @@ type database interface {
GetAllUsers() ([]*User, error)
DeleteUserByHash(transmissionRsaHash []byte) error
upsertEphemeral(ephemeral *Ephemeral) error
insertEphemeral(ephemeral *Ephemeral) error
GetEphemeral(ephemeralId int64) ([]*Ephemeral, error)
GetLatestEphemeral() (*Ephemeral, error)
DeleteOldEphemerals(currentEpoch int32) error
......@@ -53,7 +53,7 @@ type User struct {
type Ephemeral struct {
ID uint `gorm:"primaryKey"`
Offset int64 `gorm:"not null; index"`
TransmissionRSAHash []byte `gorm:"not null; unique; references users(transmission_rsa_hash)"`
TransmissionRSAHash []byte `gorm:"not null; references users(transmission_rsa_hash)"`
EphemeralId int64 `gorm:"not null; index"`
Epoch int32 `gorm:"not null; index"`
}
......
......@@ -11,7 +11,6 @@ package storage
import (
"github.com/pkg/errors"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
// Obtain User from backend by primary key
......@@ -68,10 +67,8 @@ func (impl *DatabaseImpl) GetAllUsers() ([]*User, error) {
return dest, impl.db.Find(&dest).Error
}
func (impl *DatabaseImpl) upsertEphemeral(ephemeral *Ephemeral) error {
return impl.db.Clauses(clause.OnConflict{
UpdateAll: true,
}).Create(&ephemeral).Error
func (impl *DatabaseImpl) insertEphemeral(ephemeral *Ephemeral) error {
return impl.db.Create(&ephemeral).Error
}
func (impl *DatabaseImpl) GetEphemeral(ephemeralId int64) ([]*Ephemeral, error) {
......
......@@ -95,7 +95,7 @@ func (m *MapImpl) GetAllUsers() ([]*User, error) {
return m.allUsers, nil
}
func (m *MapImpl) upsertEphemeral(ephemeral *Ephemeral) error {
func (m *MapImpl) insertEphemeral(ephemeral *Ephemeral) error {
m.ephIDSeq++
ephemeral.ID = uint(m.ephIDSeq)
m.ephemeralsById[ephemeral.EphemeralId] = append(m.ephemeralsById[ephemeral.EphemeralId], ephemeral)
......
......@@ -311,7 +311,7 @@ func TestMapImpl_UpsertEphemeral(t *testing.T) {
t.Errorf("Failed to create ephemeral ID: %+v", err)
}
err = m.upsertEphemeral(&Ephemeral{
err = m.insertEphemeral(&Ephemeral{
Offset: 0,
TransmissionRSAHash: trsaHash,
EphemeralId: eid.Int64(),
......@@ -361,7 +361,7 @@ func TestMapImpl_GetEphemeral(t *testing.T) {
t.Errorf("FAiled to create ephemeral ID: %+v", err)
}
err = m.upsertEphemeral(&Ephemeral{
err = m.insertEphemeral(&Ephemeral{
Offset: 0,
TransmissionRSAHash: trsaHash,
EphemeralId: eid.Int64(),
......@@ -408,7 +408,7 @@ func TestMapImpl_DeleteOldEphemerals(t *testing.T) {
t.Errorf("FAiled to create ephemeral ID: %+v", err)
}
err = m.upsertEphemeral(&Ephemeral{
err = m.insertEphemeral(&Ephemeral{
Offset: 0,
TransmissionRSAHash: trsaHash,
EphemeralId: eid.Int64(),
......@@ -462,7 +462,7 @@ func TestMapImpl_GetLatestEphemeral(t *testing.T) {
t.Errorf("FAiled to create ephemeral ID: %+v", err)
}
err = m.upsertEphemeral(&Ephemeral{
err = m.insertEphemeral(&Ephemeral{
Offset: 0,
TransmissionRSAHash: trsaHash,
EphemeralId: eid.Int64(),
......
......@@ -55,7 +55,7 @@ func (s *Storage) AddLatestEphemeral(u *User, epoch int32, size uint) (*Ephemera
Epoch: epoch,
Offset: u.OffsetNum,
}
err = s.upsertEphemeral(e)
err = s.insertEphemeral(e)
if err != nil {
return nil, err
}
......@@ -71,7 +71,7 @@ func (s *Storage) AddLatestEphemeral(u *User, epoch int32, size uint) (*Ephemera
Epoch: epoch + 1,
Offset: u.OffsetNum,
}
err = s.upsertEphemeral(e)
err = s.insertEphemeral(e)
if err != nil {
return nil, err
}
......@@ -105,7 +105,7 @@ func (s *Storage) AddEphemeralsForOffset(offset int64, epoch int32, size uint, t
if err != nil {
return errors.WithMessage(err, "Failed to get eid for user")
}
err = s.upsertEphemeral(&Ephemeral{
err = s.insertEphemeral(&Ephemeral{
TransmissionRSAHash: u.TransmissionRSAHash,
EphemeralId: eid.Int64(),
Epoch: epoch,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment