mirror of https://github.com/apache/superset.git
Use multi-value parameter
This commit is contained in:
parent
a26b23e331
commit
98cb635741
|
@ -96,16 +96,18 @@ def migrate_viz() -> None:
|
||||||
type=str,
|
type=str,
|
||||||
)
|
)
|
||||||
@optgroup.option(
|
@optgroup.option(
|
||||||
"--ids",
|
"--id",
|
||||||
help="A comma separated list of chart IDs to upgrade",
|
"ids",
|
||||||
type=str,
|
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:
|
||||||
"""Upgrade a viz to the latest version."""
|
"""Upgrade a viz to the latest version."""
|
||||||
if ids is None:
|
if ids is None:
|
||||||
migrate_by_viz_type(VizType(viz_type))
|
migrate_by_viz_type(VizType(viz_type))
|
||||||
else:
|
else:
|
||||||
migrate_by_ids(ids)
|
migrate_by_id(ids)
|
||||||
|
|
||||||
|
|
||||||
@migrate_viz.command()
|
@migrate_viz.command()
|
||||||
|
@ -120,16 +122,18 @@ def upgrade(viz_type: str, ids: str | None = None) -> None:
|
||||||
type=str,
|
type=str,
|
||||||
)
|
)
|
||||||
@optgroup.option(
|
@optgroup.option(
|
||||||
"--ids",
|
"--id",
|
||||||
help="A comma separated list of chart IDs to downgrade",
|
"ids",
|
||||||
type=str,
|
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:
|
||||||
"""Downgrade a viz to the previous version."""
|
"""Downgrade a viz to the previous version."""
|
||||||
if ids is None:
|
if ids is None:
|
||||||
migrate_by_viz_type(VizType(viz_type), is_downgrade=True)
|
migrate_by_viz_type(VizType(viz_type), is_downgrade=True)
|
||||||
else:
|
else:
|
||||||
migrate_by_ids(ids, is_downgrade=True)
|
migrate_by_id(ids, is_downgrade=True)
|
||||||
|
|
||||||
|
|
||||||
def migrate_by_viz_type(viz_type: VizType, is_downgrade: bool = False) -> None:
|
def migrate_by_viz_type(viz_type: VizType, is_downgrade: bool = False) -> None:
|
||||||
|
@ -146,15 +150,14 @@ def migrate_by_viz_type(viz_type: VizType, is_downgrade: bool = False) -> None:
|
||||||
migration.upgrade(db.session)
|
migration.upgrade(db.session)
|
||||||
|
|
||||||
|
|
||||||
def migrate_by_ids(ids: str, is_downgrade: bool = False) -> None:
|
def migrate_by_id(ids: tuple[int, ...], is_downgrade: bool = False) -> None:
|
||||||
"""
|
"""
|
||||||
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.
|
: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_(ids))
|
||||||
slices = db.session.query(Slice).filter(Slice.id.in_(id_list))
|
|
||||||
for slc in paginated_update(
|
for slc in paginated_update(
|
||||||
slices,
|
slices,
|
||||||
lambda current, total: print(
|
lambda current, total: print(
|
||||||
|
@ -163,5 +166,5 @@ def migrate_by_ids(ids: str, is_downgrade: bool = False) -> None:
|
||||||
):
|
):
|
||||||
if is_downgrade:
|
if is_downgrade:
|
||||||
PREVIOUS_VERSION[slc.viz_type].downgrade_slice(slc)
|
PREVIOUS_VERSION[slc.viz_type].downgrade_slice(slc)
|
||||||
else:
|
elif slc.viz_type in MIGRATIONS:
|
||||||
MIGRATIONS[slc.viz_type].upgrade_slice(slc)
|
MIGRATIONS[slc.viz_type].upgrade_slice(slc)
|
||||||
|
|
Loading…
Reference in New Issue