Skip to content

Commit 00488bc

Browse files
committed
Consistent root path.
1 parent faf103e commit 00488bc

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

cpp/deeplake_pg/table_storage.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ icm::string_map<> session_credentials::get_credentials()
173173

174174
std::string session_credentials::get_root_path()
175175
{
176+
// Environment variable takes priority over per-session GUC
177+
auto root = base::getenv<std::string>("DEEPLAKE_ROOT_PATH", "");
178+
if (!root.empty()) {
179+
return root;
180+
}
176181
if (root_path_guc_string != nullptr && std::strlen(root_path_guc_string) > 0) {
177182
return std::string(root_path_guc_string);
178183
}
@@ -731,8 +736,11 @@ void table_storage::create_table(const std::string& table_name, Oid table_id, Tu
731736
if (session_root.empty()) {
732737
session_root = pg::utils::get_deeplake_root_directory();
733738
}
734-
// Construct path: root_dir/schema_name/table_name
735-
dataset_path = session_root + "/" + schema_name + "/" + simple_table_name;
739+
// Construct path: root_dir/db_name/schema_name/table_name
740+
// root_path is the global root; include the database name so each
741+
// database's datasets are stored under their own prefix.
742+
const auto db_name = get_current_database_name();
743+
dataset_path = session_root + "/" + db_name + "/" + schema_name + "/" + simple_table_name;
736744
}
737745

738746
// Get credentials from current session

postgres/tests/py_tests/test_root_path.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ async def test_root_path_basic(db_conn: asyncpg.Connection, temp_dir_for_postgre
5555
print(f"✓ Dataset path from metadata: {ds_path}")
5656

5757
# Verify the path starts with our root_path
58-
expected_path = os.path.join(root_path, "public", "test_root_path")
58+
# The extension now auto-includes the database name in the path:
59+
# root_path / db_name / schema / table
60+
db_name = await db_conn.fetchval("SELECT current_database()")
61+
expected_path = os.path.join(root_path, db_name, "public", "test_root_path")
5962
# Strip trailing slash for comparison
6063
ds_path_normalized = ds_path.rstrip('/')
6164
expected_path_normalized = expected_path.rstrip('/')

0 commit comments

Comments
 (0)