diff --git a/CHANGELOG.md b/CHANGELOG.md index e842660..80a0d19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 diff --git a/db/db.go b/db/db.go index f35c75e..3321c65 100644 --- a/db/db.go +++ b/db/db.go @@ -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` @@ -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 { diff --git a/db/db_test.go b/db/db_test.go index abe45c4..42f18a8 100644 --- a/db/db_test.go +++ b/db/db_test.go @@ -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)) diff --git a/db/mocks_test.go b/db/mocks_test.go index 4ab5afc..7d4c201 100644 --- a/db/mocks_test.go +++ b/db/mocks_test.go @@ -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 } diff --git a/db/retry.go b/db/retry.go index b30b2d9..ca8ace9 100644 --- a/db/retry.go +++ b/db/retry.go @@ -73,7 +73,7 @@ func CreateRetryInsertService(inserter Inserter, retries int, interval time.Dura } type Pruner interface { - PruneRecords(t time.Time) error + PruneRecords(t int64) error } type RetryUpdateService struct { @@ -81,7 +81,7 @@ type RetryUpdateService struct { config retryConfig } -func (ru RetryUpdateService) PruneRecords(t time.Time) error { +func (ru RetryUpdateService) PruneRecords(t int64) error { var err error retries := ru.config.retries diff --git a/db/retry_mocks_test.go b/db/retry_mocks_test.go index 8eeff79..50ded7c 100644 --- a/db/retry_mocks_test.go +++ b/db/retry_mocks_test.go @@ -18,8 +18,6 @@ package db import ( - "time" - "github.com/stretchr/testify/mock" ) @@ -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) } diff --git a/db/retry_test.go b/db/retry_test.go index 23f8aea..b693614 100644 --- a/db/retry_test.go +++ b/db/retry_test.go @@ -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 {