first handler writing to database
This commit is contained in:
55
src/udi/database/migrate_database.go
Normal file
55
src/udi/database/migrate_database.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"log"
|
||||
//"time"
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func Migrate() {
|
||||
dsn := ""
|
||||
db, err := gorm.Open(postgres.Open(dsn))
|
||||
if err != nil {
|
||||
log.Fatalf("Unable to open database connection: %s", err)
|
||||
}
|
||||
|
||||
db.AutoMigrate(&Application{})
|
||||
log.Println("Application created")
|
||||
|
||||
db.AutoMigrate(&DeviceType{})
|
||||
log.Println("DeviceType created")
|
||||
|
||||
db.AutoMigrate(&Device{})
|
||||
log.Println("Device created")
|
||||
|
||||
db.AutoMigrate(&Measurement{})
|
||||
log.Println("Measurement created")
|
||||
|
||||
log.Println("Remember to call create_hypertable on measurements, sowhat I can't do that for you.")
|
||||
|
||||
/*
|
||||
m := Measurement {
|
||||
Time: time.Now(),
|
||||
Application: "app",
|
||||
Attributes: nil,
|
||||
Values: []SensorType {
|
||||
{ Variable: "Temperature", Unit: "Degree Celsius", Value: 1.0 },
|
||||
{ Variable: "Temperature", Unit: "Degree Celsius", Value: 3.0 },
|
||||
},
|
||||
}
|
||||
db.Create(&m)
|
||||
|
||||
m = Measurement {
|
||||
Time: time.Now(),
|
||||
Application: "app",
|
||||
Attributes: nil,
|
||||
Values: []SensorType {
|
||||
{ Variable: "Temperature", Unit: "Degree Celsius", Value: 10.0 },
|
||||
{ Variable: "Temperature", Unit: "Degree Celsius", Value: 30.0 },
|
||||
},
|
||||
}
|
||||
db.Create(&m)
|
||||
*/
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user