mirror of
https://github.com/simonw/datasette.git
synced 2026-08-13 04:44:14 +02:00
parent
12b25affb5
commit
0337fba234
2 changed files with 40 additions and 1 deletions
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue