Associations autoupdate OFF. Formated model structs.

This commit is contained in:
smavros 2019-04-14 20:50:26 +02:00
parent 3682ae265a
commit 9df906bc15
2 changed files with 54 additions and 40 deletions

View file

@ -138,13 +138,13 @@ func DummyPopulateDB(test_db *gorm.DB) {
test_db.Model(&simn_A).Association("Projects").Append(&proj_B) test_db.Model(&simn_A).Association("Projects").Append(&proj_B)
test_db.Model(&proj_A).Association("Simulation").Append(&simn_A) test_db.Model(&proj_A).Association("Simulation").Append(&simn_A)
test_db.Debug().Model(&proj_A).Association("User").Append(&usr_A) test_db.Model(&proj_A).Association("User").Append(&usr_A)
test_db.Model(&proj_A).Association("Visualizations").Append(&vis_A) test_db.Model(&proj_A).Association("Visualizations").Append(&vis_A)
test_db.Model(&proj_A).Association("Visualizations").Append(&vis_B) test_db.Model(&proj_A).Association("Visualizations").Append(&vis_B)
test_db.Model(&usr_A).Association("Projects").Append(&proj_A) test_db.Model(&usr_A).Association("Projects").Append(&proj_A)
test_db.Model(&usr_A).Association("Projects").Append(&proj_B) test_db.Model(&usr_A).Association("Projects").Append(&proj_B)
test_db.Debug().Model(&usr_A).Association("Simulations").Append(&simn_A) test_db.Model(&usr_A).Association("Simulations").Append(&simn_A)
test_db.Model(&usr_A).Association("Simulations").Append(&simn_B) test_db.Model(&usr_A).Association("Simulations").Append(&simn_B)
test_db.Model(&usr_A).Association("Files").Append(&file_A) test_db.Model(&usr_A).Association("Files").Append(&file_A)
test_db.Model(&usr_A).Association("Files").Append(&file_B) test_db.Model(&usr_A).Association("Files").Append(&file_B)

View file

@ -26,66 +26,80 @@ type File struct {
Size uint `gorm:"not null"` Size uint `gorm:"not null"`
ImageHeight uint // only required in case file is an image ImageHeight uint // only required in case file is an image
ImageWidth uint // only required in case file is an image ImageWidth uint // only required in case file is an image
User User `gorm:"not null"`
UserID uint `gorm:"not null"`
Date time.Time Date time.Time
User User `gorm:"not null;association_autoupdate:false"`
UserID uint `gorm:"not null"`
} }
type Project struct { type Project struct {
gorm.Model gorm.Model
Name string `gorm:"not null"` Name string `gorm:"not null"`
User User `gorm:"not null"`
UserID uint `gorm:"not null"` User User `gorm:"not null;association_autoupdate:false"`
Simulation Simulation `gorm:"not null"` UserID uint `gorm:"not null"`
SimulationID uint `gorm:"not null"`
Visualizations []Visualization Simulation Simulation `gorm:"not null;association_autoupdate:false"`
SimulationID uint `gorm:"not null"`
Visualizations []Visualization `gorm:"association_autoupdate:false"`
} }
type Simulation struct { type Simulation struct {
gorm.Model gorm.Model
Name string `gorm:"not null"` Name string `gorm:"not null"`
Running bool `gorm:"default:false"` Running bool `gorm:"default:false"`
User User `gorm:"not null"` StartParameters postgres.Jsonb // TODO default value
UserID uint `gorm:"not null"`
StartParameters postgres.Jsonb // TODO default value User User `gorm:"not null;association_autoupdate:false"`
Models []SimulationModel `gorm:"foreignkey:BelongsToSimulationID"` UserID uint `gorm:"not null"`
Projects []Project
Models []SimulationModel `gorm:"foreignkey:BelongsToSimulationID;association_autoupdate:false"`
Projects []Project `gorm:"association_autoupdate:false"`
} }
type SimulationModel struct { type SimulationModel struct {
gorm.Model gorm.Model
Name string `gorm:"not null"` Name string `gorm:"not null"`
OutputLength int `gorm:"default:1"` OutputLength int `gorm:"default:1"`
InputLength int `gorm:"default:1"` InputLength int `gorm:"default:1"`
OutputMapping []Signal // order of signals is important StartParameters postgres.Jsonb // TODO: default value?
InputMapping []Signal // order of signals is important
StartParameters postgres.Jsonb // TODO: default value? BelongsToSimulation Simulation `gorm:"not null;association_autoupdate:false"`
BelongsToSimulation Simulation `gorm:"not null"` BelongsToSimulationID uint `gorm:"not null"`
BelongsToSimulationID uint `gorm:"not null"`
BelongsToSimulator Simulator `gorm:"not null"` BelongsToSimulator Simulator `gorm:"not null;association_autoupdate:false"`
BelongsToSimulatorID uint `gorm:"not null"` BelongsToSimulatorID uint `gorm:"not null"`
// NOTE: order of signals is important
OutputMapping []Signal `gorm:"association_autoupdate:false"`
InputMapping []Signal `gorm:"association_autoupdate:false"`
} }
type User struct { type User struct {
gorm.Model gorm.Model
Username string `gorm:"unique;not null"` Username string `gorm:"unique;not null"`
Password string `gorm:"not null"` Password string `gorm:"not null"`
Mail string `gorm:"default:''"` Mail string `gorm:"default:''"`
Role string `gorm:"default:'user'"` Role string `gorm:"default:'user'"`
Projects []Project
Simulations []Simulation Projects []Project `gorm:"association_autoupdate:false"`
Files []File Simulations []Simulation `gorm:"association_autoupdate:false"`
Files []File `gorm:"association_autoupdate:false"`
} }
type Visualization struct { type Visualization struct {
gorm.Model gorm.Model
Name string `gorm:"not null"` Name string `gorm:"not null"`
Project Project `gorm:"not null"` Grid int `gorm:"default:15"`
Project Project `gorm:"not null;association_autoupdate:false"`
ProjectID uint `gorm:"not null"` ProjectID uint `gorm:"not null"`
Grid int `gorm:"default:15"`
User User `gorm:"not null"` User User `gorm:"not null;association_autoupdate:false"`
UserID uint `gorm:"not null"` UserID uint `gorm:"not null"`
Widgets []Widget
Widgets []Widget `gorm:"association_autoupdate:false"`
} }
type Signal struct { type Signal struct {