Skip to content

Commit eceaae7

Browse files
committed
add: version column to crawls table
1 parent f74507c commit eceaae7

8 files changed

Lines changed: 31 additions & 7 deletions

cmd/nebula/cmd_crawl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func CrawlAction(c *cli.Context) error {
194194
// Inserting a crawl row into the db so that we
195195
// can associate results with this crawl via
196196
// its DB identifier
197-
dbCrawl, err := dbc.InitCrawl(ctx)
197+
dbCrawl, err := dbc.InitCrawl(ctx, cfg.Root.Version())
198198
if err != nil {
199199
return fmt.Errorf("creating crawl in db: %w", err)
200200
}

pkg/db/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616

1717
type Client interface {
1818
io.Closer
19-
InitCrawl(ctx context.Context) (*models.Crawl, error)
19+
InitCrawl(ctx context.Context, version string) (*models.Crawl, error)
2020
UpdateCrawl(ctx context.Context, crawl *models.Crawl) error
2121
PersistCrawlProperties(ctx context.Context, crawl *models.Crawl, properties map[string]map[string]int) error
2222
PersistCrawlVisit(ctx context.Context, crawlID int, peerID peer.ID, maddrs []ma.Multiaddr, protocols []string, agentVersion string, connectDuration time.Duration, crawlDuration time.Duration, visitStartedAt time.Time, visitEndedAt time.Time, connectErrorStr string, crawlErrorStr string, properties null.JSON) (*InsertVisitResult, error)

pkg/db/client_db.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,11 @@ func partitionQuery(table string, lower time.Time, upper time.Time) string {
255255

256256
// InitCrawl inserts a crawl instance into the database in the state `started`.
257257
// This is done to receive a database ID that all subsequent database entities can be linked to.
258-
func (c *DBClient) InitCrawl(ctx context.Context) (*models.Crawl, error) {
258+
func (c *DBClient) InitCrawl(ctx context.Context, version string) (*models.Crawl, error) {
259259
crawl := &models.Crawl{
260260
State: models.CrawlStateStarted,
261261
StartedAt: time.Now(),
262+
Version: version,
262263
}
263264
return crawl, crawl.Insert(ctx, c.dbh, boil.Infer())
264265
}

pkg/db/client_json.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,13 @@ func InitJSONClient(out string) (Client, error) {
6666
return client, nil
6767
}
6868

69-
func (c *JSONClient) InitCrawl(ctx context.Context) (*models.Crawl, error) {
69+
func (c *JSONClient) InitCrawl(ctx context.Context, version string) (*models.Crawl, error) {
7070
crawl := &models.Crawl{
7171
State: models.CrawlStateStarted,
7272
StartedAt: time.Now(),
73+
Version: version,
74+
UpdatedAt: time.Now(),
75+
CreatedAt: time.Now(),
7376
}
7477

7578
data, err := json.Marshal(crawl)
@@ -85,6 +88,8 @@ func (c *JSONClient) InitCrawl(ctx context.Context) (*models.Crawl, error) {
8588
}
8689

8790
func (c *JSONClient) UpdateCrawl(ctx context.Context, crawl *models.Crawl) error {
91+
crawl.UpdatedAt = time.Now()
92+
8893
data, err := json.Marshal(crawl)
8994
if err != nil {
9095
return fmt.Errorf("marshal crawl json: %w", err)

pkg/db/client_noop.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ func InitNoopClient() *NoopClient {
1919
return &NoopClient{}
2020
}
2121

22-
func (n *NoopClient) InitCrawl(ctx context.Context) (*models.Crawl, error) {
22+
func (n *NoopClient) InitCrawl(ctx context.Context, version string) (*models.Crawl, error) {
2323
return &models.Crawl{
2424
ID: 1,
2525
StartedAt: time.Now(),
2626
State: models.CrawlStateStarted,
27+
Version: version,
2728
UpdatedAt: time.Now(),
2829
CreatedAt: time.Now(),
2930
}, nil
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE crawls DROP COLUMN version;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
BEGIN;
2+
3+
ALTER TABLE crawls ADD COLUMN version TEXT;
4+
5+
UPDATE crawls SET version = 'undefined';
6+
7+
ALTER TABLE crawls ALTER COLUMN version SET NOT NULL;
8+
9+
COMMIT;

pkg/models/crawls.go

Lines changed: 9 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)