Compare commits
2 Commits
d753d32025
...
4312cbdff5
Author | SHA1 | Date | |
---|---|---|---|
4312cbdff5 | |||
b1e97f4142 |
11
pkg/database/migrations/004_scrape_history.sql
Normal file
11
pkg/database/migrations/004_scrape_history.sql
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
-- +migrate Up
|
||||||
|
CREATE TABLE "ScrapeHistory"
|
||||||
|
(
|
||||||
|
user_source_id CHAR(25) NOT NULL REFERENCES "UserSource" (id),
|
||||||
|
scrape_task_id CHAR(25) PRIMARY KEY,
|
||||||
|
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
finished_at TIMESTAMP NULL,
|
||||||
|
error TEXT NULL,
|
||||||
|
added_posts INT NOT NULL,
|
||||||
|
deleted_posts INT NOT NULL
|
||||||
|
);
|
19
pkg/models/scrape_history.go
Normal file
19
pkg/models/scrape_history.go
Normal file
@ -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"
|
||||||
|
}
|
11
pkg/models/scrape_history_test.go
Normal file
11
pkg/models/scrape_history_test.go
Normal file
@ -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)
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user