Skip to main content

Track changes to data using triggers and hidden JSON tables

Project description

datasette-sqlite-history-json

PyPI Changelog Tests License

Track changes to data using triggers and hidden JSON tables using sqlite-history-json.

Installation

Install this plugin in the same environment as Datasette.

datasette install datasette-sqlite-history-json

Usage

Install tracking on a table from Datasette's table actions menu (Enable tracking) or access the route directly:

/-/history-json/<database>/<table>/-/enable

Once enabled, the table action menu also shows:

  • View history → table history page at /-/history-json/<database>/<table>
  • Disable tracking if tracking is already active

On each row in a tracked table, the row action menu now shows:

  • View row history/-/history-json/<database>/<table>/<primary-key>, with a subtitle showing the number of changes.
  • If the table is not tracked, or the user lacks permission, that action does not appear.

API

All endpoints return JSON for machine access and can be used in scripts:

  • Table history: /-/history-json/<database>/<table>.json
  • Row history: /-/history-json/<database>/<table>/<primary-key>.json
  • Filter by operation: ?operation=insert|update|delete

Permissions

The plugin registers:

  • sqlite-history-json for enabling/disabling tracking (database-level action)
  • sqlite-history-json-view for viewing history (table-level action)

sqlite-history-json-view is automatically allowed in non---default-deny mode when the actor can view-table.

Required permissions by feature:

  • Enable tracking: sqlite-history-json on DatabaseResource(database)
  • Disable tracking: sqlite-history-json on DatabaseResource(database)
  • View table history page/action: sqlite-history-json-view on TableResource(database, table) (plus the implicit view-table check)
  • View row history action/page: same as table history permission above

In --default-deny mode, sqlite-history-json-view is not auto-granted. In that case, provide explicit grants for that action in your permission policy (and keep sqlite-history-json grants as needed for managing tracking).

Notes

<primary-key> is URL-safe, tilde-encoded values in the same format Datasette uses internally (for example comma-joined values for composite keys).

Development

To set up this plugin locally, first checkout the code. You can confirm it is available like this:

cd datasette-sqlite-history-json
# Confirm the plugin is visible
uv run datasette plugins

To run the tests:

uv run pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

datasette_sqlite_history_json-0.1a0.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

datasette_sqlite_history_json-0.1a0-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file datasette_sqlite_history_json-0.1a0.tar.gz.

File metadata

File hashes

Hashes for datasette_sqlite_history_json-0.1a0.tar.gz
Algorithm Hash digest
SHA256 a7bba6b30620c0079745e8fb546deaf83285eec167de19c9426b59378124513e
MD5 1980b4e85d055c47636f294880940a0c
BLAKE2b-256 afefde322d5902e7bebfc9906cd047005ff824c52177b5af5819f99b04a1512f

See more details on using hashes here.

Provenance

The following attestation bundles were made for datasette_sqlite_history_json-0.1a0.tar.gz:

Publisher: publish.yml on datasette/datasette-sqlite-history-json

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file datasette_sqlite_history_json-0.1a0-py3-none-any.whl.

File metadata

File hashes

Hashes for datasette_sqlite_history_json-0.1a0-py3-none-any.whl
Algorithm Hash digest
SHA256 5cb46ff662ab14d5c4135634cc52f026f4a1d3b0ff116e2b8761c17ad54254ff
MD5 3686e7c560da53eac297a3c5edcfd47b
BLAKE2b-256 79d8216b4ca66795e33f9dde60b3f51187b345a31f4fa3d9f2512d1df23b15ae

See more details on using hashes here.

Provenance

The following attestation bundles were made for datasette_sqlite_history_json-0.1a0-py3-none-any.whl:

Publisher: publish.yml on datasette/datasette-sqlite-history-json

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page