Skip to content

Commit

Permalink
Improve cli for checkdb
Browse files Browse the repository at this point in the history
  • Loading branch information
hellais committed Sep 11, 2024
1 parent 567396c commit 2a23d20
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions oonipipeline/src/oonipipeline/cli/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,23 +255,36 @@ def startworkers():
is_flag=True,
help="should we drop tables before creating them",
)
@click.option(
"--print-create",
is_flag=True,
default=True,
help="should we drop tables before creating them",
)
@click.option(
"--print-diff",
is_flag=True,
help="should we drop tables before creating them",
)
def checkdb(
create_tables: bool,
drop_tables: bool,
create_tables: bool, drop_tables: bool, print_create: bool, print_diff: bool
):
"""
Check if the database tables require migrations. If the create-tables flag
is not specified, it will not perform any operations.
"""
for query, table_name in make_create_queries():
click.echo(f"## Create for {table_name}")
click.echo(query)

maybe_create_delete_tables(
clickhouse_url=config.clickhouse_url,
create_tables=create_tables,
drop_tables=drop_tables,
)

with ClickhouseConnection(config.clickhouse_url) as db:
list_all_table_diffs(db)
if print_create:
for query, table_name in make_create_queries():
click.echo(f"## Create for {table_name}")
click.echo(query)

if create_tables or drop_tables:
maybe_create_delete_tables(
clickhouse_url=config.clickhouse_url,
create_tables=create_tables,
drop_tables=drop_tables,
)

if print_diff:
with ClickhouseConnection(config.clickhouse_url) as db:
list_all_table_diffs(db)

0 comments on commit 2a23d20

Please sign in to comment.