@@ -213,17 +213,25 @@ StorageEmbeddedRocksDB::StorageEmbeddedRocksDB(const StorageID & table_id_,
213213 setSettings (std::move (settings_));
214214
215215 if (rocksdb_dir.empty ())
216- rocksdb_dir = fs::path{getContext ()->getUserFilesPath ()} / relative_data_path_;
217-
218- bool is_local = context_->getApplicationType () == Context::ApplicationType::LOCAL;
219- fs::path user_files_path = is_local ? " " : fs::canonical (getContext ()->getUserFilesPath ());
220- if (fs::path (rocksdb_dir).is_relative ())
221- rocksdb_dir = user_files_path / rocksdb_dir;
222- rocksdb_dir = fs::absolute (rocksdb_dir).lexically_normal ();
223-
224- if (!is_local && !pathStartsWith (fs::path (rocksdb_dir), user_files_path))
225- throw Exception (ErrorCodes::BAD_ARGUMENTS,
226- " Path must be inside user-files path: {}" , user_files_path.string ());
216+ {
217+ // / We used to create databases under the database directory by default instead of user files. Check first if it exists there
218+ auto old_path = context_->getPath () + relative_data_path_;
219+ if (mode >= LoadingStrictnessLevel::ATTACH && fs::exists (old_path))
220+ rocksdb_dir = old_path;
221+ else
222+ rocksdb_dir = fs::path{getContext ()->getUserFilesPath ()} / relative_data_path_;
223+ }
224+ else
225+ {
226+ bool is_local = context_->getApplicationType () == Context::ApplicationType::LOCAL;
227+ fs::path user_files_path = is_local ? " " : fs::canonical (getContext ()->getUserFilesPath ());
228+ if (fs::path (rocksdb_dir).is_relative ())
229+ rocksdb_dir = user_files_path / rocksdb_dir;
230+ rocksdb_dir = fs::absolute (rocksdb_dir).lexically_normal ();
231+
232+ if (!is_local && !pathStartsWith (fs::path (rocksdb_dir), user_files_path))
233+ throw Exception (ErrorCodes::BAD_ARGUMENTS, " Path must be inside user-files path: {}" , user_files_path.string ());
234+ }
227235
228236 if (mode < LoadingStrictnessLevel::ATTACH)
229237 {
0 commit comments