Skip to content

Commit 88ccb81

Browse files
committed
fix(mongodb): implement dropObjectStatement for collection drops via UI
1 parent af38e3b commit 88ccb81

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

Plugins/MongoDBDriverPlugin/MongoDBPluginDriver.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,13 @@ final class MongoDBPluginDriver: PluginDatabaseDriver, @unchecked Sendable {
634634
)
635635
}
636636

637+
/// A collection drop is a shell statement, not a SQL one: `db.<collection>.drop()`. The
638+
/// app-level fallback would emit `DROP TABLE <name>`, which the Mongo shell parser rejects.
639+
/// Mongo has no schemas or cascade, so both are ignored.
640+
func dropObjectStatement(name: String, objectType: String, schema: String?, cascade: Bool) -> String? {
641+
"db.\(name).drop()"
642+
}
643+
637644
func dropDatabase(name: String) async throws {
638645
guard let conn = mongoConnection else {
639646
throw MongoDBPluginError.notConnected

TableProTests/Core/MongoDB/MongoShellParserTests.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,19 @@ struct MongoShellParserTests {
312312
}
313313
}
314314

315+
@Test("SQL DROP TABLE fallback is rejected for MongoDB collections")
316+
func testDropTableFallbackIsRejected() {
317+
// The sidebar's drop used to fall through to the SQL fallback and emit
318+
// `DROP TABLE "<collection>"`, which the Mongo shell parser rejects. Dropping a
319+
// collection must go through `db.<collection>.drop()` instead.
320+
do {
321+
_ = try MongoShellParser.parse("DROP TABLE \"users\"")
322+
Issue.record("Expected the SQL DROP TABLE fallback to be rejected")
323+
} catch {
324+
// Any parse failure is the point: a Mongo connection must never send SQL.
325+
}
326+
}
327+
315328
@Test("runCommand")
316329
func testRunCommand() throws {
317330
let op = try MongoShellParser.parse("db.runCommand({\"ping\": 1})")

0 commit comments

Comments
 (0)