Skip to content

Commit

Permalink
Use multi-value parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-s-molina committed Jun 26, 2024
1 parent 2b2dce7 commit 0eb50d8
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions superset/cli/viz_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,18 @@ def migrate_viz() -> None:
type=str,
)
@optgroup.option(

Check warning on line 101 in superset/cli/viz_migrations.py

View check run for this annotation

Codecov / codecov/patch

superset/cli/viz_migrations.py#L101

Added line #L101 was not covered by tests
"--ids",
help="A comma separated list of chart IDs to upgrade",
type=str,
"--id",
"ids",
help="The chart ID to upgrade. It can set set multiple times.",
type=int,
multiple=True,
)
def upgrade(viz_type: str, ids: str | None = None) -> None:
def upgrade(viz_type: str, ids: tuple[int, ...] | None = None) -> None:

Check warning on line 108 in superset/cli/viz_migrations.py

View check run for this annotation

Codecov / codecov/patch

superset/cli/viz_migrations.py#L108

Added line #L108 was not covered by tests
"""Upgrade a viz to the latest version."""
if ids is None:
migrate_by_viz_type(VizType(viz_type))

Check warning on line 111 in superset/cli/viz_migrations.py

View check run for this annotation

Codecov / codecov/patch

superset/cli/viz_migrations.py#L110-L111

Added lines #L110 - L111 were not covered by tests
else:
migrate_by_ids(ids)
migrate_by_id(ids)

Check warning on line 113 in superset/cli/viz_migrations.py

View check run for this annotation

Codecov / codecov/patch

superset/cli/viz_migrations.py#L113

Added line #L113 was not covered by tests


@migrate_viz.command()
Expand All @@ -123,16 +125,18 @@ def upgrade(viz_type: str, ids: str | None = None) -> None:
type=str,
)
@optgroup.option(

Check warning on line 127 in superset/cli/viz_migrations.py

View check run for this annotation

Codecov / codecov/patch

superset/cli/viz_migrations.py#L127

Added line #L127 was not covered by tests
"--ids",
help="A comma separated list of chart IDs to downgrade",
type=str,
"--id",
"ids",
help="The chart ID to downgrade. It can set set multiple times.",
type=int,
multiple=True,
)
def downgrade(viz_type: str, ids: str | None = None) -> None:
def downgrade(viz_type: str, ids: tuple[int, ...] | None = None) -> None:

Check warning on line 134 in superset/cli/viz_migrations.py

View check run for this annotation

Codecov / codecov/patch

superset/cli/viz_migrations.py#L134

Added line #L134 was not covered by tests
"""Downgrade a viz to the previous version."""
if ids is None:
migrate_by_viz_type(VizType(viz_type), is_downgrade=True)

Check warning on line 137 in superset/cli/viz_migrations.py

View check run for this annotation

Codecov / codecov/patch

superset/cli/viz_migrations.py#L136-L137

Added lines #L136 - L137 were not covered by tests
else:
migrate_by_ids(ids, is_downgrade=True)
migrate_by_id(ids, is_downgrade=True)

Check warning on line 139 in superset/cli/viz_migrations.py

View check run for this annotation

Codecov / codecov/patch

superset/cli/viz_migrations.py#L139

Added line #L139 was not covered by tests


def migrate_by_viz_type(viz_type: VizType, is_downgrade: bool = False) -> None:

Check warning on line 142 in superset/cli/viz_migrations.py

View check run for this annotation

Codecov / codecov/patch

superset/cli/viz_migrations.py#L142

Added line #L142 was not covered by tests
Expand All @@ -149,15 +153,14 @@ def migrate_by_viz_type(viz_type: VizType, is_downgrade: bool = False) -> None:
migration.upgrade(db.session)

Check warning on line 153 in superset/cli/viz_migrations.py

View check run for this annotation

Codecov / codecov/patch

superset/cli/viz_migrations.py#L153

Added line #L153 was not covered by tests


def migrate_by_ids(ids: str, is_downgrade: bool = False) -> None:
def migrate_by_id(ids: tuple[int, ...], is_downgrade: bool = False) -> None:

Check warning on line 156 in superset/cli/viz_migrations.py

View check run for this annotation

Codecov / codecov/patch

superset/cli/viz_migrations.py#L156

Added line #L156 was not covered by tests
"""
Migrate a subset of charts by a list of IDs.
Migrate a subset of charts by IDs.
:param ids: List of chart IDs to migrate
:param id: Tuple of chart IDs to migrate
:param is_downgrade: Whether to downgrade the charts. Default is upgrade.
"""
id_list = [int(i) for i in ids.split(",")]
slices = db.session.query(Slice).filter(Slice.id.in_(id_list))
slices = db.session.query(Slice).filter(Slice.id.in_(ids))
for slc in paginated_update(

Check warning on line 164 in superset/cli/viz_migrations.py

View check run for this annotation

Codecov / codecov/patch

superset/cli/viz_migrations.py#L163-L164

Added lines #L163 - L164 were not covered by tests
slices,
lambda current, total: print(
Expand All @@ -166,5 +169,5 @@ def migrate_by_ids(ids: str, is_downgrade: bool = False) -> None:
):
if is_downgrade:
PREVIOUS_VERSION[slc.viz_type].downgrade_slice(slc)
else:
elif slc.viz_type in MIGRATIONS:
MIGRATIONS[slc.viz_type].upgrade_slice(slc)

Check warning on line 173 in superset/cli/viz_migrations.py

View check run for this annotation

Codecov / codecov/patch

superset/cli/viz_migrations.py#L170-L173

Added lines #L170 - L173 were not covered by tests

0 comments on commit 0eb50d8

Please sign in to comment.