Closed simonw closed 2 years ago
From https://sqlite-utils.datasette.io/en/latest/cli-reference.html
Commands that currently have an --ignore
flag, and their descriptions:
insert
: Ignore records if pk already existscreate-table
: If table already exists, do nothingadd-foreign-key
: If foreign key already exists, do nothingdrop-table
: description is missingcreate-view
: If view already exists, do nothingdrop-view
: description is missingAnd create-index
has:
--if-not-exists
: Ignore if index already existsCommands that could have --ignore
added to them:
enable-fts
disable-fts
(not doing)add-column
add-foreign-keys
(decided not to do this)duplicate
add-geometry-column
(decided not to do this)create-spatial-index
(decided not to do this)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
disable-fts
already fails silently if the table doesn't have FTS setup.
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.
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.
add-foreign-keys
is enough of a power-feature that I'm happy not to add this there.
I'm going to skip add-geometry-column
and create-spatial-index
as well.
Here are all of the changes I made in this issue: https://github.com/simonw/sqlite-utils/compare/e10536c7f59abbb785f092bf83c4ab94c00e31a3...b9a89a0f2c3559989efe65f25a6e1f8fa76fe8b0
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