mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Fix to support replacing a database, closes #2465
This commit is contained in:
parent
53a3b3c80e
commit
f95ac19e71
2 changed files with 36 additions and 2 deletions
|
|
@ -721,3 +721,34 @@ async def test_hidden_tables(app_client):
|
|||
"r_parent",
|
||||
"r_rowid",
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_replace_database(tmpdir):
|
||||
path1 = str(tmpdir / "data1.db")
|
||||
(tmpdir / "two").mkdir()
|
||||
path2 = str(tmpdir / "two" / "data1.db")
|
||||
sqlite3.connect(path1).executescript(
|
||||
"""
|
||||
create table t (id integer primary key);
|
||||
insert into t (id) values (1);
|
||||
insert into t (id) values (2);
|
||||
"""
|
||||
)
|
||||
sqlite3.connect(path2).executescript(
|
||||
"""
|
||||
create table t (id integer primary key);
|
||||
insert into t (id) values (1);
|
||||
"""
|
||||
)
|
||||
datasette = Datasette([path1])
|
||||
db = datasette.get_database("data1")
|
||||
count = (await db.execute("select count(*) from t")).first()[0]
|
||||
assert count == 2
|
||||
# Now replace that database
|
||||
datasette.get_database("data1").close()
|
||||
datasette.remove_database("data1")
|
||||
datasette.add_database(Database(datasette, path2), "data1")
|
||||
db2 = datasette.get_database("data1")
|
||||
count = (await db2.execute("select count(*) from t")).first()[0]
|
||||
assert count == 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue