simonw / datasette-edit-schema

Datasette plugin for modifying table schemas
Apache License 2.0
16 stars 0 forks source link

Ability to create a new table #5

Closed simonw closed 1 year ago

simonw commented 4 years ago

This feature will be much more interesting when accompanied by some plugin that supports inserting data into tables.

simonw commented 4 years ago

Some unfinished code I just removed while working on #8:

async def post(self, request):
    formdata = await request.form()
    database_name = request.url_vars["database"]
    columns = [
        c.split(".", 1)[1] for c in formdata.keys() if c.startswith("column.")
    ]
    table = formdata["table"]
    # TODO: Create table
    raise NotImplementedError
simonw commented 1 year ago

I'm going to force the user to have a primary key in their table - it will default to id integer primary key but they can change it to a text if they want to (and change the name).

Should I let users have a compound primary key? I think not - if they really want that they can use a create table statement directly, but it feels too confusing to explain to users who are using a visual table builder.

simonw commented 1 year ago

This feature will be much more interesting when accompanied by some plugin that supports inserting data into tables.

Well that exists now! https://github.com/datasette/datasette-write-ui

simonw commented 1 year ago

The UI can look like this:

CleanShot 2023-08-17 at 23 18 59@2x

So the primary key column is always at the top and can't be dragged around or deleted, but can have its name and type changed (probably limit type to integer or text though, float feels weird - blob could be OK but I'd rather not go there yet.)

simonw commented 1 year ago

Actually no need for delete buttons that are checkboxes, they can be real buttons that JavaScript remove that row from the page.

And there needs to be a prominent "add column" button that adds a new row.

simonw commented 1 year ago

The "table name" form field should fetch() check for tables with the same name and display an error + prevent you from submitting if your table matches an existing table.

simonw commented 1 year ago

I won't bother with "add another column" just yet, I'll provide ten and people can add more using the edit table screen later if they need to.

simonw commented 1 year ago

Demo:

create-demo