disable_fts() before dropping table

Closes #2874
This commit is contained in:
Simon Willison 2026-08-10 15:03:29 -07:00 committed by GitHub
commit 0337fba234
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 40 additions and 1 deletions

View file

@ -1391,7 +1391,9 @@ class TableDropView(BaseView):
# Drop table
def drop_table(conn):
sqlite_utils.Database(conn)[table_name].drop()
table = sqlite_utils.Database(conn)[table_name]
table.disable_fts()
table.drop()
await db.execute_write_fn(drop_table, request=request)
await self.ds.track_event(

View file

@ -1,6 +1,7 @@
import time
import pytest
import sqlite_utils
from datasette.app import Datasette
from datasette.events import RenameTableEvent
@ -1725,6 +1726,42 @@ async def test_drop_table(ds_write, scenario):
assert (await ds_write.client.get("/data/docs")).status_code == 404
@pytest.mark.asyncio
async def test_drop_table_cleans_up_fts(ds_write):
db = ds_write.get_database("data")
def enable_fts(conn):
sqlite_utils.Database(conn)["docs"].enable_fts(["title"], create_triggers=True)
await db.execute_write_fn(enable_fts)
assert {
row[0]
for row in await db.execute(
"select name from sqlite_master where type = 'table' and name like 'docs_fts%'"
)
} == {
"docs_fts",
"docs_fts_config",
"docs_fts_data",
"docs_fts_docsize",
"docs_fts_idx",
}
response = await ds_write.client.post(
"/data/docs/-/drop",
json={"confirm": True},
headers=_headers(write_token(ds_write)),
)
assert response.json() == {"ok": True}
assert [
row[0]
for row in await db.execute(
"select name from sqlite_master where type = 'table' and name like 'docs_fts%'"
)
] == []
@pytest.mark.asyncio
@pytest.mark.parametrize(
"input,expected_status,expected_response,expected_events",