mirror of
https://github.com/lancedb/lancedb.git
synced 2026-10-29 06:56:15 +00:00
feat: add a cascade option to drop_database (#4697)
The remote catalog could only drop an empty database: it always asked
the server for a restricted drop.
`DropDatabaseRequest::cascade`, `drop_database(..., cascade=True)` in
Python and `dropDatabase(name, { cascade: true })` in TypeScript ask the
server to drop everything in the database first. The name stays taken
until the server finishes cleaning up the dropped objects' storage. A
restricted drop remains the default.
This commit is contained in:
@@ -86,7 +86,10 @@ describe("remote catalog", () => {
|
||||
value: "team/search",
|
||||
});
|
||||
expect(names.pageToken()).toBe("next");
|
||||
await catalog.dropDatabase("team/search", { ignoreMissing: true });
|
||||
await catalog.dropDatabase("team/search", {
|
||||
ignoreMissing: true,
|
||||
cascade: true,
|
||||
});
|
||||
expect(requests[0].url).toBe("/v1/namespace/team%2Fsearch/create");
|
||||
expect(requests[0].body).toEqual({ mode: "ExistOk" });
|
||||
expect(requests[5].url).toBe(
|
||||
@@ -94,7 +97,7 @@ describe("remote catalog", () => {
|
||||
);
|
||||
expect(requests[6].body).toEqual({
|
||||
mode: "Skip",
|
||||
behavior: "Restrict",
|
||||
behavior: "Cascade",
|
||||
});
|
||||
for (const [i, request] of requests.entries()) {
|
||||
expect(request.headers["x-lancedb-database"]).toBe(
|
||||
|
||||
@@ -82,12 +82,16 @@ export class Catalog {
|
||||
return new LocalConnection(await this.inner.connectDatabase(name));
|
||||
}
|
||||
|
||||
/** Drop an empty database. The server rejects nonempty databases. */
|
||||
/**
|
||||
* Drop a database. A nonempty database is an error unless `cascade` is set,
|
||||
* which drops everything in it first; the name stays taken until the server
|
||||
* finishes cleaning up their storage.
|
||||
*/
|
||||
async dropDatabase(
|
||||
name: string,
|
||||
options: { ignoreMissing?: boolean } = {},
|
||||
options: { ignoreMissing?: boolean; cascade?: boolean } = {},
|
||||
): Promise<void> {
|
||||
await this.inner.dropDatabase(name, options.ignoreMissing);
|
||||
await this.inner.dropDatabase(name, options.ignoreMissing, options.cascade);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -124,10 +124,17 @@ impl Catalog {
|
||||
.default_error()
|
||||
}
|
||||
#[napi]
|
||||
pub async fn drop_database(&self, name: String, ignore_missing: Option<bool>) -> Result<()> {
|
||||
pub async fn drop_database(
|
||||
&self,
|
||||
name: String,
|
||||
ignore_missing: Option<bool>,
|
||||
cascade: Option<bool>,
|
||||
) -> Result<()> {
|
||||
self.inner
|
||||
.drop_database(
|
||||
DropDatabaseRequest::new(name).ignore_missing(ignore_missing.unwrap_or(false)),
|
||||
DropDatabaseRequest::new(name)
|
||||
.ignore_missing(ignore_missing.unwrap_or(false))
|
||||
.cascade(cascade.unwrap_or(false)),
|
||||
)
|
||||
.await
|
||||
.default_error()
|
||||
|
||||
Reference in New Issue
Block a user