Compare commits
No commits in common. "1540e5bbce67dfbea31a8fc7a6685ab06ea46947" and "746ca0c5f039beb34b4407b47231b17dde48015b" have entirely different histories.
1540e5bbce
...
746ca0c5f0
@ -1,5 +0,0 @@
|
|||||||
-- +migrate Up
|
|
||||||
|
|
||||||
ALTER TABLE "Pool"
|
|
||||||
ALTER
|
|
||||||
COLUMN name TYPE TEXT;
|
|
@ -1,5 +0,0 @@
|
|||||||
-- +migrate Up
|
|
||||||
|
|
||||||
ALTER TABLE "Source"
|
|
||||||
ADD COLUMN enabled BOOL DEFAULT FALSE,
|
|
||||||
ADD COLUMN meta JSON DEFAULT '{}';
|
|
@ -245,37 +245,3 @@ func DeleteSource(ctx context.Context, id models.SourceID) error {
|
|||||||
utils.HandleEvent(span, localLogger, "Source deleted successfully")
|
utils.HandleEvent(span, localLogger, "Source deleted successfully")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateKnownSources(ctx context.Context) ([]models.Source, error) {
|
|
||||||
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateKnownSources")
|
|
||||||
defer span.End()
|
|
||||||
|
|
||||||
if client == nil {
|
|
||||||
return nil, utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.DatabaseIsNotConnected})
|
|
||||||
}
|
|
||||||
|
|
||||||
sources := []models.Source{
|
|
||||||
{
|
|
||||||
DisplayName: "e621",
|
|
||||||
Domain: "e621.net",
|
|
||||||
Icon: "https://e621.net/safari-pinned-tab.svg",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
DisplayName: "Fur Affinity",
|
|
||||||
Domain: "furaffinity.net",
|
|
||||||
Icon: "https://www.furaffinity.net/themes/beta/img/banners/fa_logo.png",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
result := client.WithContext(ctx).Model(models.Source{}).CreateInBatches(sources, len(sources))
|
|
||||||
if result.Error != nil {
|
|
||||||
if errors.Is(result.Error, gorm.ErrDuplicatedKey) {
|
|
||||||
return nil, utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.DuplicateKey})
|
|
||||||
}
|
|
||||||
return nil, utils.HandleError(ctx, span, localLogger, result.Error)
|
|
||||||
}
|
|
||||||
|
|
||||||
utils.HandleEvent(span, localLogger, "Batch posts created successfully")
|
|
||||||
|
|
||||||
return sources, nil
|
|
||||||
}
|
|
||||||
|
@ -537,34 +537,6 @@ func TestDeleteSource(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateKnownSources(t *testing.T) {
|
|
||||||
// Setup trow away container
|
|
||||||
ctx := context.Background()
|
|
||||||
container, gormDB, err := test.StartPostgresContainer(ctx)
|
|
||||||
if err != nil {
|
|
||||||
logger.Fatalf("Could not start PostgreSQL container: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
client = gormDB
|
|
||||||
|
|
||||||
// Setup open telemetry
|
|
||||||
tracer = otel.Tracer(tracingName)
|
|
||||||
|
|
||||||
hook := otellogrus.NewHook(tracingName)
|
|
||||||
logger.AddHook(hook)
|
|
||||||
|
|
||||||
defer container.Terminate(ctx)
|
|
||||||
|
|
||||||
// -- -- Tests
|
|
||||||
|
|
||||||
t.Run("CreateKnownSources", func(t *testing.T) {
|
|
||||||
_, err := CreateKnownSources(ctx)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("DeleteSource() error = %v", err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func checkSourceID(got models.Source, want models.Source) bool {
|
func checkSourceID(got models.Source, want models.Source) bool {
|
||||||
if got.ID != want.ID {
|
if got.ID != want.ID {
|
||||||
return false
|
return false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user