Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

chore: don't clean data in dev mode

steven6a3b052fa2f9
diff --git a/store/db/db.go b/store/db/db.go
index ebf7a9415..52db60075 100644
--- a/store/db/db.go
+++ b/store/db/db.go
@@ -51,22 +51,22 @@ func (db *DB) Open(ctx context.Context) (err error) {
db.Db = sqlDB
// If mode is dev, we should migrate and seed the database.
if db.profile.Mode == "dev" {
- if err := db.applyLatestSchema(ctx); err != nil {
- return fmt.Errorf("failed to apply latest schema: %w", err)
- }
- if err := db.seed(ctx); err != nil {
- return fmt.Errorf("failed to seed: %w", err)
+ 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)
+ }
+ if err := db.seed(ctx); err != nil {
+ return fmt.Errorf("failed to seed: %w", err)
+ }
}
} else {
// If db file not exists, we should migrate the database.
if _, err := os.Stat(db.profile.DSN); errors.Is(err, os.ErrNotExist) {
- err := db.applyLatestSchema(ctx)
- if err != nil {
+ if err := db.applyLatestSchema(ctx); err != nil {
return fmt.Errorf("failed to apply latest schema: %w", err)
}
} else {
- err := db.createMigrationHistoryTable(ctx)
- if err != nil {
+ if err := db.createMigrationHistoryTable(ctx); err != nil {
return fmt.Errorf("failed to create migration_history table: %w", err)
}