Sample: Change Projects
In this example, source data sources and workbooks in a project named Test
are migrated to the destination's Production
project.
Both the C# and Python mapping classes inherit from a base class that handles most of the work, and then create an IWorkbook
and IDataSource
version.
Mapping Class
from typing import TypeVar
from tableau_migration import(
IWorkbook,
IDataSource,
ContentMappingContext,
ContentMappingBase)
T = TypeVar("T")
class ChangeProjectMapping(ContentMappingBase[T]):
def map(self, ctx: ContentMappingContext[T]) -> ContentMappingContext[T]:
# Get the container (project) location for the content item.
container_location = ctx.content_item.location.parent()
# We only want to map content items whose project name is "Test".
if not container_location.name.casefold() == "Test".casefold():
return ctx
# Build the new project location.
new_container_location = container_location.rename("Production")
# Build the new content item location.
new_location = new_container_location.append(ctx.content_item.name)
# Map the new content item location.
ctx = ctx.map_to(new_location)
return ctx
# Create the workbook version of the templated ChangeProjectMapping class
class ChangeProjectMappingForWorkbooks(ChangeProjectMapping[IWorkbook]):
pass
# Create the datasource version of the templated ChangeProjectMapping class
class ChangeProjectMappingForDataSources(ChangeProjectMapping[IDataSource]):
pass
Registration
plan_builder.mappings.add(ChangeProjectMappingForWorkbooks)
plan_builder.mappings.add(ChangeProjectMappingForDataSources)
See hook registration for more details.