From f33205e721cda54193f90be1ddd52194433151de Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Wed, 3 Dec 2014 12:51:36 -0900 Subject: [PATCH] =?UTF-8?q?Measurements=20=E2=80=94=20adding=20notes,=20ch?= =?UTF-8?q?anging=20schema?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- datastore/measurements_test.go | 8 ++++---- datastore/migrations/00009_AddMeasurements_up.sql | 6 +++--- models/measurements.go | 3 +-- models/measurements_test.go | 10 +++++----- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/datastore/measurements_test.go b/datastore/measurements_test.go index 1f0c3e4..9ddf703 100644 --- a/datastore/measurements_test.go +++ b/datastore/measurements_test.go @@ -48,8 +48,8 @@ func TestMeasurementsStore_Get_db(t *testing.T) { t.Fatal(err) } - normalizeTime(&want.CreatedAt, &want.UpdatedAt, &want.DeletedAt) - normalizeTime(&measurement.CreatedAt, &measurement.UpdatedAt, &measurement.DeletedAt) + normalizeTime(&want.CreatedAt, &want.UpdatedAt) + normalizeTime(&measurement.CreatedAt, &measurement.UpdatedAt) if !reflect.DeepEqual(measurement, want) { t.Errorf("got measurement %+v, want %+v", measurement, want) @@ -91,8 +91,8 @@ func TestMeasurementsStore_List_db(t *testing.T) { } for i := range want { - normalizeTime(&want[i].CreatedAt, &want[i].UpdatedAt, &want[i].DeletedAt) - normalizeTime(&measurements[i].CreatedAt, &measurements[i].UpdatedAt, &measurements[i].DeletedAt) + normalizeTime(&want[i].CreatedAt, &want[i].UpdatedAt) + normalizeTime(&measurements[i].CreatedAt, &measurements[i].UpdatedAt) } if !reflect.DeepEqual(measurements, want) { t.Errorf("got measurements %+v, want %+v", measurements, want) diff --git a/datastore/migrations/00009_AddMeasurements_up.sql b/datastore/migrations/00009_AddMeasurements_up.sql index 22a3c3c..4bf0be7 100644 --- a/datastore/migrations/00009_AddMeasurements_up.sql +++ b/datastore/migrations/00009_AddMeasurements_up.sql @@ -6,13 +6,13 @@ CREATE TABLE measurements ( strain_id BIGINT, observation_id BIGINT, text_measurement_type_id BIGINT NULL, - measurement_value NUMERIC(6, 4) NULL, - confidence_interval NUMERIC(6, 4) NULL, + measurement_value NUMERIC(8, 3) NULL, + confidence_interval NUMERIC(8, 3) NULL, unit_type_id BIGINT NULL, + notes CHARACTER VARYING(255) NULL, created_at TIMESTAMP WITH TIME ZONE, updated_at TIMESTAMP WITH TIME ZONE, - deleted_at TIMESTAMP WITH TIME ZONE, CONSTRAINT strainsobsmeasurements_pkey PRIMARY KEY (id), FOREIGN KEY (strain_id) REFERENCES strains(id), diff --git a/models/measurements.go b/models/measurements.go index 6381f3e..1a9c277 100644 --- a/models/measurements.go +++ b/models/measurements.go @@ -7,7 +7,6 @@ import ( "strconv" "time" - "github.com/lib/pq" "github.com/thermokarst/bactdb/router" ) @@ -23,9 +22,9 @@ type Measurement struct { MeasurementValue sql.NullFloat64 `db:"measurement_value" json:"measurementValue"` ConfidenceInterval sql.NullFloat64 `db:"confidence_interval" json:"confidenceInterval"` UnitTypeId sql.NullInt64 `db:"unit_type_id" json:"unitTypeId"` + Notes sql.NullString `db:"notes" json:"notes"` CreatedAt time.Time `db:"created_at" json:"createdAt"` UpdatedAt time.Time `db:"updated_at" json:"updatedAt"` - DeletedAt pq.NullTime `db:"deleted_at" json:"deletedAt"` } func NewMeasurement() *Measurement { diff --git a/models/measurements_test.go b/models/measurements_test.go index cc61b88..614cbb9 100644 --- a/models/measurements_test.go +++ b/models/measurements_test.go @@ -41,7 +41,7 @@ func TestMeasurementService_Get(t *testing.T) { t.Fatal("!called") } - normalizeTime(&want.CreatedAt, &want.UpdatedAt, &want.DeletedAt) + normalizeTime(&want.CreatedAt, &want.UpdatedAt) if !reflect.DeepEqual(measurement, want) { t.Errorf("Measurements.Get return %+v, want %+v", measurement, want) @@ -58,7 +58,7 @@ func TestMeasurementService_Create(t *testing.T) { mux.HandleFunc(urlPath(t, router.CreateMeasurement, nil), func(w http.ResponseWriter, r *http.Request) { called = true testMethod(t, r, "POST") - testBody(t, r, `{"id":1,"strainId":1,"observationId":1,"textMeasurementTypeId":{"Int64":0,"Valid":false},"measurementValue":{"Float64":1.23,"Valid":true},"confidenceInterval":{"Float64":0,"Valid":false},"unitTypeId":{"Int64":1,"Valid":true},"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","deletedAt":{"Time":"0001-01-01T00:00:00Z","Valid":false}}`+"\n") + testBody(t, r, `{"id":1,"strainId":1,"observationId":1,"textMeasurementTypeId":{"Int64":0,"Valid":false},"measurementValue":{"Float64":1.23,"Valid":true},"confidenceInterval":{"Float64":0,"Valid":false},"unitTypeId":{"Int64":1,"Valid":true},"notes":{"String":"","Valid":false},"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z"}`+"\n") w.WriteHeader(http.StatusCreated) writeJSON(w, want) @@ -78,7 +78,7 @@ func TestMeasurementService_Create(t *testing.T) { t.Fatal("!called") } - normalizeTime(&want.CreatedAt, &want.UpdatedAt, &want.DeletedAt) + normalizeTime(&want.CreatedAt, &want.UpdatedAt) if !reflect.DeepEqual(measurement, want) { t.Errorf("Measurements.Create returned %+v, want %+v", measurement, want) } @@ -109,7 +109,7 @@ func TestMeasurementService_List(t *testing.T) { } for _, u := range want { - normalizeTime(&u.CreatedAt, &u.UpdatedAt, &u.DeletedAt) + normalizeTime(&u.CreatedAt, &u.UpdatedAt) } if !reflect.DeepEqual(measurements, want) { @@ -127,7 +127,7 @@ func TestMeasurementService_Update(t *testing.T) { mux.HandleFunc(urlPath(t, router.UpdateMeasurement, map[string]string{"Id": "1"}), func(w http.ResponseWriter, r *http.Request) { called = true testMethod(t, r, "PUT") - testBody(t, r, `{"id":1,"strainId":1,"observationId":1,"textMeasurementTypeId":{"Int64":0,"Valid":false},"measurementValue":{"Float64":4.56,"Valid":true},"confidenceInterval":{"Float64":0,"Valid":false},"unitTypeId":{"Int64":1,"Valid":true},"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","deletedAt":{"Time":"0001-01-01T00:00:00Z","Valid":false}}`+"\n") + testBody(t, r, `{"id":1,"strainId":1,"observationId":1,"textMeasurementTypeId":{"Int64":0,"Valid":false},"measurementValue":{"Float64":4.56,"Valid":true},"confidenceInterval":{"Float64":0,"Valid":false},"unitTypeId":{"Int64":1,"Valid":true},"notes":{"String":"","Valid":false},"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z"}`+"\n") w.WriteHeader(http.StatusOK) writeJSON(w, want) })