fix(postgres): check if source exists before creating

Signed-off-by: soxx <soxx@fenpa.ws>
This commit is contained in:
SoXX 2024-06-21 15:08:42 +02:00
parent 795bcbdac3
commit 2515fc5081
2 changed files with 3 additions and 3 deletions

View File

@ -16,7 +16,7 @@ func CreateSourceNode(ctx context.Context, db *gorm.DB, anthroveSource *pgModels
return fmt.Errorf("anthroveSource domain is required")
}
result := db.WithContext(ctx).Create(anthroveSource)
result := db.WithContext(ctx).Where(pgModels.Source{Domain: anthroveSource.Domain}).FirstOrCreate(anthroveSource)
if result.Error != nil {
return result.Error

View File

@ -65,7 +65,7 @@ func TestCreateSourceNode(t *testing.T) {
db: gormDB,
anthroveSource: validAnthroveSource,
},
wantErr: true,
wantErr: false,
},
}
for _, tt := range tests {