Skip to main content

Datasette plugin for modifying table schemas

Project description

datasette-edit-schema

PyPI Changelog Tests License

Datasette plugin for modifying table schemas

:warning: The latest alpha release depends on Datasette 1.09a. Use version 0.7.1 with older releases of Datasette.

Features

  • Add new columns to a table
  • Rename columns in a table
  • Modify the type of columns in a table
  • Re-order the columns in a table
  • Rename a table
  • Delete a table
  • Change the primary key of a table to another column containing unique values
  • Update the foreign key constraints on a table
  • Add an index (or unique index) to a column on a table
  • Drop an index from a table

Installation

Install this plugin in the same environment as Datasette.

pip install datasette-edit-schema

Usage

Navigate to /-/edit-schema/dbname/tablename on your Datasette instance to edit a specific table.

Use /-/edit-schema/dbname to create a new table in a specific database.

By default only the root actor can access the page - so you'll need to run Datasette with the --root option and click on the link shown in the terminal to sign in and access the page.

Permissions

The edit-schema permission provides access to all functionality.

You can use permission plugins such as datasette-permissions-sql to grant additional access to the write interface.

These permission checks will call the permission_allowed() plugin hook with three arguments:

  • action will be the string "edit-schema"
  • actor will be the currently authenticated actor - usually a dictionary
  • resource will be the string name of the database

You can instead use more finely-grained permissions from the default Datasette permissions collection:

  • create-table allows users to create a new table. The resource will be the name of the database.
  • drop-table allows users to drop a table. The resource will be a tuple of (database_name, table_name).
  • alter-table allows users to alter a table. The resource will be a tuple of (database_name, table_name).

To rename a table a user must have both drop-table permission for that table and create-table permission for that database.

For example, to configure Datasette to allow the user with ID pelican to create, alter and drop tables in the marketing database and to alter just the notes table in the sales database, you could use the following configuration:

databases:
  marketing:
    permissions:
      create-table:
        id: pelican
      drop-table:
        id: pelican
      alter-table:
        id: pelican
  sales:
    tables:
      notes:
        permissions:
          alter-table:
            id: pelican

Events

This plugin fires create-table, alter-table and drop-table events when tables are modified, using the Datasette Events system introduced in Datasette 1.0a8.

Screenshot

datasette-edit-schema interface

Development

To set up this plugin locally, first checkout the code. Then create a new virtual environment:

cd datasette-edit-schema
python3 -mvenv venv
source venv/bin/activate

Or if you are using pipenv:

pipenv shell

Now install the dependencies and tests:

pip install -e '.[test]'

To run the tests:

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_edit_schema-0.8a2.tar.gz (71.2 kB view details)

Uploaded Source

Built Distribution

datasette_edit_schema-0.8a2-py3-none-any.whl (67.0 kB view details)

Uploaded Python 3

File details

Details for the file datasette_edit_schema-0.8a2.tar.gz.

File metadata

  • Download URL: datasette_edit_schema-0.8a2.tar.gz
  • Upload date:
  • Size: 71.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for datasette_edit_schema-0.8a2.tar.gz
Algorithm Hash digest
SHA256 e3a0b964bdbc90618503c650193539b6da864a71c2f878e93158c62a77ecd4cf
MD5 54736eb2f134987eee1fbb61fb437f8d
BLAKE2b-256 21e1b9096e1712f8f2d51d69d42711acea5314139b9ebaac0c35e0106c344d42

See more details on using hashes here.

Provenance

File details

Details for the file datasette_edit_schema-0.8a2-py3-none-any.whl.

File metadata

File hashes

Hashes for datasette_edit_schema-0.8a2-py3-none-any.whl
Algorithm Hash digest
SHA256 6ee222a2a3710365215f383f35625071605d01147d1a62e978fc3b757c727084
MD5 9c1e1e69770f6acb561c1e5734de3087
BLAKE2b-256 be4794ed5705f8e7d9af97468a9b79ba1b3ad8ec7bad493bf06dd40bcd618b67

See more details on using hashes here.

Provenance

Supported by

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