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.

feat(store): change default storage type to local filesystem

Johnny78efa6802e2f
diff --git a/store/instance_setting.go b/store/instance_setting.go
index d64508159..3b44ce1a5 100644
--- a/store/instance_setting.go
+++ b/store/instance_setting.go
@@ -169,7 +169,7 @@ func (s *Store) GetInstanceMemoRelatedSetting(ctx context.Context) (*storepb.Ins
}
const (
- defaultInstanceStorageType = storepb.InstanceStorageSetting_DATABASE
+ defaultInstanceStorageType = storepb.InstanceStorageSetting_LOCAL
defaultInstanceUploadSizeLimitMb = 30
defaultInstanceFilepathTemplate = "assets/{timestamp}_{filename}"
)
diff --git a/store/migration/mysql/0.26/03__migrate_storage_setting.sql b/store/migration/mysql/0.26/03__migrate_storage_setting.sql
new file mode 100644
index 000000000..9a8187713
--- /dev/null
+++ b/store/migration/mysql/0.26/03__migrate_storage_setting.sql
@@ -0,0 +1,6 @@
+-- Set storage type to DATABASE for existing instances that have no storage setting configured.
+-- This preserves backward-compatible behavior before the default was changed to LOCAL.
+INSERT INTO system_setting (name, value, description)
+SELECT 'STORAGE', '{"storageType":"DATABASE"}', ''
+FROM DUAL
+WHERE NOT EXISTS (SELECT 1 FROM system_setting WHERE name = 'STORAGE');
diff --git a/store/migration/postgres/0.26/03__migrate_storage_setting.sql b/store/migration/postgres/0.26/03__migrate_storage_setting.sql
new file mode 100644
index 000000000..ea40755a9
--- /dev/null
+++ b/store/migration/postgres/0.26/03__migrate_storage_setting.sql
@@ -0,0 +1,5 @@
+-- Set storage type to DATABASE for existing instances that have no storage setting configured.
+-- This preserves backward-compatible behavior before the default was changed to LOCAL.
+INSERT INTO system_setting (name, value, description)
+SELECT 'STORAGE', '{"storageType":"DATABASE"}', ''
+WHERE NOT EXISTS (SELECT 1 FROM system_setting WHERE name = 'STORAGE');
diff --git a/store/migration/sqlite/0.26/05__migrate_storage_setting.sql b/store/migration/sqlite/0.26/05__migrate_storage_setting.sql
new file mode 100644
index 000000000..ea40755a9
--- /dev/null
+++ b/store/migration/sqlite/0.26/05__migrate_storage_setting.sql
@@ -0,0 +1,5 @@
+-- Set storage type to DATABASE for existing instances that have no storage setting configured.
+-- This preserves backward-compatible behavior before the default was changed to LOCAL.
+INSERT INTO system_setting (name, value, description)
+SELECT 'STORAGE', '{"storageType":"DATABASE"}', ''
+WHERE NOT EXISTS (SELECT 1 FROM system_setting WHERE name = 'STORAGE');
diff --git a/store/test/instance_setting_test.go b/store/test/instance_setting_test.go
index 0f0c4cfb0..241c3e26e 100644
--- a/store/test/instance_setting_test.go
+++ b/store/test/instance_setting_test.go
@@ -193,7 +193,7 @@ func TestInstanceSettingStorageSetting(t *testing.T) {
storageSetting, err := ts.GetInstanceStorageSetting(ctx)
require.NoError(t, err)
require.NotNil(t, storageSetting)
- require.Equal(t, storepb.InstanceStorageSetting_DATABASE, storageSetting.StorageType)
+ require.Equal(t, storepb.InstanceStorageSetting_LOCAL, storageSetting.StorageType)
require.Equal(t, int64(30), storageSetting.UploadSizeLimitMb)
require.Equal(t, "assets/{timestamp}_{filename}", storageSetting.FilepathTemplate)