Skip to content

Commit

Permalink
change timestamps to be int64 (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
kristinapathak authored Mar 20, 2019
1 parent 6bad053 commit f1d6197
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 24 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [v0.2.6]
- Fixed birthdate and deathdate in record schema

## [v0.2.5]
- Modified record schema in `db` package

Expand Down Expand Up @@ -59,7 +62,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Initial creation
- Created `db` and `xvault` package

[Unreleased]: https://github.com/Comcast/codex/compare/v0.2.5...HEAD
[Unreleased]: https://github.com/Comcast/codex/compare/v0.2.6...HEAD
[v0.2.6]: https://github.com/Comcast/codex/compare/v0.2.5...v0.2.6
[v0.2.5]: https://github.com/Comcast/codex/compare/v0.2.4...v0.2.5
[v0.2.4]: https://github.com/Comcast/codex/compare/v0.2.3...v0.2.4
[v0.2.3]: https://github.com/Comcast/codex/compare/v0.2.2...v0.2.3
Expand Down
14 changes: 7 additions & 7 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ type Event struct {
}

type Record struct {
ID int `json:"id" gorm:"type:bigint;AUTO_INCREMENT"`
Type int `json:"type"`
DeviceID string `json:"deviceid" gorm:"not null;index"`
BirthDate time.Time `json:"birthdate" gorm:"type:bigint;not null;index"`
DeathDate time.Time `json:"deathdate" gorm:"type:bigint;not null;index"`
Data []byte `json:"data" gorm:"not null"`
ID int `json:"id" gorm:"AUTO_INCREMENT"`
Type int `json:"type"`
DeviceID string `json:"deviceid" gorm:"not null;index"`
BirthDate int64 `json:"birthdate" gorm:"not null;index"`
DeathDate int64 `json:"deathdate" gorm:"not null;index"`
Data []byte `json:"data" gorm:"not null"`
}

// set Record's table name to be `events`
Expand Down Expand Up @@ -273,7 +273,7 @@ func (db *Connection) GetRecordsOfType(deviceID string, eventType int) ([]Record
}

// PruneRecords removes records past their deathdate.
func (db *Connection) PruneRecords(t time.Time) error {
func (db *Connection) PruneRecords(t int64) error {
rowsAffected, err := db.deleter.delete(&Record{}, "death_date < ?", t)
db.measures.SQLDeletedRows.Add(float64(rowsAffected))
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion db/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func TestUpdateHistory(t *testing.T) {
p.Assert(t, SQLQueryFailureCounter)(xmetricstest.Value(0.0))
p.Assert(t, SQLDeletedRowsCounter)(xmetricstest.Value(0.0))

err := dbConnection.PruneRecords(tc.time)
err := dbConnection.PruneRecords(tc.time.Unix())
mockObj.AssertExpectations(t)
p.Assert(t, SQLQuerySuccessCounter, typeLabel, deleteType)(xmetricstest.Value(tc.expectedSuccessMetric))
p.Assert(t, SQLQueryFailureCounter, typeLabel, deleteType)(xmetricstest.Value(tc.expectedFailureMetric))
Expand Down
9 changes: 0 additions & 9 deletions db/mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,6 @@ func (f *mockFinder) find(out *[]Record, where ...interface{}) error {
return args.Error(0)
}

type mockCreator struct {
mock.Mock
}

func (c *mockCreator) create(value interface{}) error {
args := c.Called(value)
return args.Error(0)
}

type mockMultiInsert struct {
mock.Mock
}
Expand Down
4 changes: 2 additions & 2 deletions db/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ func CreateRetryInsertService(inserter Inserter, retries int, interval time.Dura
}

type Pruner interface {
PruneRecords(t time.Time) error
PruneRecords(t int64) error
}

type RetryUpdateService struct {
pruner Pruner
config retryConfig
}

func (ru RetryUpdateService) PruneRecords(t time.Time) error {
func (ru RetryUpdateService) PruneRecords(t int64) error {
var err error

retries := ru.config.retries
Expand Down
4 changes: 1 addition & 3 deletions db/retry_mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
package db

import (
"time"

"github.com/stretchr/testify/mock"
)

Expand All @@ -36,7 +34,7 @@ type mockPruner struct {
mock.Mock
}

func (p *mockPruner) PruneRecords(t time.Time) error {
func (p *mockPruner) PruneRecords(t int64) error {
args := p.Called(t)
return args.Error(0)
}
Expand Down
2 changes: 1 addition & 1 deletion db/retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func TestRetryPruneRecords(t *testing.T) {
},
}
p.Assert(t, SQLQueryRetryCounter)(xmetricstest.Value(0.0))
err := retryInsertService.PruneRecords(time.Now())
err := retryInsertService.PruneRecords(time.Now().Unix())
mockObj.AssertExpectations(t)
p.Assert(t, SQLQueryRetryCounter, typeLabel, deleteType)(xmetricstest.Value(tc.expectedRetryMetric))
if tc.expectedErr == nil || err == nil {
Expand Down

0 comments on commit f1d6197

Please sign in to comment.