Added devices and companies models
This commit is contained in:
@@ -2,7 +2,9 @@ package shared
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"novatech/config"
|
||||
"novatech/models"
|
||||
|
||||
"github.com/jinzhu/gorm"
|
||||
_ "github.com/jinzhu/gorm/dialects/postgres"
|
||||
@@ -13,23 +15,28 @@ var db *gorm.DB
|
||||
var err error
|
||||
|
||||
|
||||
func Init() {
|
||||
func Init() error{
|
||||
host := config.AppConfig.Database.HostName
|
||||
user := config.AppConfig.Database.UserName
|
||||
port := config.AppConfig.Database.Port
|
||||
// port := config.AppConfig.Database.Port
|
||||
dbName := config.AppConfig.Database.DatabaseName
|
||||
password := config.AppConfig.Database.Password
|
||||
|
||||
dbString:= fmt.Sprintf("postgres, host=%s:%s user=%s dbname=%s sslmode=disable password=%s",host,port,user,dbName,password)
|
||||
|
||||
//PostgreSQL
|
||||
db, err = gorm.Open(dbString)
|
||||
dbString:= fmt.Sprintf("host=%s user=%s dbname=%s sslmode=disable password=%s",host,user,dbName,password)
|
||||
// db, err = gorm.Open("postgres", "host=localhost user=postgres dbname=postgres sslmode=disable password=root")
|
||||
var err error
|
||||
// //PostgreSQL
|
||||
db, err = gorm.Open("postgres",dbString)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Println("Error initializing the database: ", err)
|
||||
return err
|
||||
}
|
||||
//TODO AUTOMIGRATE models once we have them
|
||||
//db.AutoMigrate(&models.Person{})
|
||||
db.AutoMigrate(&models.User{}, &models.Company{}, &models.Device{})
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user