Skip to content

Commit

Permalink
Fix bug with schema not correcctly shown, closes #49
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Jan 29, 2024
1 parent 974c803 commit df11fae
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
5 changes: 3 additions & 2 deletions datasette_edit_schema/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,11 @@ def get_columns_and_schema_and_fks_and_pks_and_indexes(conn):
textwrap.dedent(
"""
select group_concat(sql, ';
') from sqlite_master where tbl_name = 'Orders'
') from sqlite_master where tbl_name = ?
order by type desc
"""
)
),
[table],
).fetchone()[0]
return columns, schema, t.foreign_keys, t.pks, t.indexes

Expand Down
22 changes: 22 additions & 0 deletions tests/test_edit_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,28 @@ async def test_permission_alter_table(permission_plugin, ds, rules_allow, should
assert response.status_code == 302


@pytest.mark.asyncio
async def test_table_form_contains_schema(permission_plugin, ds):
ds._rules_allow = [
Rule(
actor_id="user",
action="edit-schema",
database="data",
resource=None,
),
]
response = await ds.client.get(
"/-/edit-schema/data/creatures",
cookies={"ds_actor": ds.sign({"a": {"id": "user"}}, "actor")},
)
assert response.status_code == 200
assert (
"CREATE TABLE [creatures]" in response.text
# In case we remove '[' in the future:
or "CREATE TABLE creatures" in response.text
)


@pytest.mark.asyncio
@pytest.mark.parametrize(
"new_name,should_work,expected_message",
Expand Down

0 comments on commit df11fae

Please sign in to comment.