79 lines
1.5 KiB
Go
79 lines
1.5 KiB
Go
package db
|
|
|
|
import (
|
|
"gorm.io/driver/postgres"
|
|
"gorm.io/gorm"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
type Class struct {
|
|
id uint "gorm:primaryKey"
|
|
name string
|
|
created_at time.Time
|
|
}
|
|
|
|
type Student struct {
|
|
id uint "gorm:primaryKey"
|
|
prename string
|
|
surname string
|
|
sex string
|
|
study_id uint
|
|
class_id uint
|
|
group_id uint
|
|
created_at time.Time
|
|
}
|
|
|
|
type Study struct {
|
|
id uint "gorm:primaryKey"
|
|
name string
|
|
created_at time.Time
|
|
}
|
|
|
|
type Lecture struct {
|
|
id uint "gorm:primaryKey"
|
|
title string
|
|
points uint
|
|
class_id uint
|
|
created_at time.Time
|
|
}
|
|
|
|
type Submission struct {
|
|
id uint "gorm:primaryKey"
|
|
student_id uint
|
|
lecture_id uint
|
|
class_id uint
|
|
points float32
|
|
created_at time.Time
|
|
}
|
|
|
|
type Group struct {
|
|
id uint "gorm:primaryKey"
|
|
name string
|
|
project string
|
|
has_passed bool
|
|
presentation string
|
|
class_id uint
|
|
created_at time.Time
|
|
}
|
|
|
|
func ConnectDB() *gorm.DB {
|
|
dsn := "host=postgres.cyperpunk.de user=dergrumpf password=1P2h3i4lon$% dbname=phil port=5432 sslmode=disable TimeZone=Europe/Berlin"
|
|
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
|
|
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
}
|
|
|
|
db.AutoMigrate(
|
|
&Class{},
|
|
&Student{},
|
|
&Study{},
|
|
&Lecture{},
|
|
&Submission{},
|
|
&Group{},
|
|
)
|
|
|
|
return db
|
|
}
|