diff --git a/common/database.go b/common/database.go index 6cdfb98..3c9fae3 100644 --- a/common/database.go +++ b/common/database.go @@ -138,13 +138,13 @@ func DummyPopulateDB(test_db *gorm.DB) { test_db.Model(&simn_A).Association("Projects").Append(&proj_B) 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_B) test_db.Model(&usr_A).Association("Projects").Append(&proj_A) 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("Files").Append(&file_A) test_db.Model(&usr_A).Association("Files").Append(&file_B) diff --git a/common/datastructs.go b/common/datastructs.go index e9f4b5e..3a49ac2 100644 --- a/common/datastructs.go +++ b/common/datastructs.go @@ -26,66 +26,80 @@ type File struct { Size uint `gorm:"not null"` ImageHeight 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 + + User User `gorm:"not null;association_autoupdate:false"` + UserID uint `gorm:"not null"` } type Project struct { gorm.Model - Name string `gorm:"not null"` - User User `gorm:"not null"` - UserID uint `gorm:"not null"` - Simulation Simulation `gorm:"not null"` - SimulationID uint `gorm:"not null"` - Visualizations []Visualization + Name string `gorm:"not null"` + + User User `gorm:"not null;association_autoupdate:false"` + UserID uint `gorm:"not null"` + + Simulation Simulation `gorm:"not null;association_autoupdate:false"` + SimulationID uint `gorm:"not null"` + + Visualizations []Visualization `gorm:"association_autoupdate:false"` } type Simulation struct { gorm.Model - Name string `gorm:"not null"` - Running bool `gorm:"default:false"` - User User `gorm:"not null"` - UserID uint `gorm:"not null"` - StartParameters postgres.Jsonb // TODO default value - Models []SimulationModel `gorm:"foreignkey:BelongsToSimulationID"` - Projects []Project + Name string `gorm:"not null"` + Running bool `gorm:"default:false"` + StartParameters postgres.Jsonb // TODO default value + + User User `gorm:"not null;association_autoupdate:false"` + UserID uint `gorm:"not null"` + + Models []SimulationModel `gorm:"foreignkey:BelongsToSimulationID;association_autoupdate:false"` + Projects []Project `gorm:"association_autoupdate:false"` } type SimulationModel struct { gorm.Model - Name string `gorm:"not null"` - OutputLength int `gorm:"default:1"` - InputLength int `gorm:"default:1"` - OutputMapping []Signal // order of signals is important - InputMapping []Signal // order of signals is important - StartParameters postgres.Jsonb // TODO: default value? - BelongsToSimulation Simulation `gorm:"not null"` - BelongsToSimulationID uint `gorm:"not null"` - BelongsToSimulator Simulator `gorm:"not null"` - BelongsToSimulatorID uint `gorm:"not null"` + Name string `gorm:"not null"` + OutputLength int `gorm:"default:1"` + InputLength int `gorm:"default:1"` + StartParameters postgres.Jsonb // TODO: default value? + + BelongsToSimulation Simulation `gorm:"not null;association_autoupdate:false"` + BelongsToSimulationID uint `gorm:"not null"` + + BelongsToSimulator Simulator `gorm:"not null;association_autoupdate:false"` + 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 { gorm.Model - Username string `gorm:"unique;not null"` - Password string `gorm:"not null"` - Mail string `gorm:"default:''"` - Role string `gorm:"default:'user'"` - Projects []Project - Simulations []Simulation - Files []File + Username string `gorm:"unique;not null"` + Password string `gorm:"not null"` + Mail string `gorm:"default:''"` + Role string `gorm:"default:'user'"` + + Projects []Project `gorm:"association_autoupdate:false"` + Simulations []Simulation `gorm:"association_autoupdate:false"` + Files []File `gorm:"association_autoupdate:false"` } type Visualization struct { gorm.Model - Name string `gorm:"not null"` - Project Project `gorm:"not null"` + Name string `gorm:"not null"` + Grid int `gorm:"default:15"` + + Project Project `gorm:"not null;association_autoupdate:false"` ProjectID uint `gorm:"not null"` - Grid int `gorm:"default:15"` - User User `gorm:"not null"` - UserID uint `gorm:"not null"` - Widgets []Widget + + User User `gorm:"not null;association_autoupdate:false"` + UserID uint `gorm:"not null"` + + Widgets []Widget `gorm:"association_autoupdate:false"` } type Signal struct {