simonw / sqlite-utils

Python CLI utility and library for manipulating SQLite databases
https://sqlite-utils.datasette.io
Apache License 2.0
1.68k stars 112 forks source link

Add --ignore option to more commands #450

Closed simonw closed 2 years ago

simonw commented 2 years ago

As seen in https://sqlite-utils.datasette.io/en/stable/cli-reference.html#add-foreign-key

Could make this TIL trick unnecessary: https://til.simonwillison.net/bash/ignore-errors

simonw commented 2 years ago

From https://sqlite-utils.datasette.io/en/latest/cli-reference.html

Commands that currently have an --ignore flag, and their descriptions:

And create-index has:

simonw commented 2 years ago

Commands that could have --ignore added to them:

simonw commented 2 years ago

For enable-fts I should use --replace instead, since that matches how the Python API works: https://github.com/simonw/sqlite-utils/blob/9dd4cf891d9f4565019e030ddc712507ac87b998/sqlite_utils/db.py#L2088-L2106

simonw commented 2 years ago

disable-fts already fails silently if the table doesn't have FTS setup.

simonw commented 2 years ago

create-spatial-index is tricky. For consistency with create-index it should really use --if-not-exists - but under the hood it's not using IF NOT EXISTS because those indexes are created using select CreateSpatialIndex(...).

Really this highlights that --if-not-exists is a bad name for that option on create-index.

I'm tempted to add --ignore to create-index and mark --if-not-exists as deprecated - though it will still work because I don't want to release a major version bump.

simonw commented 2 years ago

I can do this for --create-index instead:

Options:
  --name TEXT                Explicit name for the new index
  --unique                   Make this a unique index
  --if-not-exists, --ignore  Ignore if index already exists
  --analyze                  Run ANALYZE after creating the index
  --load-extension TEXT      SQLite extensions to load
  -h, --help                 Show this message and exit.

That supports both names for the option.

simonw commented 2 years ago

add-foreign-keys is enough of a power-feature that I'm happy not to add this there.

simonw commented 2 years ago

I'm going to skip add-geometry-column and create-spatial-index as well.

simonw commented 2 years ago

Here are all of the changes I made in this issue: https://github.com/simonw/sqlite-utils/compare/e10536c7f59abbb785f092bf83c4ab94c00e31a3...b9a89a0f2c3559989efe65f25a6e1f8fa76fe8b0