mirror of
https://github.com/typesense/typesense.git
synced 2025-05-21 14:12:27 +08:00
Properly handle deleting collection via an alias.
This commit is contained in:
parent
b191a74016
commit
222ab345be
@ -413,6 +413,9 @@ Option<nlohmann::json> CollectionManager::drop_collection(const std::string& col
|
||||
return Option<nlohmann::json>(404, "No collection with name `" + collection_name + "` found.");
|
||||
}
|
||||
|
||||
// to handle alias resolution
|
||||
const std::string actual_coll_name = collection->get_name();
|
||||
|
||||
nlohmann::json collection_json = collection->get_summary_json();
|
||||
|
||||
if(remove_from_store) {
|
||||
@ -426,11 +429,11 @@ Option<nlohmann::json> CollectionManager::drop_collection(const std::string& col
|
||||
}
|
||||
delete iter;
|
||||
|
||||
store->remove(Collection::get_next_seq_id_key(collection_name));
|
||||
store->remove(Collection::get_meta_key(collection_name));
|
||||
store->remove(Collection::get_next_seq_id_key(actual_coll_name));
|
||||
store->remove(Collection::get_meta_key(actual_coll_name));
|
||||
}
|
||||
|
||||
collections.erase(collection_name);
|
||||
collections.erase(actual_coll_name);
|
||||
collection_id_names.erase(collection->get_collection_id());
|
||||
|
||||
delete collection;
|
||||
|
@ -435,6 +435,15 @@ TEST_F(CollectionManagerTest, Symlinking) {
|
||||
ASSERT_TRUE(collection_option.ok());
|
||||
ASSERT_EQ("collection1", collection_option.get());
|
||||
|
||||
// try to drop a collection using the alias `collection1_link`
|
||||
auto drop_op = cmanager.drop_collection("collection1_link");
|
||||
ASSERT_TRUE(drop_op.ok());
|
||||
|
||||
// try to list collections now
|
||||
nlohmann::json summaries = cmanager.get_collection_summaries();
|
||||
ASSERT_EQ(0, summaries.size());
|
||||
|
||||
// remap alias to another non-existing collection
|
||||
inserted = cmanager.upsert_symlink("collection1_link", "collection2");
|
||||
ASSERT_TRUE(inserted.ok());
|
||||
collection_option = cmanager.resolve_symlink("collection1_link");
|
||||
|
Loading…
x
Reference in New Issue
Block a user