You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.3 KiB
51 lines
1.3 KiB
package model
|
|
|
|
import (
|
|
"gorm.io/driver/sqlite"
|
|
"gorm.io/gorm"
|
|
"whiteboxsystems.nl/openkvpoc/openkv"
|
|
"whiteboxsystems.nl/openkvpoc/sharedmodel"
|
|
)
|
|
|
|
func GetDB(location string) (*gorm.DB, error) {
|
|
db, err := gorm.Open(sqlite.Open(location), &gorm.Config{})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Migrate the schema
|
|
db.AutoMigrate(&sharedmodel.Registration{})
|
|
db.AutoMigrate(&sharedmodel.Connection{})
|
|
db.AutoMigrate(&sharedmodel.Service{})
|
|
db.AutoMigrate(&sharedmodel.AuthConfig{})
|
|
db.AutoMigrate(&sharedmodel.ProtocolConfig{})
|
|
db.AutoMigrate(&sharedmodel.ServiceConfig{})
|
|
db.AutoMigrate(&sharedmodel.Subscription{})
|
|
|
|
var cnt int64
|
|
db.Model(&sharedmodel.Service{}).Count(&cnt)
|
|
|
|
if cnt == 0 {
|
|
db.Create(&sharedmodel.Service{
|
|
Name: "KIS",
|
|
Description: "Ketenzorg informatie systeem",
|
|
SubscriptionPolicy: openkv.SubscriptionPolicy_optin,
|
|
ConsentPolicy: openkv.ConsentPolicy_presumed,
|
|
ServiceID: "voorbeeld:kiss",
|
|
FetchProtocols: sharedmodel.ProtocolArray{
|
|
{
|
|
"https://whiteboxsystems.nl/protospecs/whitebox-fetch/http",
|
|
[]openkv.AuthMethod{openkv.AuthMethod_APIToken},
|
|
},
|
|
},
|
|
PushProtocols: sharedmodel.ProtocolArray{
|
|
{
|
|
"https://whiteboxsystems.nl/protospecs/whitebox-push/http",
|
|
[]openkv.AuthMethod{openkv.AuthMethod_APIToken},
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
return db, nil
|
|
}
|
|
|