simonw/datasette-app

_desktop.db mechanism for storing app preferences, audit logs and suchlike

simonw opened this issue · 3 comments

If I'm going to have default plugins and I'm going to let users uninstall them, I need a way of remembering what they uninstalled.

I quite like the idea of doing this as an audit log - so every time a user installs or uninstalls or upgrades a plugin we record that permanently somewhere. This could be really useful for debugging later on.

Obviously this should be a SQLite database somewhere. But what should it be called?

Some options:

  • prefs.db or preferences.db
  • config.db - could be confused with Datasette's concept of configuration (e.g plugin configuration)
  • settings.db - definitely confused with Datasette's --setting mechanism

So preferences.db is probably the best option - but do I risk confusion over preferences v.s. settings v.s. configuration v.s. metadata? And what if there's stuff I end up storing in there that doesn't classify as user preferences?

I could call it _desktop.db since it's the internal database for stuff relating to the Datasette Desktop app.

Originally posted by @simonw in #72 (comment)

What kind of stuff could go in here?

  • Plugin audit log, needed by #72 to persist the fact that default plugins may have been deliberately uninstalled
  • Persistent network settings, e.g. that the user wants the app to be available to the rest of the network
  • Maybe authentication credentials such that other users on the network have to sign in to view
  • Saved bookmarks and history, see #85
  • A log of recently run queries too (a specialized case of history)
  • API keys and other credentials needed by potential future plugins, e.g. Dogsheep stuff

And a really fun idea I've been contemplating: imagine a form of plugin which is pure JavaScript and can be installed by copying and pasting a chunk of code into a textarea and hitting "save".

So where does this thing go? I think it goes in the app.getPath("userData") folder.

One problem: the Electron shell knows where that is, but the datasette process doesn't without the shell telling it. So I think the shell sets that as another environment variable here:

datasette-app/main.js

Lines 167 to 172 in f83a929

process = cp.spawn(datasette_bin, this.serverArgs(), {
env: {
DATASETTE_API_TOKEN: this.apiToken,
DATASETTE_SECRET: RANDOM_SECRET,
},
});
- maybe DATASETTE_USER_DATA or DATASETTE_DESKTOP_DB (a full path to the _desktop.db file).