From 58344b82a5d09ef5e45ba7a5adc8803227e3d77c Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Thu, 30 Oct 2014 16:24:15 -0800 Subject: [PATCH] Importing data, realized need to handle NULLs. --- datastore/migrations/00004_AddStrain_up.sql | 6 ++--- models/genera.go | 11 ++++---- models/species.go | 13 +++++----- models/strains.go | 28 +++++++++++++-------- 4 files changed, 33 insertions(+), 25 deletions(-) diff --git a/datastore/migrations/00004_AddStrain_up.sql b/datastore/migrations/00004_AddStrain_up.sql index 855f3a9..bd38800 100644 --- a/datastore/migrations/00004_AddStrain_up.sql +++ b/datastore/migrations/00004_AddStrain_up.sql @@ -3,9 +3,9 @@ CREATE TABLE strains ( id BIGSERIAL NOT NULL, - species_id BIGINT, - strain_name CHARACTER VARYING(100), - strain_type CHARACTER VARYING(100), + species_id BIGINT NOT NULL, + strain_name CHARACTER VARYING(100) NOT NULL, + strain_type CHARACTER VARYING(100) NOT NULL, etymology CHARACTER VARYING(500), accession_banks CHARACTER VARYING(100), genbank_embl_ddb CHARACTER VARYING(100), diff --git a/models/genera.go b/models/genera.go index eda59c0..715ce46 100644 --- a/models/genera.go +++ b/models/genera.go @@ -6,16 +6,17 @@ import ( "strconv" "time" + "github.com/lib/pq" "github.com/thermokarst/bactdb/router" ) // A Genus is a high-level classifier in bactdb. type Genus struct { - Id int64 `json:"id,omitempty"` - GenusName string `db:"genus_name" json:"genus_name"` - CreatedAt time.Time `db:"created_at" json:"created_at"` - UpdatedAt time.Time `db:"updated_at" json:"updated_at"` - DeletedAt time.Time `db:"deleted_at" json:"deleted_at"` + Id int64 `json:"id,omitempty"` + GenusName string `db:"genus_name" json:"genus_name"` + CreatedAt time.Time `db:"created_at" json:"created_at"` + UpdatedAt time.Time `db:"updated_at" json:"updated_at"` + DeletedAt pq.NullTime `db:"deleted_at" json:"deleted_at"` } func NewGenus() *Genus { diff --git a/models/species.go b/models/species.go index 7b76ccf..fa8e650 100644 --- a/models/species.go +++ b/models/species.go @@ -6,17 +6,18 @@ import ( "strconv" "time" + "github.com/lib/pq" "github.com/thermokarst/bactdb/router" ) // A Species is a high-level classifier in bactdb. type Species struct { - Id int64 `json:"id,omitempty"` - GenusId int64 `db:"genus_id" json:"genus_id"` - SpeciesName string `db:"species_name" json:"species_name"` - CreatedAt time.Time `db:"created_at" json:"created_at"` - UpdatedAt time.Time `db:"updated_at" json:"updated_at"` - DeletedAt time.Time `db:"deleted_at" json:"deleted_at"` + Id int64 `json:"id,omitempty"` + GenusId int64 `db:"genus_id" json:"genus_id"` + SpeciesName string `db:"species_name" json:"species_name"` + CreatedAt time.Time `db:"created_at" json:"created_at"` + UpdatedAt time.Time `db:"updated_at" json:"updated_at"` + DeletedAt pq.NullTime `db:"deleted_at" json:"deleted_at"` } func NewSpecies() *Species { diff --git a/models/strains.go b/models/strains.go index e32f98d..a890a31 100644 --- a/models/strains.go +++ b/models/strains.go @@ -6,25 +6,31 @@ import ( "strconv" "time" + "github.com/lib/pq" "github.com/thermokarst/bactdb/router" ) // A Strain is a subclass of species type Strain struct { - Id int64 `json:"id,omitempty"` - SpeciesId int64 `db:"species_id" json:"species_id"` - StrainName string `db:"strain_name" json:"strain_name"` - StrainType string `db:"strain_type" json:"strain_type"` - Etymology string `db:"etymology" json:"etymology"` - AccessionBanks string `db:"accession_banks" json:"accession_banks"` - GenbankEmblDdb string `db:"genbank_embl_ddb" json:"genbank_embl_ddb"` - CreatedAt time.Time `db:"created_at" json:"created_at"` - UpdatedAt time.Time `db:"updated_at" json:"updated_at"` - DeletedAt time.Time `db:"deleted_at" json:"deleted_at"` + Id int64 `json:"id,omitempty"` + SpeciesId int64 `db:"species_id" json:"species_id"` + StrainName string `db:"strain_name" json:"strain_name"` + StrainType string `db:"strain_type" json:"strain_type"` + Etymology string `db:"etymology" json:"etymology"` + AccessionBanks string `db:"accession_banks" json:"accession_banks"` + GenbankEmblDdb string `db:"genbank_embl_ddb" json:"genbank_embl_ddb"` + CreatedAt time.Time `db:"created_at" json:"created_at"` + UpdatedAt time.Time `db:"updated_at" json:"updated_at"` + DeletedAt pq.NullTime `db:"deleted_at" json:"deleted_at"` } func NewStrain() *Strain { - return &Strain{StrainName: "Test Strain", StrainType: "Test Type", Etymology: "Test Etymology", AccessionBanks: "Test Accession", GenbankEmblDdb: "Test Genbank"} + return &Strain{ + StrainName: "Test Strain", + StrainType: "Test Type", + Etymology: "Test Etymology", + AccessionBanks: "Test Accession", + GenbankEmblDdb: "Test Genbank"} } // StrainService interacts with the strain-related endpoints in bactdb's API