Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proper SQLite default database and warn SHIORI_DBMS users #667

Merged
merged 4 commits into from Jul 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 13 additions & 12 deletions internal/cmd/root.go
Expand Up @@ -82,7 +82,7 @@ func initShiori(ctx context.Context, cmd *cobra.Command) (*config.Config, *confi
logger.WithError(err).Fatal("error creating data directory")
}

db, err := openDatabase(ctx, cfg.Database.DBMS, cfg.Database.URL)
db, err := openDatabase(logger, ctx, cfg)
if err != nil {
logger.WithError(err).Fatal("error opening database")
}
Expand Down Expand Up @@ -124,23 +124,24 @@ func initShiori(ctx context.Context, cmd *cobra.Command) (*config.Config, *confi
return cfg, dependencies
}

func openDatabase(ctx context.Context, dbms, dbURL string) (database.DB, error) {
if dbURL != "" {
return database.Connect(ctx, dbURL)
func openDatabase(logger *logrus.Logger, ctx context.Context, cfg *config.Config) (database.DB, error) {
if cfg.Database.URL != "" {
return database.Connect(ctx, cfg.Database.URL)
}
if dbms == "mysql" {

if cfg.Database.DBMS != "" {
logger.Warnf("The use of SHIORI_DBMS is deprecated and will be removed in the future. Please migrate to SHIORI_DATABASE_URL instead.")
}

// TODO remove this the moment DBMS is deprecated
if cfg.Database.DBMS == "mysql" {
return openMySQLDatabase(ctx)
}
if dbms == "postgresql" {
if cfg.Database.DBMS == "postgresql" {
return openPostgreSQLDatabase(ctx)
}
return openSQLiteDatabase(ctx)
}

func openSQLiteDatabase(ctx context.Context) (database.DB, error) {
dataDir := os.Getenv("SHIORI_DIR")
dbPath := fp.Join(dataDir, "shiori.db")
return database.OpenSQLiteDatabase(ctx, dbPath)
return database.OpenSQLiteDatabase(ctx, fp.Join(cfg.Storage.DataDir, "shiori.db"))
}

func openMySQLDatabase(ctx context.Context) (database.DB, error) {
Expand Down