mirror of
https://github.com/simonw/datasette.git
synced 2026-07-16 20:44:35 +02:00
- 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
29 lines
869 B
Python
29 lines
869 B
Python
from datasette import hookimpl
|
|
from datasette.resources import TableResource
|
|
|
|
|
|
@hookimpl
|
|
def table_actions(datasette, actor, database, table, request):
|
|
async def inner():
|
|
db = datasette.get_database(database)
|
|
if not db.is_mutable:
|
|
return []
|
|
if not await datasette.allowed(
|
|
action="alter-table",
|
|
resource=TableResource(database=database, table=table),
|
|
actor=actor,
|
|
):
|
|
return []
|
|
return [
|
|
{
|
|
"type": "button",
|
|
"label": "Alter table",
|
|
"description": "Change columns and primary key for this table.",
|
|
"attrs": {
|
|
"aria-label": "Alter table {}".format(table),
|
|
"data-table-action": "alter-table",
|
|
},
|
|
}
|
|
]
|
|
|
|
return inner
|