turso-cli icon indicating copy to clipboard operation
turso-cli copied to clipboard

There's nothing stopping people from dropping internal tables

Open CodingDoug opened this issue 1 year ago • 4 comments

I don't know if this is the right repo for this issue, apologies if this is wrong.

→  select * from sqlite_schema;
TYPE   NAME                    TBL_NAME                ROOTPAGE  SQL
table  libsql_wasm_func_table  libsql_wasm_func_table  2         CREATE TABLE libsql_wasm_func_table (name text PRIMARY KEY, body text) WITHOUT ROWID
table  _litestream_seq         _litestream_seq         3         CREATE TABLE _litestream_seq (id INTEGER PRIMARY KEY, seq INTEGER)
table  _litestream_lock        _litestream_lock        4         CREATE TABLE _litestream_lock (id INTEGER)
→  drop table libsql_wasm_func_table;

→  drop table _litestream_seq;

→  drop table _litestream_lock;

→  select * from sqlite_schema;
TYPE  NAME  TBL_NAME  ROOTPAGE  SQL

Did I just do something very bad to this database? If I later create a replica, that db will have libsql_wasm_func_table, and then it reappears at the primary. But the litestream tables seem to be gone permanently.

SQLite stops important tables from being dropped:

→  drop table sqlite_schema;
Error: table sqlite_master may not be dropped

We should probably do the same. Also probably control read/write access on them as appropriate.

CodingDoug avatar Mar 11 '23 23:03 CodingDoug

I think it's an sqld issue.

haaawk avatar Mar 13 '23 09:03 haaawk

@haaawk The main reason why I didn't initially file this under sqld is because I couldn't find any references to "litestream" anywhere in that codebase. I don't know where it comes from.

CodingDoug avatar Mar 13 '23 12:03 CodingDoug

Fair point. The litestream tables are turso. wasm_func_table is sqld/libsql

haaawk avatar Mar 13 '23 12:03 haaawk

sqld could allow marking tables as protected, without protecting any, and then turso-api could, on database creation, protect the ones we care about.

glommer avatar Mar 28 '23 10:03 glommer