diff --git a/common/database.go b/common/database.go index b6def16..ca666a1 100644 --- a/common/database.go +++ b/common/database.go @@ -96,10 +96,14 @@ func DummyPopulateDB(test_db *gorm.DB) { checkErr(test_db.Create(&simr_A).Error) checkErr(test_db.Create(&simr_B).Error) - sig_A := Signal{Name: "Signal_A"} - sig_B := Signal{Name: "Signal_B"} - checkErr(test_db.Create(&sig_A).Error) - checkErr(test_db.Create(&sig_B).Error) + outSig_A := Signal{Name: "outSignal_A"} + outSig_B := Signal{Name: "outSignal_B"} + inSig_A := Signal{Name: "inSignal_A"} + inSig_B := Signal{Name: "inSignal_B"} + checkErr(test_db.Create(&outSig_A).Error) + checkErr(test_db.Create(&outSig_B).Error) + checkErr(test_db.Create(&inSig_A).Error) + checkErr(test_db.Create(&inSig_B).Error) smo_A := SimulationModel{Name: "SimModel_A"} smo_B := SimulationModel{Name: "SimModel_B"} @@ -140,37 +144,46 @@ func DummyPopulateDB(test_db *gorm.DB) { // For `belongs to` use the model with id=1 // For `has many` use the models with id=1 and id=2 - checkErr(test_db.Model(&smo_A).Association("BelongsToSimulation").Append(&simn_A).Error) - checkErr(test_db.Model(&smo_A).Association("BelongsToSimulator").Append(&simr_A).Error) - checkErr(test_db.Model(&smo_A).Association("OutputMapping").Append(&sig_A).Error) - checkErr(test_db.Model(&smo_A).Association("OutputMapping").Append(&sig_B).Error) - checkErr(test_db.Model(&smo_A).Association("InputMapping").Append(&sig_B).Error) - checkErr(test_db.Model(&smo_A).Association("InputMapping").Append(&sig_A).Error) - - checkErr(test_db.Model(&simn_A).Association("User").Append(&usr_A).Error) - checkErr(test_db.Model(&simn_A).Association("Models").Append(&smo_A).Error) - checkErr(test_db.Model(&simn_A).Association("Models").Append(&smo_B).Error) - checkErr(test_db.Model(&simn_A).Association("Projects").Append(&proj_A).Error) - checkErr(test_db.Model(&simn_A).Association("Projects").Append(&proj_B).Error) - - checkErr(test_db.Model(&proj_A).Association("Simulation").Append(&simn_A).Error) - checkErr(test_db.Model(&proj_A).Association("User").Append(&usr_A).Error) - checkErr(test_db.Model(&proj_A).Association("Visualizations").Append(&vis_A).Error) - checkErr(test_db.Model(&proj_A).Association("Visualizations").Append(&vis_B).Error) - - checkErr(test_db.Model(&usr_A).Association("Projects").Append(&proj_A).Error) - checkErr(test_db.Model(&usr_A).Association("Projects").Append(&proj_B).Error) - checkErr(test_db.Model(&usr_A).Association("Simulations").Append(&simn_A).Error) - checkErr(test_db.Model(&usr_A).Association("Simulations").Append(&simn_B).Error) - checkErr(test_db.Model(&usr_A).Association("Files").Append(&file_A).Error) - checkErr(test_db.Model(&usr_A).Association("Files").Append(&file_B).Error) - + // Project HM Visualization, Visualization BT Project checkErr(test_db.Model(&vis_A).Association("Project").Append(&proj_A).Error) - checkErr(test_db.Model(&vis_A).Association("User").Append(&usr_A).Error) + checkErr(test_db.Model(&vis_B).Association("Project").Append(&proj_A).Error) + + // User HM Project, Project BT User + checkErr(test_db.Model(&proj_A).Association("User").Append(&usr_A).Error) + checkErr(test_db.Model(&proj_B).Association("User").Append(&usr_A).Error) + + // Simulation HM Project, Project BT Simulation + checkErr(test_db.Model(&proj_A).Association("Simulation").Append(&simn_A).Error) + checkErr(test_db.Model(&proj_B).Association("Simulation").Append(&simn_A).Error) + + // User HM File, File BT User + checkErr(test_db.Model(&file_A).Association("User").Append(&usr_A).Error) + checkErr(test_db.Model(&file_B).Association("User").Append(&usr_A).Error) + + // Simulation HM SimModel, SimModel BT Simulation + checkErr(test_db.Model(&smo_A).Association("BelongsToSimulation").Append(&simn_A).Error) + checkErr(test_db.Model(&smo_B).Association("BelongsToSimulation").Append(&simn_A).Error) + + // User HM Simulation, Simulation BT User + checkErr(test_db.Model(&simn_A).Association("User").Append(&usr_A).Error) + checkErr(test_db.Model(&simn_B).Association("User").Append(&usr_A).Error) + + // Visualization HM Widget checkErr(test_db.Model(&vis_A).Association("Widgets").Append(&widg_A).Error) checkErr(test_db.Model(&vis_A).Association("Widgets").Append(&widg_B).Error) - checkErr(test_db.Model(&file_A).Association("User").Append(&usr_A).Error) + // SimModel HM Signal + checkErr(test_db.Model(&smo_A).Association("InputMapping").Append(&inSig_A).Error) + checkErr(test_db.Model(&smo_A).Association("InputMapping").Append(&inSig_B).Error) + checkErr(test_db.Model(&smo_A).Association("OutputMapping").Append(&outSig_A).Error) + checkErr(test_db.Model(&smo_A).Association("OutputMapping").Append(&outSig_B).Error) + + // Visualization BT User + checkErr(test_db.Model(&vis_A).Association("User").Append(&usr_A).Error) + + // Simulator BT SimModel + checkErr(test_db.Model(&smo_A).Association("BelongsToSimulator").Append(&simr_A).Error) + } // Erase tables and glose the testdb diff --git a/common/datastructs.go b/common/datastructs.go index 74798fd..6d4dd9c 100644 --- a/common/datastructs.go +++ b/common/datastructs.go @@ -1,13 +1,14 @@ package common import ( - "github.com/jinzhu/gorm" + //"github.com/jinzhu/gorm" "github.com/jinzhu/gorm/dialects/postgres" "time" ) type Simulator struct { - gorm.Model + //gorm.Model + ID uint `gorm:"primary_key;auto_increment"` UUID string `gorm:"unique;not null"` Host string `gorm:"default:''"` Modeltype string `gorm:"default:''"` @@ -19,7 +20,8 @@ type Simulator struct { } type File struct { - gorm.Model + //gorm.Model + ID uint `gorm:"primary_key;auto_increment"` Name string `gorm:"not null"` Path string `gorm:"not null"` Type string `gorm:"not null"` @@ -33,7 +35,8 @@ type File struct { } type Project struct { - gorm.Model + //gorm.Model + ID uint `gorm:"primary_key;auto_increment"` Name string `gorm:"not null"` User User `gorm:"not null;association_autoupdate:false"` @@ -42,11 +45,12 @@ type Project struct { Simulation Simulation `gorm:"not null;association_autoupdate:false"` SimulationID uint `gorm:"not null"` - Visualizations []Visualization //`gorm:"association_autoupdate:false"` + Visualizations []Visualization `gorm:"association_autoupdate:false"` } type Simulation struct { - gorm.Model + //gorm.Model + ID uint `gorm:"primary_key;auto_increment"` Name string `gorm:"not null"` Running bool `gorm:"default:false"` StartParameters postgres.Jsonb // TODO default value @@ -54,12 +58,13 @@ type Simulation struct { User User `gorm:"not null;association_autoupdate:false"` UserID uint `gorm:"not null"` - Models []SimulationModel `gorm:"foreignkey:BelongsToSimulationID"` //;association_autoupdate:false"` + Models []SimulationModel `gorm:"foreignkey:BelongsToSimulationID;association_autoupdate:false"` Projects []Project `gorm:"association_autoupdate:false"` } type SimulationModel struct { - gorm.Model + //gorm.Model + ID uint `gorm:"primary_key;auto_increment"` Name string `gorm:"not null"` OutputLength int `gorm:"default:1"` InputLength int `gorm:"default:1"` @@ -72,24 +77,26 @@ type SimulationModel struct { BelongsToSimulatorID uint `gorm:"not null"` // NOTE: order of signals is important - OutputMapping []Signal //`gorm:"association_autoupdate:false"` - InputMapping []Signal //`gorm:"association_autoupdate:false"` + OutputMapping []Signal `gorm:""` + InputMapping []Signal `gorm:""` } type User struct { - gorm.Model + //gorm.Model + ID uint `gorm:"primary_key;auto_increment"` 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"` + Projects []Project `gorm:"association_autoupdate:false"` + Simulations []Simulation `gorm:"association_autoupdate:false"` + Files []File `gorm:"association_autoupdate:false"` } type Visualization struct { - gorm.Model + //gorm.Model + ID uint `gorm:"primary_key;auto_increment"` Name string `gorm:"not null"` Grid int `gorm:"default:15"` @@ -99,11 +106,12 @@ type Visualization struct { User User `gorm:"not null;association_autoupdate:false"` UserID uint `gorm:"not null"` - Widgets []Widget //`gorm:"association_autoupdate:false"` + Widgets []Widget `gorm:""` } type Signal struct { - gorm.Model + //gorm.Model + ID uint `gorm:"primary_key;auto_increment"` Name string `gorm:"not null"` Unit string `gorm:"not null"` SimulationModelID uint @@ -111,7 +119,8 @@ type Signal struct { } type Widget struct { - gorm.Model + //gorm.Model + ID uint `gorm:"primary_key;auto_increment"` Name string `gorm:"not null"` Type string `gorm:"not null"` Width uint `gorm:"not null"`