forked from tiagorlampert/CHAOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprovider.go
36 lines (31 loc) · 803 Bytes
/
provider.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package database
import (
"github.com/tiagorlampert/CHAOS/entities"
"github.com/tiagorlampert/CHAOS/internal"
"github.com/tiagorlampert/CHAOS/internal/environment"
"gorm.io/gorm"
"log"
)
const tablePrefix = "v1_0_"
type Provider struct {
Conn *gorm.DB
}
func NewProvider(configuration environment.Database) (*Provider, error) {
switch {
case configuration.Sqlite.IsValid():
log.Println("Starting sqlite database")
return NewSqliteClient(configuration.Sqlite)
case configuration.Postgres.IsValid():
log.Println("Starting postgres database")
return NewPostgresClient(configuration.Postgres)
default:
return nil, internal.ErrNoDatabaseProvided
}
}
func (p *Provider) Migrate() error {
return p.Conn.AutoMigrate(
&entities.User{},
&entities.Device{},
&entities.Auth{},
)
}