Skip to content

Add --ignore option to more commands #450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
simonw opened this issue Jul 2, 2022 · 9 comments
Closed

Add --ignore option to more commands #450

simonw opened this issue Jul 2, 2022 · 9 comments
Labels
enhancement New feature or request

Comments

@simonw simonw added the enhancement New feature or request label Jul 2, 2022
@simonw
Copy link
Owner Author

simonw commented Jul 15, 2022

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 exists
  • create-table: If table already exists, do nothing
  • add-foreign-key: If foreign key already exists, do nothing
  • drop-table: description is missing
  • create-view: If view already exists, do nothing
  • drop-view: description is missing

And create-index has:

  • --if-not-exists: Ignore if index already exists

@simonw
Copy link
Owner Author

simonw commented Jul 15, 2022

Commands 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)

Sorry, something went wrong.

@simonw
Copy link
Owner Author

simonw commented Jul 15, 2022

For enable-fts I should use --replace instead, since that matches how the Python API works:

def enable_fts(
self,
columns: Iterable[str],
fts_version: str = "FTS5",
create_triggers: bool = False,
tokenize: Optional[str] = None,
replace: bool = False,
):
"""
Enable SQLite full-text search against the specified columns.
See :ref:`python_api_fts` for more details.
:param columns: List of column names to include in the search index.
:param fts_version: FTS version to use - defaults to ``FTS5`` but you may want ``FTS4`` for older SQLite versions.
:param create_triggers: Should triggers be created to keep the search index up-to-date? Defaults to ``False``.
:param tokenize: Custom SQLite tokenizer to use, for example ``"porter"`` to enable Porter stemming.
:param replace: Should any existing FTS index for this table be replaced by the new one?
"""

@simonw
Copy link
Owner Author

simonw commented Jul 15, 2022

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

simonw added a commit that referenced this issue Jul 15, 2022
Also fixed up some sqlite3.OperationalError imports.
@simonw
Copy link
Owner Author

simonw commented Jul 15, 2022

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
Copy link
Owner Author

simonw commented Jul 15, 2022

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
Copy link
Owner Author

simonw commented Jul 15, 2022

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

simonw added a commit that referenced this issue Jul 15, 2022
@simonw
Copy link
Owner Author

simonw commented Jul 15, 2022

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

@simonw simonw closed this as completed Jul 15, 2022
@simonw
Copy link
Owner Author

simonw commented Jul 15, 2022

Here are all of the changes I made in this issue: e10536c...b9a89a0

simonw added a commit that referenced this issue Jul 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant