From ffe107329251d63223aa5d2de419bb08e34150d5 Mon Sep 17 00:00:00 2001 From: boojack Date: Sun, 19 Feb 2023 16:34:15 +0800 Subject: [PATCH] fix: schema path for demo mode (#1124) --- server/profile/profile.go | 2 +- store/db/db.go | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/server/profile/profile.go b/server/profile/profile.go index 3ef9f7f8..11c87a9f 100644 --- a/server/profile/profile.go +++ b/server/profile/profile.go @@ -52,7 +52,7 @@ func GetProfile() (*Profile, error) { flag.StringVar(&profile.Data, "data", "", "data directory") flag.Parse() - if profile.Mode != "dev" && profile.Mode != "prod" && profile.Mode != "demo" { + if profile.Mode != "demo" && profile.Mode != "dev" && profile.Mode != "prod" { profile.Mode = "demo" } diff --git a/store/db/db.go b/store/db/db.go index 279b22db..cea80b7d 100644 --- a/store/db/db.go +++ b/store/db/db.go @@ -111,7 +111,7 @@ func (db *DB) Open(ctx context.Context) (err error) { } } } else { - // In non-prod mode, we should migrate the database. + // In non-prod mode, we should always migrate the database. if _, err := os.Stat(db.profile.DSN); errors.Is(err, os.ErrNotExist) { if err := db.applyLatestSchema(ctx); err != nil { return fmt.Errorf("failed to apply latest schema: %w", err) @@ -133,7 +133,11 @@ const ( ) func (db *DB) applyLatestSchema(ctx context.Context) error { - latestSchemaPath := fmt.Sprintf("%s/%s/%s", "migration", db.profile.Mode, latestSchemaFileName) + schemaMode := "dev" + if db.profile.Mode == "prod" { + schemaMode = "prod" + } + latestSchemaPath := fmt.Sprintf("%s/%s/%s", "migration", schemaMode, latestSchemaFileName) buf, err := migrationFS.ReadFile(latestSchemaPath) if err != nil { return fmt.Errorf("failed to read latest schema %q, error %w", latestSchemaPath, err)