func SetupDatabase(drop bool) {
	dbInfo := fmt.Sprintf("host=%s port=%s user=%s dbname=%s password=%s sslmode=disable",
		os.Getenv("POSTGRES_HOST"), os.Getenv("POSTGRES_PORT"), os.Getenv("POSTGRES_USER"),
		os.Getenv("POSTGRES_DB"), os.Getenv("POSTGRES_PASSWORD"))
	var err error
	DB, err = gorm.Open("postgres", dbInfo)
	if err != nil {
		fmt.Println(err)
		fmt.Println(dbInfo)
		panic("[!] failed to connect to db")
	} else {
		fmt.Println("[✓] successfully connected to db")
	}
	if drop {
		DB.DropTableIfExists(&RoomModel{}, &Sensor{}, &Data{}, &Location{})
		fmt.Println("[✓] all data successfully dropped")
	}
	DB.AutoMigrate(&RoomModel{}, &Sensor{}, &Data{}, &Location{})
	fmt.Println("[✓] schemes migrated")
}
SetupDatabase initializes the database w/ the orm mapping and postgres as the dialect;
drop defines whether or not the currently active scheme should be dropped
package model
import (
	"bufio"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"math"
	"os"
	"strconv"
	"sync"
	"time"
	"github.com/gocarina/gocsv"
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/postgres"
	_ "github.com/jinzhu/gorm/dialects/sqlite"
)
type Location struct {
	Address   string  `json:"address"`
	Latitude  float64 `json:"latitude"`
	Longitude float64 `json:"longitude"`
}
type RoomModel struct {
	ID       uint     `json:"id"`
	Sensors  []Sensor `json:"sensors"`
	Name     string   `json:"name"`
	Url      string   `json:"url"`
	ImageUrl string   `json:"image_url"`
	Type     string   `json:"type"`
	Location Location `json:"location" gorm:"embedded"`
	Floors   int      `json:"floors"`
}
type Sensor struct {
	ID              uint     `json:"id"`
	RoomModelID     uint     `json:"room_model_id"`
	LatestData      Data     `json:"latest_data" gorm:"-"`
	Data            []Data   `json:"-"`
	ImportName      string   `json:"import_name,omitempty" gorm:"-"`
	MeshID          *int64   `json:"mesh_id"`
	Name            string   `json:"name"`
	Description     string   `json:"description"`
	MeasurementUnit string   `json:"measurement_unit"`
	Range           string   `json:"range"`
	UpperBound      *float64 `json:"upper_bound"`
	LowerBound      *float64 `json:"lower_bound"`
	GradientBound   *float64 `json:"gradient_bound"`
}
type Data struct {
	ID       uint    `json:"id" csv:"-"`
	SensorID uint    `json:"sensor_id" csv:"-"`
	Value    float64 `json:"value" csv:"value"`
	Gradient float64 `json:"gradient" csv:"-"`
	Date     Date    `json:"date" csv:"date" gorm:"embedded"`
}
type Date struct {
	time.Time `gorm:"column:date"`
}
func (date *Date) UnmarshalCSV(csv string) (err error) {
	t, err := strconv.ParseInt(csv, 10, 64)
	date.Time = time.Unix(t, 0).UTC()
	return err
}
const Layout = "2006-01-02 15:04:05"
var DB *gorm.DB