Commit graph

3,240 commits

Author SHA1 Message Date
Simon Willison
21c156dfb1 Expose foreign key targets to create table UI
- Add foreignKeyTargetsPath to create table page data
- Filter hidden tables from database-level foreign key target results
- Update JSON API docs and tests for filtered targets
2026-06-22 10:11:56 -07:00
Simon Willison
a6ef65f90d /<database>/-/foreign-key-targets API endpoint
Returns a list of tables with a single primary key, and for each one
the name of that primary key column and its SQLite type affinity.

This will be used by the create table UI to suggest foreign keys.
2026-06-22 10:11:56 -07:00
Simon Willison
2900efb32d /db/table/-/foreign-key-suggestions API
Improved version of the implementation datasette-edit-schema
2026-06-22 10:11:56 -07:00
Simon Willison
9d9a2d3ff3 Add foreign keys to alter table API
- Add add_foreign_key, drop_foreign_key, and set_foreign_keys operations.
- Validate flat fk_table and fk_column arguments with Pydantic.
- Document the API and cover inferred primary-key and validation cases.
2026-06-22 10:11:56 -07:00
Simon Willison
9766a9c087 Add foreign keys to create table API
- Add fk_table and optional fk_column support to create-table columns.
- Validate create-table requests with Pydantic while preserving existing errors.
- Document the API and cover inferred primary-key and validation cases.
Refs https://github.com/simonw/datasette/pull/2789#issuecomment-4733544452
2026-06-22 10:11:56 -07:00
Simon Willison
1972ba8952 Split table create and alter views
- Move create-table and alter-table API views into table_create_alter.py.
- Keep create and alter schema-editing constants and helpers together.
- Rename the create table modal context helper.
2026-06-22 10:11:56 -07:00
Simon Willison
8cec528eeb Test against pyodide/v314.0.0
Now that we depend on pydantic we need a more recent
pyodide in order to load the emscripten build
of pydantic-core.

Refs https://github.com/simonw/datasette/pull/2789#issuecomment-4733412763
2026-06-22 10:11:56 -07:00
Simon Willison
4115213e17 Precompute action permissions for table pages
- Extract reusable helpers for database and table action permission preloading.
- Precompute those permissions before building table-page HTML data.
- Document the default table actions plugin.
2026-06-22 10:11:56 -07:00
Simon Willison
c9c79fdfc8 Isolate Unix domain socket test server paths
- Use a per-process socket path for the UDS test fixture.
- Clean up stale socket files before and after the fixture runs.
- Close the HTTP client and wait for the Datasette subprocess to exit.
2026-06-22 10:11:56 -07:00
Simon Willison
15a3ac58cc Ran Prettier 2026-06-22 10:11:56 -07:00
Simon Willison
fdd1b61a3e Add alter table modal
- Register a built-in table action and expose alter-table metadata to table pages.
- Build the client-side modal for editing columns, defaults, ordering, primary keys, and custom column types.
- Add a review/apply confirmation flow with HTML and Playwright coverage.

Refs #2788
2026-06-22 10:11:56 -07:00
Simon Willison
b40665dd14 Add alter table JSON API
- Add POST /<database>/<table>/-/alter with Pydantic validation and dry-run support.
- Support add, rename, alter, drop, primary-key and reorder operations, including allow-listed default expressions.
- Document the endpoint and cover schema changes, validation, permissions, events and dry runs.

Refs #2788
2026-06-22 10:11:56 -07:00
Simon Willison
2d3c85dfc0 Add create table UI
Adds a permission-gated database action that opens a create table modal on database pages, backed by the existing create-table JSON API.

The modal starts with an id integer primary key column plus a blank text column, supports SQLite type selection, and shows custom column type controls only when the actor can set column types.

Selected custom column types are applied after table creation with follow-up set-column-type API calls. Includes styling plus HTML and Playwright coverage for the action payload and create-table flow.
2026-06-22 10:11:56 -07:00
Simon Willison
57e7bba38f Stop matrix testing against sqlite-utils 4.0rc1
Refs https://github.com/simonw/sqlite-utils/issues/758#issuecomment-4770349630

I'm going to test this in a branch instead.
2026-06-22 09:06:00 -07:00
Simon Willison
bccb7f17e5 Don't fail test run on sqlite-utils 4.0rc1 failures
Refs https://github.com/simonw/sqlite-utils/issues/758#issuecomment-4763675905
2026-06-21 16:52:14 -07:00
Simon Willison
387f4dd4bc Try sqlite-utils 4.0rc1 in CI
Also output current sqlite-utils version in pytest headers

Refs https://github.com/simonw/sqlite-utils/issues/758
2026-06-21 16:46:20 -07:00
Simon Willison
ad6fe47a95 Better way of setting min height on CodeMirror
Previously there were four lines of whitespace, but that
meant users had to delete that whitespace themselves when
they started editing. Now it is four lines tall without that.
2026-06-19 22:40:37 -07:00
Simon Willison
f673e7416f
Add create table execute-write template (#2794)
Add a Create table starter template to the execute-write page, alongside the existing table-specific insert/update/delete templates.

Keep template button clicks in-page by updating CodeMirror and the URL without collapsing the template controls.

Refresh schema metadata after successful schema-changing execute-write statements so newly created tables appear immediately.
2026-06-19 17:14:33 -07:00
Simon Willison
dfd5b95ec8 Document --headed option, closes #2791 2026-06-17 09:52:02 -07:00
Simon Willison
1ae55007f2 Release 1.0a34 1.0a34
Refs #2767, #2775, #2776, #2779, #2780, #2782
2026-06-16 14:27:26 -07:00
Simon Willison
8c700f5337 Renamed base_url parameter to ds_base_url in tests
Integrating Playwright brought in pytest-base-url which declares a
base_url fixture that was colliding with our own base_url parameters.
2026-06-16 14:25:42 -07:00
Simon Willison
39a397e5b7
Test Datasette JavaScript features using Playwright
Merge pull request #2785 from simonw/playwright-tests
2026-06-16 14:16:20 -07:00
Simon Willison
3edc98a871 Playwright tests exercise the real UI now
Refs https://github.com/simonw/datasette/pull/2785#issuecomment-4723583959
2026-06-16 14:13:44 -07:00
Simon Willison
a8124172dd Remove load_edit_tools(), use a new fixture instead
Refs https://github.com/simonw/datasette/pull/2785/changes#r3423913454
2026-06-16 13:54:00 -07:00
Simon Willison
2f27b08405 Use code-block:: bash for Playwright docs 2026-06-16 13:41:24 -07:00
Simon Willison
77fa49cf17 Just recipes for running Playwright tests
Plus the pytest header now reports selected Playwright browsers
2026-06-16 13:35:17 -07:00
Simon Willison
2a887e5853 Merge branch 'main' into playwright-tests 2026-06-16 13:29:22 -07:00
Simon Willison
b5ba41c9db Fix for Safari esc-closes-confirm bug, closes #2784 2026-06-16 13:28:18 -07:00
Simon Willison
0a0491568a Fix flaky autocomplete timeout test 2026-06-16 11:59:42 -07:00
Simon Willison
dc6f207d37 Update unreleased release notes section
Refs #2780 and many more.
2026-06-14 20:29:59 -07:00
Simon Willison
49362a9b20 await request.json() method, closes #2767 2026-06-14 17:00:12 -07:00
Simon Willison
0748b561d5 Document Playwright test commands
Refs #2779
2026-06-14 16:52:07 -07:00
Simon Willison
387e309b3b Port JSON column field test to Playwright
Refs #2779
2026-06-14 16:49:30 -07:00
Simon Willison
3cfdca026a Port edit tools field API test to Playwright
Refs #2779
2026-06-14 16:48:32 -07:00
Simon Willison
b5fa485a9f Port datasette manager plugin test to Playwright
Refs #2779
2026-06-14 16:45:48 -07:00
Simon Willison
6bbd33d81d Port navigation jump sections to Playwright
Refs #2779
2026-06-14 16:44:59 -07:00
Simon Willison
047b69e87f Port navigation search recents to Playwright
Refs #2779
2026-06-14 16:44:17 -07:00
Simon Willison
6cd65cf4fb Initial Playwright setup plus first test
Refs #2779
2026-06-14 16:39:55 -07:00
Simon Willison
bba7e0b027 Better docs for makeJumpSections()
Closes #2778
2026-06-14 16:28:09 -07:00
Simon Willison
f1af216852
Insert/edit/delete UI in Datasette core, plus makeColumnField() plugin hook
PR #2781

- A new `/db/table/-/autocomplete?q=term` JSON API for fast autocomplete search against foreign key tables - it searches against their label column or their primary key and switches to just a prefix search against the first primary key (for speed) if the label column check takes more than 500ms. A new `/-/debug/autocomplete` page lets you try this out.
- A `<datasette-autocomplete>` Web Component that uses that API.
- Table pages now get an insert button above the table, and little edit and delete icons next to each row. All three trigger custom modal dialogs. The edit/insert dialog is a full form - the delete one is just confirmation.
- A new `/<database>/<table>/-/fragment?_row=` endpoint which returns a rendered fragment of HTML for the specified row. This is used by the insert/edit code to partially update the table to reflect those changes. Uses a new `data-row="{{ row.row_path }}"` attribute on the `<tr>` to enable the replacement.
- A new default column type called `textarea` which users can use to specify a multi-line textarea for a column
- A new JavaScript plugin hook, [makeColumnField()](3f7d389caf/docs/javascript_plugins.rst (makecolumnfieldcontext)), which plugins can use to add custom form fields to the edit form. Datasette [uses this itself](3f7d389caf/datasette/static/table.js (L1181-L1209)) for the JSON field to add client-side JSON validation. I iterated a *lot* on this one, including spinning up a `datasette-prosemirror` plugin and a branch of `datasette-files` to fully exercise it.

Closes #2780

Video demo: https://github.com/user-attachments/assets/2c18b8a4-975f-4c7b-9573-ec6040fe8223
2026-06-14 16:14:14 -07:00
Simon Willison
f157df7f07 Ran prettier 2026-06-14 16:06:36 -07:00
Simon Willison
82c95a1a13 Refactor edit/delete tools to work on row pages too
Refs https://github.com/simonw/datasette/pull/2781#issuecomment-4703303274

Refs #2780
2026-06-14 16:05:42 -07:00
Simon Willison
4ce2888e79 Support for <button> items in action menus
Closes #2782

Animated demo: https://github.com/simonw/datasette/pull/2781#issuecomment-4703303274
2026-06-14 15:58:37 -07:00
Simon Willison
3f7d389caf Refine column field plugin API and documentation
- Simplify JavaScript column field context:
  - expose `isPk` instead of `isPrimaryKey`
  - expose `defaultExpression` instead of separate SQLite default flags
  - remove value/default state from plugin context
- Update field helper behavior:
  - `setValue()` no longer dispatches input/change events
  - remove dispatch options and `resetValue()`
  - add `markClean()` for plugin-normalized initial values
  - track clean field state for reliable dirty detection

Also:

- Prompt before closing row insert/edit dialogs when there are unsaved changes
- Map declared SQLite types to affinities, returning `BLOB` for typeless columns and `NUMERIC` for numeric/date/boolean-like declarations
2026-06-14 15:09:24 -07:00
Simon Willison
c083e44561 Ignore .playwright-mcp
Codex Desktop likes using this folder.
2026-06-14 14:21:04 -07:00
Simon Willison
841a2536ea Tighten row edit field plugin API
Replace the value/valueType/originalValue/originalValueType fields on makeColumnField() contexts with an explicit field object API for reading, writing, resetting, comparing and validating field values.

Normalize columnType to {type, config}, rename the SQLite default metadata so it is clearly SQLite-specific, and document that plugins submit only string, number, boolean or null values. Plugins that need structured data should serialize it themselves instead of relying on Datasette to special-case JSON.

Move the built-in json column type behavior onto the same plugin API used by external plugins: validate the textarea with field.setValidity() as the value changes, but submit plain text. Harden row edit value comparison so fixing invalid JSON in an existing row is not blocked by the original invalid value.

Update the JavaScript plugin documentation and Node-based tests for the revised field contract.
2026-06-14 13:58:55 -07:00
Simon Willison
b2de8b5d2e First draft of makeColumnField() plugin hook 2026-06-14 11:57:13 -07:00
Simon Willison
c405b56223 Tweak modal color scheme to be more Datasette 2026-06-14 11:56:51 -07:00
Simon Willison
35d7e3cab8 Fixed some tests for the new autocomplete work 2026-06-14 08:03:28 -07:00
Simon Willison
574290fb23 Add foreign key autocomplete to row forms
Expose single-primary-key foreign key autocomplete URLs in table page metadata and load the autocomplete component when needed.

Enhance insert and edit dialogs to wrap foreign-key inputs with the autocomplete web component, show linked selected-row labels, reserve metadata space, and keep the dropdown as a fixed overlay above modal chrome.

Add an explicit _initial=1 autocomplete mode for empty-field starter suggestions while keeping blank q responses empty by default, with tests for the endpoint and table metadata.
2026-06-14 07:30:34 -07:00