add gorm.Model in all DB models

This commit is contained in:
Sonja Happ 2019-07-25 12:41:31 +02:00
parent 4cf4049b40
commit c57b083eed

View file

@ -1,11 +1,13 @@
package common package common
import "github.com/jinzhu/gorm/dialects/postgres" import (
"github.com/jinzhu/gorm"
"github.com/jinzhu/gorm/dialects/postgres"
)
// User data model // User data model
type User struct { type User struct {
// ID of user gorm.Model
ID uint `gorm:"primary_key;auto_increment"`
// Username of user // Username of user
Username string `gorm:"unique;not null"` Username string `gorm:"unique;not null"`
// Password of user // Password of user
@ -20,8 +22,7 @@ type User struct {
// Scenario data model // Scenario data model
type Scenario struct { type Scenario struct {
// ID of scenario gorm.Model
ID uint `gorm:"primary_key;auto_increment"`
// Name of scenario // Name of scenario
Name string `gorm:"not null"` Name string `gorm:"not null"`
// Running state of scenario // Running state of scenario
@ -38,8 +39,7 @@ type Scenario struct {
// SimulationModel data model // SimulationModel data model
type SimulationModel struct { type SimulationModel struct {
// ID of simulation model gorm.Model
ID uint `gorm:"primary_key;auto_increment"`
// Name of simulation model // Name of simulation model
Name string `gorm:"not null"` Name string `gorm:"not null"`
// Number of output signals // Number of output signals
@ -62,8 +62,7 @@ type SimulationModel struct {
// Signal data model // Signal data model
type Signal struct { type Signal struct {
// ID of simulation model gorm.Model
ID uint `gorm:"primary_key;auto_increment"`
// Name of Signal // Name of Signal
Name string Name string
// Unit of Signal // Unit of Signal
@ -78,8 +77,7 @@ type Signal struct {
// Simulator data model // Simulator data model
type Simulator struct { type Simulator struct {
// ID of the simulator gorm.Model
ID uint `gorm:"primary_key;auto_increment",json:"id"`
// UUID of the simulator // UUID of the simulator
UUID string `gorm:"not null",json:"uuid"` UUID string `gorm:"not null",json:"uuid"`
// Host if the simulator // Host if the simulator
@ -102,8 +100,7 @@ type Simulator struct {
// Dashboard data model // Dashboard data model
type Dashboard struct { type Dashboard struct {
// ID of dashboard gorm.Model
ID uint `gorm:"primary_key;auto_increment"`
// Name of dashboard // Name of dashboard
Name string `gorm:"not null"` Name string `gorm:"not null"`
// Grid of dashboard // Grid of dashboard
@ -116,8 +113,7 @@ type Dashboard struct {
// Widget data model // Widget data model
type Widget struct { type Widget struct {
// ID of widget gorm.Model
ID uint `gorm:"primary_key;auto_increment"`
// Name of widget // Name of widget
Name string `gorm:"not null"` Name string `gorm:"not null"`
// Type of widget // Type of widget
@ -148,14 +144,13 @@ type Widget struct {
// File data model // File data model
type File struct { type File struct {
// ID of file gorm.Model
ID uint `gorm:"primary_key;auto_increment"`
// Name of file // Name of file
Name string `gorm:"not null"` Name string `gorm:"not null"`
// Type of file (MIME type) // Type of file (MIME type)
Type string `gorm:"not null"` Type string
// Size of file (in byte) // Size of file (in byte)
Size uint `gorm:"not null"` Size uint
// Height of image (only needed in case of image) // Height of image (only needed in case of image)
ImageHeight uint ImageHeight uint
// Width of image (only needed in case of image) // Width of image (only needed in case of image)
@ -166,7 +161,7 @@ type File struct {
SimulationModelID uint SimulationModelID uint
// ID of widget to which file belongs // ID of widget to which file belongs
WidgetID uint WidgetID uint
// TODO Add file itself here?? // File itself
FileData []byte `gorm:"column:FileData"` FileData []byte `gorm:"column:FileData"`
} }