From 4312cbdff5cee8c73e24ad9dc2b2166699101c78 Mon Sep 17 00:00:00 2001 From: SoXX Date: Tue, 15 Oct 2024 11:23:33 +0200 Subject: [PATCH] feat(database): added model - added model - added test for model --- pkg/models/scrape_history.go | 19 +++++++++++++++++++ pkg/models/scrape_history_test.go | 11 +++++++++++ 2 files changed, 30 insertions(+) create mode 100644 pkg/models/scrape_history.go create mode 100644 pkg/models/scrape_history_test.go diff --git a/pkg/models/scrape_history.go b/pkg/models/scrape_history.go new file mode 100644 index 0000000..e06f6c5 --- /dev/null +++ b/pkg/models/scrape_history.go @@ -0,0 +1,19 @@ +package models + +import ( + "time" +) + +type ScrapeHistory struct { + ScrapeTaskID string `json:"scrape_task_id" gorm:"primaryKey"` + UserSourceID string `json:"user_source_id" gorm:""` + CreatedAt time.Time `json:"created_at" gorm:""` + FinishedAt time.Time `json:"finished_at" gorm:"null"` + Error string `json:"error" gorm:"null"` + AddedPosts int `json:"added_posts" gorm:"not null"` + DeletedPosts int `json:"deleted_posts" gorm:"not null"` +} + +func (ScrapeHistory) TableName() string { + return "ScrapeHistory" +} diff --git a/pkg/models/scrape_history_test.go b/pkg/models/scrape_history_test.go new file mode 100644 index 0000000..d479a26 --- /dev/null +++ b/pkg/models/scrape_history_test.go @@ -0,0 +1,11 @@ +package models + +import "testing" + +func TestScrapeHistory_TableName(t *testing.T) { + scrapeHistory := ScrapeHistory{} + expectedTableName := "ScrapeHistory" + if tableName := scrapeHistory.TableName(); tableName != expectedTableName { + t.Fatalf("expected %s, but got %s", expectedTableName, tableName) + } +}