Extend model with sections & model
This commit is contained in:
parent
0351eeafd4
commit
4be15c2f12
4 changed files with 77 additions and 1 deletions
|
|
@ -30,8 +30,23 @@ func connectDatabase() (*gorm.DB, error) {
|
||||||
sqlite.Open(config.Database.Location),
|
sqlite.Open(config.Database.Location),
|
||||||
&gorm.Config{},
|
&gorm.Config{},
|
||||||
)
|
)
|
||||||
|
if err != nil {
|
||||||
|
// TODO: Handle exception
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
database.AutoMigrate(&models.User{})
|
err = database.AutoMigrate(
|
||||||
|
&models.User{},
|
||||||
|
&models.ParentSection{},
|
||||||
|
&models.Section{},
|
||||||
|
&models.Person{},
|
||||||
|
&models.ManageSection{},
|
||||||
|
&models.ManageParentSection{},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
// TODO: Handle exception
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
connected = true
|
connected = true
|
||||||
|
|
||||||
|
|
|
||||||
18
models/people.go
Normal file
18
models/people.go
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
package models
|
||||||
|
|
||||||
|
import "gorm.io/gorm"
|
||||||
|
|
||||||
|
type Person struct {
|
||||||
|
gorm.Model
|
||||||
|
FirstName string
|
||||||
|
LastName string
|
||||||
|
Email string
|
||||||
|
Phone string
|
||||||
|
Mobile string
|
||||||
|
Address1 string
|
||||||
|
Address2 string
|
||||||
|
PostalCode string
|
||||||
|
City string
|
||||||
|
SectionID uint
|
||||||
|
Section Section
|
||||||
|
}
|
||||||
15
models/sections.go
Normal file
15
models/sections.go
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
package models
|
||||||
|
|
||||||
|
import "gorm.io/gorm"
|
||||||
|
|
||||||
|
type ParentSection struct {
|
||||||
|
gorm.Model
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
||||||
|
type Section struct {
|
||||||
|
gorm.Model
|
||||||
|
Name string
|
||||||
|
ParentSectionID uint
|
||||||
|
ParentSection ParentSection
|
||||||
|
}
|
||||||
|
|
@ -16,3 +16,31 @@ type User struct {
|
||||||
IsAdmin bool
|
IsAdmin bool
|
||||||
SkipWelcome bool
|
SkipWelcome bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ManageSection struct {
|
||||||
|
gorm.Model
|
||||||
|
UserID uint
|
||||||
|
User User
|
||||||
|
SectionID uint
|
||||||
|
Section Section
|
||||||
|
ShowPerson bool
|
||||||
|
CreatePerson bool
|
||||||
|
EditPerson bool
|
||||||
|
ShowArchivedPerson bool
|
||||||
|
ArchivePerson bool
|
||||||
|
UnarchivePerson bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type ManageParentSection struct {
|
||||||
|
gorm.Model
|
||||||
|
UserID uint
|
||||||
|
User User
|
||||||
|
ParentSectionID uint
|
||||||
|
ParentSection ParentSection
|
||||||
|
ShowPerson bool
|
||||||
|
CreatePerson bool
|
||||||
|
EditPerson bool
|
||||||
|
ShowArchivedPerson bool
|
||||||
|
ArchivePerson bool
|
||||||
|
UnarchivePerson bool
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue