Skip to content

Commit 15fe529

Browse files
rustyconoverclaude
andcommitted
feat(attach): name discovered catalog as the DB alias
On the bare connection-string form, DuckDB derives the database alias from the path basename, so `vgi:uvx vgi-easter` surfaced as the ugly `uvx vgi-easter` rather than the catalog name. When the alias was path-derived (CLI default-DB open, or ATTACH with no AS clause), rename the AttachedDatabase to the discovered catalog name via SetName(). Registration reads GetName() after attach (DatabaseManager::FinalizeAttach) and derives the default-database pointer from it, so the rename is honored consistently — current_database() and unqualified lookups resolve under the catalog name. A user-chosen `AS alias` (name differs from the path basename) is left untouched. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent e19e189 commit 15fe529

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

src/vgi_extension.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#endif
1616

1717
#include "duckdb.hpp"
18+
#include "duckdb/common/file_system.hpp"
1819
#include "duckdb/main/attached_database.hpp"
1920
#include "duckdb/main/config.hpp"
2021
#include "duckdb/main/database_manager.hpp"
@@ -1333,6 +1334,20 @@ static unique_ptr<Catalog> VgiCatalogAttach(optional_ptr<StorageExtensionInfo> s
13331334
worker_path);
13341335
}
13351336
catalog_name = catalogs[0].name;
1337+
1338+
// When DuckDB derived the database alias from the path (the CLI
1339+
// default-DB open `vgi:uvx vgi-easter`, or `ATTACH 'uvx vgi-easter'
1340+
// (TYPE vgi)` with no AS clause), the alias is the ugly path
1341+
// basename. Replace it with the discovered catalog name so the DB
1342+
// surfaces as `easter`, not `uvx vgi-easter`. Registration reads
1343+
// GetName() *after* attach (DatabaseManager::FinalizeAttach), and
1344+
// derives the default-database pointer from it too, so SetName here
1345+
// is honored consistently. A user-chosen `AS alias` (name differs
1346+
// from the path basename) is left untouched.
1347+
auto &fs = FileSystem::GetFileSystem(context);
1348+
if (name == AttachedDatabase::ExtractDatabaseName(info.path, fs)) {
1349+
db.SetName(catalog_name);
1350+
}
13361351
}
13371352

13381353
// Validate attach-time options against the resolved catalog's declared

0 commit comments

Comments
 (0)