Skip to content

Commit

Permalink
Merge pull request #275 from fastenhealth/nickmurray/add-postgres-db-…
Browse files Browse the repository at this point in the history
…option
  • Loading branch information
AnalogJ authored Oct 16, 2023
2 parents ef68bfc + 189ebde commit 8861e4b
Show file tree
Hide file tree
Showing 19 changed files with 1,469 additions and 1,245 deletions.
1 change: 1 addition & 0 deletions backend/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func (c *configuration) Init() error {
c.SetDefault("web.allow_unsafe_endpoints", false)

c.SetDefault("web.src.frontend.path", "/opt/fasten/web")
c.SetDefault("database.type", "sqlite")
c.SetDefault("database.location", "/opt/fasten/db/fasten.db")
c.SetDefault("cache.location", "/opt/fasten/cache/")

Expand Down
5 changes: 5 additions & 0 deletions backend/pkg/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ type BackgroundJobStatus string
type BackgroundJobType string
type BackgroundJobSchedule string

type DatabaseRepositoryType string

const (
ResourceListPageSize int = 20

Expand Down Expand Up @@ -36,4 +38,7 @@ const (
BackgroundJobScheduleWeekly BackgroundJobSchedule = "WEEKLY"
BackgroundJobScheduleBiWeekly BackgroundJobSchedule = "BIWEEKLY"
BackgroundJobScheduleMonthly BackgroundJobSchedule = "MONTHLY"

DatabaseRepositoryTypeSqlite DatabaseRepositoryType = "sqlite"
DatabaseRepositoryTypePostgres DatabaseRepositoryType = "postgres"
)
20 changes: 20 additions & 0 deletions backend/pkg/database/factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package database

import (
"github.com/fastenhealth/fasten-onprem/backend/pkg"
"github.com/fastenhealth/fasten-onprem/backend/pkg/config"
"github.com/fastenhealth/fasten-onprem/backend/pkg/errors"
"github.com/fastenhealth/fasten-onprem/backend/pkg/event_bus"
"github.com/sirupsen/logrus"
)

func NewRepository(appConfig config.Interface, globalLogger logrus.FieldLogger, eventBus event_bus.Interface) (DatabaseRepository, error) {
switch pkg.DatabaseRepositoryType(appConfig.GetString("database.type")) {
case pkg.DatabaseRepositoryTypeSqlite:
return newSqliteRepository(appConfig, globalLogger, eventBus)
case pkg.DatabaseRepositoryTypePostgres:
return newPostgresRepository(appConfig, globalLogger, eventBus)
default:
return nil, errors.DatabaseTypeNotSupportedError(appConfig.GetString("database.type"))
}
}
Loading

0 comments on commit 8861e4b

Please sign in to comment.