started datamodelling papas excel tables
This commit is contained in:
@@ -27,18 +27,26 @@ func initLogging() {
|
|||||||
gin.DefaultWriter = f // capture Gin logs too
|
gin.DefaultWriter = f // capture Gin logs too
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func dbMigration() {
|
||||||
|
database.DB.AutoMigrate(
|
||||||
|
&models.AssetType{},
|
||||||
|
&models.Asset{},
|
||||||
|
&models.LogType{},
|
||||||
|
&models.Log{},
|
||||||
|
)
|
||||||
|
|
||||||
|
db.Create(&models.AssetType{Name: "machine"})
|
||||||
|
db.Create(&models.AssetType{Name: "field"})
|
||||||
|
db.Create(&models.AssetType{Name: "animal"})
|
||||||
|
db.Create(&models.AssetType{Name: "substance"})
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
initLogging()
|
initLogging()
|
||||||
|
|
||||||
log.Println("Starting API server...")
|
log.Println("Starting API server...")
|
||||||
|
|
||||||
database.Connect()
|
database.Connect()
|
||||||
database.DB.AutoMigrate(
|
|
||||||
&models.AssetType{},
|
|
||||||
&models.Asset{},
|
|
||||||
&models.LogType{},
|
|
||||||
&models.Log{},
|
|
||||||
)
|
|
||||||
|
|
||||||
r := gin.Default()
|
r := gin.Default()
|
||||||
routes.SetupRoutes(r)
|
routes.SetupRoutes(r)
|
||||||
|
|||||||
BIN
wagfarm-api/models/Schlagkartei52.xlsm
Executable file
BIN
wagfarm-api/models/Schlagkartei52.xlsm
Executable file
Binary file not shown.
66
wagfarm-api/models/asset_models.go
Normal file
66
wagfarm-api/models/asset_models.go
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
type _Asset struct {
|
||||||
|
ID uint `gorm:"primaryKey`
|
||||||
|
Name string `gorm:"not null"`
|
||||||
|
Notes string
|
||||||
|
}
|
||||||
|
|
||||||
|
type Land struct {
|
||||||
|
_Asset
|
||||||
|
FID string `gorm:"not null"`
|
||||||
|
IsWaterProtectionArea bool `gorm:"not null"`
|
||||||
|
IsRedArea bool `gorm:"not null"`
|
||||||
|
Betriebsnummer?
|
||||||
|
Area float64 `gorm:"not null"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Plant struct {
|
||||||
|
_Asset
|
||||||
|
LandId uint `gorm:"not null"`
|
||||||
|
Land Land `gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
||||||
|
CropID uint `gorm:"not null"`
|
||||||
|
Crop Taxonomy `gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
||||||
|
CoverCropID uint `gorm:"not null"`
|
||||||
|
CoverCrop Taxonomy `gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
||||||
|
Year uint `gorm:"not null"`
|
||||||
|
AreaPercentage float64 `gorm:"not null"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Machine struct {
|
||||||
|
_Asset
|
||||||
|
UnitID uint `gorm:"not null"`
|
||||||
|
Unit Taxonomy `gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
||||||
|
Cost float64 `gorm:"not null; type:decimal(10,2);"` // in euro
|
||||||
|
}
|
||||||
|
|
||||||
|
type SeedType struct {
|
||||||
|
ID uint `gorm:"primaryKey`
|
||||||
|
Name string `gorm:"not null"`
|
||||||
|
CropID uint `gorm:"not null"`
|
||||||
|
Crop Taxonomy `gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Seed struct {
|
||||||
|
_Asset
|
||||||
|
BuyDate Datetime.Time `gorm:"type:date;default:CURRENT_DATE"`
|
||||||
|
UnitID uint `gorm:"not null"`
|
||||||
|
Unit Taxonomy `gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
||||||
|
Cost float64 `gorm:"not null; type:decimal(10,2);"` // in euro/unit
|
||||||
|
SourcedFromID uint `gorm:"not null"`
|
||||||
|
SourcedFrom Taxonomy `gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
||||||
|
SeedTypeID uint `gorm:"not null"`
|
||||||
|
SeedType SeedType `gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Fertilizer struct {
|
||||||
|
_Asset
|
||||||
|
BuyDate Datetime.Time `gorm:"type:date;default:CURRENT_DATE"`
|
||||||
|
UnitID uint `gorm:"not null"`
|
||||||
|
Unit Taxonomy `gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
||||||
|
Cost float64 `gorm:"not null; type:decimal(10,2);"` // in euro/unit
|
||||||
|
SourcedFromID uint `gorm:"not null"`
|
||||||
|
SourcedFrom Taxonomy `gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
||||||
|
FertilizerTypeID uint `gorm:"not null"`
|
||||||
|
FertilizerType Taxonomy `gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
||||||
|
}
|
||||||
41
wagfarm-api/models/log_models.go
Normal file
41
wagfarm-api/models/log_models.go
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
type Log struct {
|
||||||
|
ID uint `gorm:"primaryKey"`
|
||||||
|
Name string `gorm:"not null"`
|
||||||
|
Notes string
|
||||||
|
LogType string `gorm:"not null"`
|
||||||
|
Date Datetime.Time `gorm:"type:date;default:CURRENT_DATE"not null`
|
||||||
|
Duration float64 `gorm:"not null"` // in hours
|
||||||
|
VisibiltyID uint `gorm:"not null"`
|
||||||
|
Visibility Taxonomy `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;not null"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type _LogMetadata struct {
|
||||||
|
ID uint `gorm:"primaryKey"`
|
||||||
|
LogID uint `gorm:"not null"`
|
||||||
|
Log Log `gorm:"foreignKey:LogID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;not null"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type _FieldWorkLog struct {
|
||||||
|
_LogMetadata
|
||||||
|
WorkedAreaPercentage float64 `gorm:"not null"`
|
||||||
|
MachineID uint `gorm:"not null"`
|
||||||
|
Machine Machine `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;not null"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SeedingLog struct {
|
||||||
|
_FieldWorkLog
|
||||||
|
SeedID uint `gorm:"not null"`
|
||||||
|
Seed Seed `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;not null"`
|
||||||
|
TechniqueID uint `gorm:"not null"`
|
||||||
|
Technique Taxonomy `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;not null"`
|
||||||
|
Amount float64 `gorm:"not null"` // in units/ha
|
||||||
|
ConditionsID uint `gorm:"not null"`
|
||||||
|
Conditions Taxonomy `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;not null"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type FertilizingLog struct {
|
||||||
|
_FieldWorkLog
|
||||||
|
FertilizerID uint `gorm:"not null"`
|
||||||
|
Fertilizer Fertilizer `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;not null"`
|
||||||
|
Amount float64 `gorm:"not null"` // in units/ha
|
||||||
|
}
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
package models
|
|
||||||
|
|
||||||
type AssetType struct {
|
|
||||||
ID uint `gorm:"primaryKey" json:"id"`
|
|
||||||
Name string `gorm:"unique;not null" json:"name"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Asset struct {
|
|
||||||
ID uint `gorm:"primaryKey" json:"id"`
|
|
||||||
Name string `gorm:"not null" json:"name"`
|
|
||||||
AssetTypeID uint `json:"asset_type_id"`
|
|
||||||
AssetType AssetType `gorm:"foreignKey:AssetTypeID" json:"-"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type LogType struct {
|
|
||||||
ID uint `gorm:"primaryKey" json:"id"`
|
|
||||||
Name string `gorm:"unique;not null" json:"name"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Log struct {
|
|
||||||
ID uint `gorm:"primaryKey" json:"id"`
|
|
||||||
Name string `gorm:"not null" json:"name"`
|
|
||||||
LogTypeID uint `json:"log_type_id"`
|
|
||||||
LogType LogType `gorm:"foreignKey:LogTypeID" json:"-"`
|
|
||||||
Date string `gorm:"type:date;default:CURRENT_DATE" json:"date"`
|
|
||||||
Equipment []Asset `gorm:"many2many:log_equipment_asset;" json:"equipment"`
|
|
||||||
Substance []Asset `gorm:"many2many:log_substance_asset;" json:"substance"`
|
|
||||||
}
|
|
||||||
7
wagfarm-api/models/taxonomy_models.go
Normal file
7
wagfarm-api/models/taxonomy_models.go
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
type Taxonomy struct {
|
||||||
|
ID uint `gorm:"primaryKey" json:"id"`
|
||||||
|
Type string `gorm:"not null;index" json:"type"` // e.g., "unit", "color", etc.
|
||||||
|
Name string `gorm:"not null;index" json:"name"` // e.g., "kg", "lb"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user