db.schema and 'sqlite-utils schema' command, closes #268

This commit is contained in:
Simon Willison 2021-06-11 13:51:49 -07:00
commit 0d2e4f49f3
6 changed files with 90 additions and 2 deletions

View file

@ -1916,6 +1916,33 @@ def test_triggers(tmpdir, extra_args, expected):
assert result.output == expected
def test_schema(tmpdir):
db_path = str(tmpdir / "test.db")
db = Database(db_path)
db["dogs"].create({"id": int, "name": str})
db["chickens"].create({"id": int, "name": str, "breed": str})
db["chickens"].create_index(["breed"])
result = CliRunner().invoke(
cli.cli,
["schema", db_path],
catch_exceptions=False,
)
assert result.exit_code == 0
assert result.output == (
"CREATE TABLE [dogs] (\n"
" [id] INTEGER,\n"
" [name] TEXT\n"
");\n"
"CREATE TABLE [chickens] (\n"
" [id] INTEGER,\n"
" [name] TEXT,\n"
" [breed] TEXT\n"
");\n"
"CREATE INDEX [idx_chickens_breed]\n"
" ON [chickens] ([breed]);\n"
)
def test_long_csv_column_value(tmpdir):
db_path = str(tmpdir / "test.db")
csv_path = str(tmpdir / "test.csv")