optimize command now accepts optional tables, refs #155

This commit is contained in:
Simon Willison 2020-09-08 15:34:55 -07:00
commit 76548596a6
3 changed files with 13 additions and 5 deletions

View file

@ -218,11 +218,13 @@ def vacuum(path):
type=click.Path(exists=True, file_okay=True, dir_okay=False, allow_dash=False),
required=True,
)
@click.argument("tables", nargs=-1)
@click.option("--no-vacuum", help="Don't run VACUUM", default=False, is_flag=True)
def optimize(path, no_vacuum):
def optimize(path, tables, no_vacuum):
"""Optimize all FTS tables and then run VACUUM - should shrink the database file"""
db = sqlite_utils.Database(path)
tables = db.table_names(fts4=True) + db.table_names(fts5=True)
if not tables:
tables = db.table_names(fts4=True) + db.table_names(fts5=True)
with db.conn:
for table in tables:
db[table].optimize()