Generated banner for Synapse Migration
Generated logo for Synapse Migration

Synapse Migration

MicrosoftOfficialPublished by Microsoft

  • Skill
  • Workflow
  • Software development
  • MIT
  • Low risk
  • Has scripts

From the author

Converts Synapse workspaces to Fabric: Spark items, Lake Databases, Linked Services, and Dedicated SQL Pool schema/procedures for Lakehouse or Warehouse. During Pool-to-Lakehouse migration only, can migrate approved dependent procedure callers after notebook readiness. Excludes standalone pipelines and Warehouse administration. Triggers: Synapse workspace to Fabric, Dedicated SQL Pool to Lakehouse, Dedicated SQL Pool to Fabric Warehouse.
— the description by Microsoft

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

The synapse-migration skill provides a structured, phased workflow for transitioning Synapse Analytics workspaces to Microsoft Fabric. It covers the migration of Spark items, Lake Databases, Linked Services, and Dedicated SQL Pool schema and stored procedures. The skill emphasizes a dependency-ordered approach, requiring gap assessment and explicit approval before conversion. It distinguishes between migrating to a Fabric Lakehouse (schema and code only, no data movement) and a Fabric Warehouse, while providing specific routing for dependent pipeline callers.

What it does

  • Discovers and classifies Synapse workspace artifacts.
  • Converts Dedicated SQL Pool schema and stored procedures to Spark SQL notebooks or Warehouse objects.
  • Migrates Spark items, including notebooks and Spark Job Definitions, to Fabric equivalents.
  • Maps Linked Services to Fabric Data Connections or OneLake Shortcuts.
  • Manages the migration of approved dependent pipeline callers.
  • Validates persisted definitions and artifacts against established contracts.

When to use it

  • When migrating a full Synapse workspace to Microsoft Fabric.
  • When converting Dedicated SQL Pool schema and procedures to a Lakehouse or Warehouse.
  • When porting Spark pools, notebooks, or Spark Job Definitions to Fabric.
  • When replacing Synapse Linked Services with Fabric-native connectivity.

Advantages

  • Ensures dependency-ordered migration to maintain system integrity.
  • Provides clear routing for different workload types (Lakehouse vs. Warehouse).
  • Enforces strict validation and approval gates for behavior-changing decisions.
  • Supports incremental migration rather than high-risk big-bang cutovers.
  • Standardizes the conversion of T-SQL procedures to executable Spark SQL notebooks.

Usage examples

“Migrate this Dedicated SQL Pool DACPAC to a Fabric Lakehouse and convert the procedures.”
The agent will assess gaps, obtain approval for procedure-to-notebook mappings, create a migration manifest, convert schema/code artifacts, and validate the results.
“Migrate this Dedicated SQL Pool to Fabric Warehouse.”
The agent will assess DDL compatibility, remove unsupported distribution/index declarations, obtain provisioning consent, and prepare for potential data migration.

Install

  1. Download the skill as a ZIP:

    https://autogineer.com/agent-skills/microsoft/synapse-migration/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip synapse-migration.zip -d .agents/skills

Documentation by Microsoft

Telemetry — MANDATORY. Every api.fabric.microsoft.com call must carry x-ms-fabric-skill: synapse-migration (az rest: --headers "x-ms-fabric-skill=synapse-migration"), including every LRO poll, fabric_lro and retry. Snippets omit it — add it anyway.

OFFLINE LAKEHOUSE ARTIFACT FAST PATH — DECIDE FIRST. For a no-live-call request with complete supplied inputs and contracts, load only the fast path; do not load migration-planning-reference.md, dedicated-pool-conversion.md, or implementation scripts. Use one generator for artifacts and final-byte hashes, then one verifier. Do not inspect generated files or run post-pass spot checks. For every optional non-null source default, set missingValueBehavior to UseSourceDefault and restore that default before validation. Do not use this path for a Warehouse target; incomplete and large-procedure requests use their own routes.

CRITICAL NOTES

  1. To find workspace details (including its ID) from a workspace name: list all workspaces, then use JMESPath filtering.

  2. To find item details (including its ID) from workspace ID, item type, and item name: list all items of that type in that workspace, then use JMESPath filtering.

  3. Treat a source Dedicated SQL Pool as read-only. Do not run source DDL, DML, stored procedures, or create sample objects.

  4. Dedicated Pool-to-Lakehouse data movement is out of scope. Migrate schema and executable code artifacts only; do not copy source rows or run row-level/business-result equivalence queries. The separate Warehouse route may move data only from a separately approved restored export copy under its own consent gate and restored-source contract.

  5. For Dedicated Pool-to-Lakehouse requests, complete gap assessment, explicit mapping approval, manifest creation, conversion, deployment, and validation in order. Read dedicated-pool-to-lakehouse.md once as the router, then load only the current phase reference.

  6. Stored-procedure 1:1, N:1, and N:N mappings never apply to views. Views remain schema objects; procedures become traceable Spark SQL notebooks with executable %%sql transformation cells.

  7. Dependent ADF/Synapse callers are conditional scope, not automatic scope. Discover them during assessment, require a separate complete-closure approval, and migrate them only after notebook readiness. Route standalone pipeline requests to pipeline-migration.

  8. Before executing a specialized Dedicated Pool workflow, read the matching contract in dedicated-pool-execution-contracts.md. Its validation, hashing, request-body, resume, and completion-language requirements are mandatory.

  9. Keep Lakehouse and Warehouse paths separate. If the target is unclear, ask before loading path-specific resources. Lakehouse conversion never moves source rows; Warehouse data migration requires its own explicit consent gate and restored-source contract.

  10. For a Fabric Warehouse target, explicitly state that the complete DISTRIBUTION and CLUSTERED COLUMNSTORE INDEX declarations are removed because Fabric manages distribution, storage, and indexing; a bare mention of either source clause is insufficient.

  11. Run setup DDL and CETAS only against the separately approved restored export copy after proving it is not the original production source.

Synapse Analytics to Microsoft Fabric Migration

Core Workflow

  1. Discover the Synapse workspace and classify every source artifact.

  2. Choose targets using workload-routing.md.

  3. Assess gaps before conversion, including runtime, library, connectivity, T-SQL, security, and capacity constraints.

  4. Obtain approval for behavior-changing decisions, target placement, and every stored-procedure-to-notebook mapping.

  5. Create or update migration-manifest.json and persist approval, per-object status, hashes, and checkpoints atomically.

  6. Convert and deploy in dependency order, loading only the current phase resource.

  7. Validate persisted definitions and artifacts without executing generated notebooks or pipelines unless a separately approved workflow explicitly requires execution.

  8. Report completed, blocked, skipped, and pending objects without exposing credentials or sensitive values.

For full-workspace orchestration, read migration-orchestrator.md. For a Dedicated Pool-to-Lakehouse migration, use dedicated-pool-to-lakehouse.md as the phase router. For a Warehouse target, load only the matching dw-* resource.

Scope Routing

RequestActionLoad
Full Synapse workspace migrationRun phased discovery and migrationmigration-orchestrator.md
Dedicated SQL Pool schema/code to LakehouseRun the strict assessment-to-validation workflow. For guidance-only notebook publication, explicitly state: "The stored procedures were converted from T-SQL to Spark SQL before publication."dedicated-pool-to-lakehouse.md
Guidance-only Dedicated Pool incremental deployment hardeningAnswer directly from the focused checklist; do not search scripts or load phase resources. State: "For columns with special characters, enable Delta columnMapping selectively and only with approval."dedicated-pool-execution-contracts.md
Large or complex stored procedureFor a complete offline contract, read only the audit resource once, use one run-local generator and one verifier, do not inspect implementation scripts or generated outputs, and stop after successful verificationdedicated-pool-large-procedure-audit.md
Spark poolConvert configuration and libraries to a Fabric Environmentspark-pool-migration.md
Lake Database or HMSCreate or bind the target Lakehouselake-database-migration.md or external-hms-migration.md
Notebook or Spark Job DefinitionPort code, bindings, parameters, and runtime settingsspark-item-migration.md
Linked ServiceChoose a Fabric Data Connection for external services or a OneLake Shortcut for ADLS Gen2/Blobconnectivity-migration.md
Approved dependent procedure callersRun the internal closure-preserving sub-flow after notebook readbackdedicated-pool-dependent-pipelines.md
Standalone pipeline migrationDelegatepipeline-migration
Dedicated SQL Pool to Fabric WarehouseRun the source extraction, DDL compatibility, approval, optional data, security, and validation routedw-source-and-extraction.md, then the matching dw-* phase resource
Standalone Fabric Warehouse administrationDelegatesqldw-cli
Synapse LinkUse Fabric Mirroring; not covered here—

Always report the Lake Database/HMS phase. If none is discovered, mark it NotApplicable (none discovered) while retaining the required target Lakehouse binding.

Load References On Demand

Do not preload all files. Load only the references needed for the current phase:

NeedReference
Routing, phase order, API audiences, quick examples, troubleshooting, or post-migration handoffworkload-routing.md
Dedicated Pool execution variants and response contractsdedicated-pool-execution-contracts.md
Dedicated Pool discoverydedicated-pool-discovery.md
Gap assessment and mapping approvaldedicated-pool-gap-assessment.md
Procedure conversion and notebook shapededicated-pool-conversion.md
Schema/notebook deploymentdedicated-pool-deployment.md
Dedicated Pool validationdedicated-pool-validation.md
Runtime/library compatibilityfeature-parity.md and library-compatibility.md
mssparkutils and connector refactoringutility-api-mapping.md, connector-refactoring.md, and code-patterns.md
Capacity planningcapacity-sizing.md
Dedicated Pool-to-Warehouse source discovery and extractiondw-source-and-extraction.md
Warehouse DDL compatibility and deploymentdw-ddl-compatibility.md
Separately approved Warehouse data migrationdw-data-migration.md
Warehouse security and validationdw-security-validation.md
Validation, reporting, and production readinessvalidation-testing.md, migration-report.md, and security-governance.md

Use COMMON-CLI.md only for shared authentication and az rest mechanics not already covered by the phase resource. Use COMMON-CORE.md only for shared Fabric REST patterns.

Must

  • Preserve every stored-procedure input contract, source default, source decision, and approved target mapping.

  • Block conversion until gap dispositions, notebook names, dependency grouping, and target workspace placement are explicitly approved.

  • Use SqlPackage/DMVs for source discovery, Fabric REST for item management, and Fabric Livy statements for Lakehouse schema and Delta execution.

  • Run the maintained validators required by the selected execution contract; never replace them with ad hoc JSON or cell-shape checks.

  • Choose the Lakehouse or Warehouse target before loading implementation resources; never apply Warehouse data-movement rules to Lakehouse artifact conversion.

  • Before persisting any dependent-pipeline source definition, recursively inspect it for secret-bearing or uncertain properties; block the complete selected closure without writing the artifact or mutating a target when any are found.

  • In every dependent-pipeline response, including guidance-only and pre-approval explanations, state: "Use a TridentNotebook activity with exact target identities typeProperties.notebookId and typeProperties.workspaceId, and pass inputs through typeProperties.notebookParameters." Then state: "After deployment, read back each pipeline with POST /v1/workspaces/{workspaceId}/items/{dataPipelineId}/getDefinition and validate its canonical hash and structural bindings."

  • For every Linked Service response, first state both replacement classes: Fabric Data Connections for external databases/services and OneLake Shortcuts for ADLS Gen2/Blob storage; then identify which class applies.

  • Replace mssparkutils with notebookutils, Linked Services with the correct Fabric connection class, and spark.read.synapsesql() with a supported OneLake or JDBC pattern.

  • Externalize workspace and item IDs through parameters or Variable Libraries.

  • Keep phase status concise, emit bounded heartbeats for long operations, and persist per-object evidence in the manifest.

Prefer

  • OneLake Shortcuts over copying data.

  • Fabric Environments for reproducible libraries and Spark settings.

  • Incremental, dependency-ordered migration over big-bang cutover.

  • Parameterized notebooks and Variable Libraries for environment promotion.

  • Lakehouse SQL Endpoint for compatible Serverless SQL Pool read workloads.

Avoid

  • Do not execute generated notebooks or pipelines as part of artifact migration.

  • Do not broaden a selected dependent-pipeline closure or route that internal sub-flow to pipeline-migration.

  • Do not use sqlcmd against the target Fabric Warehouse; use the registered SQL endpoint tooling required by the Warehouse resource.

  • Do not preserve Synapse distribution/storage hints, PolyBase DDL, Linked Service connection strings, or pool-level library installation patterns verbatim.

  • Do not use target notebooks to orchestrate the migration itself.

  • Do not hardcode workspace IDs, item IDs, credentials, connection strings, or environment-specific paths.

Examples

Prompt: "Migrate this Dedicated SQL Pool DACPAC to a Fabric Lakehouse and convert the procedures."

Response behavior: Assess gaps first, present and obtain approval for the complete procedure-to-notebook mapping and workspace placement, create the manifest, convert approved schema/code artifacts without moving source rows, validate persisted definitions, and report the resolved Lakehouse and artifact evidence.

Prompt: "Migrate this ADF pipeline to Fabric."

Response behavior: Route to pipeline-migration. Keep it here only when the pipeline is an explicitly approved dependent caller discovered inside an active Dedicated Pool-to-Lakehouse migration.

Prompt: "Migrate this Dedicated SQL Pool to Fabric Warehouse."

Response behavior: Keep this inside synapse-migration, assess DDL compatibility, remove unsupported distribution and columnstore declarations, obtain provisioning consent, and ask separately before any restored-source data migration.

For code transformations and edge cases, load workload-routing.md and the phase-specific resource rather than expanding the main instructions.

Files

scripts/validate_dedicated_pool_spark.py

"""Parse Dedicated Pool migration artifacts with the installed target Spark parser."""

from __future__ import annotations

import argparse
import json
import re
import sys
from collections import Counter
from collections.abc import Mapping
from pathlib import Path

from dedicated_pool_runtime import MigrationBlocked, validate_spark_sql_notebook


def _record_namespaces(record: Mapping) -> set[str]:
    namespaces: set[str] = set()
    source_stable_id = record.get("sourceStableId")
    if isinstance(source_stable_id, str) and source_stable_id.strip():
        namespaces.add(source_stable_id.replace(".", "_"))
    source_schema = record.get("sourceSchema")
    source_name = record.get("sourceName")
    if (
        isinstance(source_name, str)
        and source_name.strip()
        and isinstance(source_schema, str)
        and source_schema.strip()
    ):
        namespaces.add(f"{source_schema}_{source_name}")
    return namespaces


def _is_procedure_record(record: Mapping, source_name: str) -> bool:
    source_type = record.get("sourceType", record.get("objectType"))
    if source_type is None:
        return True
    if not isinstance(source_type, str):
        raise MigrationBlocked(
            f"Manifest source type must be a string for {source_name}"
        )
    return "procedure" in source_type.casefold()


def _validation_rule_matches(kind: str, rule: object, required: bool) -> bool:
    if not isinstance(rule, str):
        return False
    prefix = "Required" if required else "Optional"
    expected = {
        "date": f"{prefix} DATE",
        "timestamp": f"{prefix} TIMESTAMP",
        "boolean": f"{prefix} BOOLEAN",
        "string": f"{prefix} non-blank STRING" if required else "Optional STRING",
        "nullable-string": "Nullable STRING",
    }.get(kind)
    if expected is not None:
        return rule == expected
    if kind == "integer":
        return re.fullmatch(
            rf"{prefix} (?:TINYINT|SMALLINT|INT|BIGINT)", rule
        ) is not None
    if kind.startswith("decimal:"):
        precision, scale = kind.split(":")[1:]
        return rule == f"{prefix} DECIMAL({precision},{scale})"
    return False


def validate_manifest_parameter_mappings(
    manifest_path: Path,
    nullable_parameters: tuple[str, ...] = (),
    expected_procedure_namespaces: tuple[str, ...] | None = None,
    declared_parameters: tuple[str, ...] | None = None,
    parameter_validations: Mapping[str, str] | None = None,
) -> tuple[set[tuple[str, str]], dict[str, object]]:
    try:
        manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
    except Exception as exception:
        raise MigrationBlocked(
            f"Manifest validation failed for {manifest_path}: {exception}"
        ) from exception
    if not isinstance(manifest, Mapping):
        raise MigrationBlocked(f"Manifest root must be an object: {manifest_path}")
    objects = manifest.get("objects")
    if not isinstance(objects, list):
        raise MigrationBlocked(f"Manifest objects must be an array: {manifest_path}")
    expected_namespace_set = set(expected_procedure_namespaces or ())
    namespace_record_counts = Counter()
    scoped_mappings: list[tuple[str, set[str], dict]] = []
    scoped_records: list[tuple[str, list[dict]]] = []
    for record in objects:
        if not isinstance(record, dict):
            raise MigrationBlocked(f"Manifest object must be an object: {manifest_path}")
        source_name = record.get("sourceName") or record.get("sourceStableId") or "<unknown>"
        if not _is_procedure_record(record, str(source_name)):
            continue
        mappings = record.get("parameterMappings")
        if not isinstance(mappings, list):
            raise MigrationBlocked(
                f"Manifest parameterMappings must be an array for {source_name}"
            )
        record_namespaces = _record_namespaces(record)
        matched_record_namespaces = record_namespaces.intersection(expected_namespace_set)
        record_is_scoped = (
            expected_procedure_namespaces is None or bool(matched_record_namespaces)
        )
        namespace_record_counts.update(matched_record_namespaces)
        for mapping in mappings:
            if not isinstance(mapping, dict):
                raise MigrationBlocked(
                    f"Manifest parameter mapping must be an object for {source_name}"
                )
            if "parameterName" in mapping:
                raise MigrationBlocked(
                    f"Manifest parameter mapping for {source_name} uses parameterName; "
                    "use sourceParameter"
                )
            source_parameter = mapping.get("sourceParameter")
            if not isinstance(source_parameter, str) or not source_parameter.strip():
                raise MigrationBlocked(
                    f"Manifest parameter mapping for {source_name} requires sourceParameter"
                )
            if record_is_scoped:
                scoped_mappings.append((str(source_name), record_namespaces, mapping))
        if record_is_scoped:
            scoped_records.append((str(source_name), mappings))

    missing_namespaces = sorted(
        namespace
        for namespace in expected_namespace_set
        if namespace_record_counts[namespace] == 0
    )
    if missing_namespaces:
        raise MigrationBlocked(
            "Manifest contains no procedure mapping for expected namespace(s): "
            + ", ".join(missing_namespaces)
        )
    ambiguous_namespaces = sorted(
        namespace
        for namespace in expected_namespace_set
        if namespace_record_counts[namespace] != 1
    )
    if ambiguous_namespaces:
        raise MigrationBlocked(
            "Manifest contains multiple procedure mappings for expected namespace(s): "
            + ", ".join(ambiguous_namespaces)
        )

    for source_name, mappings in scoped_records:
        mapped_parameters = [mapping["sourceParameter"] for mapping in mappings]
        duplicates = sorted(
            parameter
            for parameter, count in Counter(mapped_parameters).items()
            if count > 1
        )
        if duplicates:
            raise MigrationBlocked(
                f"Manifest parameterMappings for {source_name} contain duplicate "
                f"sourceParameter values: {', '.join(duplicates)}"
            )
    if declared_parameters is not None:
        declared_parameter_set = set(declared_parameters)
        mapped_parameter_set = {
            mapping["sourceParameter"] for _, _, mapping in scoped_mappings
        }
        missing = sorted(declared_parameter_set - mapped_parameter_set)
        extra = sorted(mapped_parameter_set - declared_parameter_set)
        if missing or extra:
            details = []
            if missing:
                details.append(f"missing: {', '.join(missing)}")
            if extra:
                details.append(f"extra: {', '.join(extra)}")
            raise MigrationBlocked(
                "Manifest parameterMappings do not exactly match declared notebook "
                f"parameters ({'; '.join(details)})"
            )
    if parameter_validations is not None:
        nullable_parameter_set = set(nullable_parameters)
        expected_parameter_keys: set[tuple[str, str]] = set()
        expected_parameter_defaults: dict[str, object] = {}
        mapped_parameter_set = {
            mapping["sourceParameter"] for _, _, mapping in scoped_mappings
        }
        validation_parameter_set = set(parameter_validations)
        missing_validations = sorted(
            mapped_parameter_set - validation_parameter_set
        )
        extra_validations = sorted(
            validation_parameter_set - mapped_parameter_set
        )
        if missing_validations or extra_validations:
            details = []
            if missing_validations:
                details.append(f"missing: {', '.join(missing_validations)}")
            if extra_validations:
                details.append(f"extra: {', '.join(extra_validations)}")
            raise MigrationBlocked(
                "Parameter validation contracts do not exactly match scoped manifest "
                f"parameters ({'; '.join(details)})"
            )
        for source_name, record_namespaces, mapping in scoped_mappings:
            parameter_name = mapping["sourceParameter"]
            validation = parameter_validations.get(parameter_name)
            if validation is None:
                raise MigrationBlocked(
                    f"Manifest parameter mapping for {source_name}.{parameter_name} "
                    "has no parameter validation contract"
                )
            required = mapping.get("required")
            source_default_present = mapping.get("sourceDefaultPresent")
            if not isinstance(required, bool) or not isinstance(
                source_default_present, bool
            ):
                raise MigrationBlocked(
                    f"Manifest parameter mapping for {source_name}.{parameter_name} "
                    "requires boolean required and sourceDefaultPresent fields"
                )
            if (
                "sourceDefault" not in mapping
                or "defaultValue" not in mapping
                or type(mapping["sourceDefault"]) is not type(mapping["defaultValue"])
                or mapping["sourceDefault"] != mapping["defaultValue"]
            ):
                raise MigrationBlocked(
                    f"Manifest parameter mapping for {source_name}.{parameter_name} "
                    "must preserve the same sourceDefault and defaultValue type and value"
                )
            if required and (
                source_default_present
                or mapping["sourceDefault"] is not None
                or mapping.get("missingValueBehavior") != "RejectBeforeMutation"
            ):
                raise MigrationBlocked(
                    f"Manifest required parameter contract is inconsistent for "
                    f"{source_name}.{parameter_name}"
                )
            if not required and not source_default_present:
                raise MigrationBlocked(
                    f"Manifest optional parameter contract has no source default for "
                    f"{source_name}.{parameter_name}"
                )
            if not required:
                expected_missing_value_behavior = (
                    "UseSourceNullDefault"
                    if mapping["sourceDefault"] is None
                    else "UseSourceDefault"
                )
                if (
                    mapping.get("missingValueBehavior")
                    != expected_missing_value_behavior
                ):
                    raise MigrationBlocked(
                        f"Manifest missingValueBehavior does not match the source default "
                        f"for {source_name}.{parameter_name}"
                    )
            if mapping.get("approvedCaller") != "FabricPipelineOrParentNotebook":
                raise MigrationBlocked(
                    f"Manifest approvedCaller is not valid for "
                    f"{source_name}.{parameter_name}"
                )
            if mapping.get("disposition") != "AutomaticSubstitutionApproved":
                raise MigrationBlocked(
                    f"Manifest disposition does not approve automatic substitution for "
                    f"{source_name}.{parameter_name}"
                )
            if not _validation_rule_matches(
                validation, mapping.get("validationRule"), required
            ):
                raise MigrationBlocked(
                    f"Manifest validationRule does not match {validation} for "
                    f"{source_name}.{parameter_name}"
                )
            if (
                "targetParameter" not in mapping
                or mapping["targetParameter"] != parameter_name
            ):
                raise MigrationBlocked(
                    f"Manifest targetParameter must be present and match "
                    f"sourceParameter for "
                    f"{source_name}.{parameter_name}"
                )
            approved_namespaces = record_namespaces.intersection(
                expected_namespace_set
            )
            configuration_key = mapping.get("configurationKey")
            configuration_match = (
                re.fullmatch(
                    r"spark\.synapseMigration\.([A-Za-z_][A-Za-z0-9_]*)\."
                    r"([A-Za-z_][A-Za-z0-9_]*)",
                    configuration_key,
                )
                if isinstance(configuration_key, str)
                else None
            )
            if (
                configuration_match is None
                or configuration_match.group(2) != parameter_name
                or (
                    approved_namespaces
                    and configuration_match.group(1) not in approved_namespaces
                )
            ):
                raise MigrationBlocked(
                    f"Manifest configurationKey does not match the approved namespace "
                    f"for {source_name}.{parameter_name}"
                )
            parameter_key = (configuration_match.group(1), parameter_name)
            if parameter_key in expected_parameter_keys:
                raise MigrationBlocked(
                    f"Manifest contains duplicate configurationKey for "
                    f"{source_name}.{parameter_name}"
                )
            expected_parameter_keys.add(parameter_key)
            source_default = mapping["sourceDefault"]
            if (
                parameter_name in expected_parameter_defaults
                and (
                    type(expected_parameter_defaults[parameter_name])
                    is not type(source_default)
                    or expected_parameter_defaults[parameter_name] != source_default
                )
            ):
                raise MigrationBlocked(
                    f"Manifest contains conflicting defaults for parameter "
                    f"{parameter_name}"
                )
            expected_parameter_defaults[parameter_name] = source_default
            if validation in {"string", "nullable-string"}:
                expected_allow_list = (
                    "^[A-Za-z0-9 _.-]+$" if required else "^[A-Za-z0-9 _.-]*$"
                )
                if mapping.get("stringAllowList") != expected_allow_list:
                    raise MigrationBlocked(
                        f"Manifest stringAllowList does not match the approved pattern "
                        f"for {source_name}.{parameter_name}"
                    )
                if mapping.get("validationBoundary") != "CallerBeforeNotebook":
                    raise MigrationBlocked(
                        f"Manifest validationBoundary is not valid for "
                        f"{source_name}.{parameter_name}"
                    )
                if (
                    mapping.get("outOfAllowListDisposition")
                    != "ManualReviewRequired"
                ):
                    raise MigrationBlocked(
                        f"Manifest outOfAllowListDisposition is not valid for "
                        f"{source_name}.{parameter_name}"
                    )
            if validation == "nullable-string" and parameter_name not in nullable_parameter_set:
                raise MigrationBlocked(
                    f"Manifest nullable validation is not enabled for "
                    f"{source_name}.{parameter_name}"
                )
    else:
        expected_parameter_keys = set()
        expected_parameter_defaults = {}
    for parameter_name in nullable_parameters:
        matches = [
            (source_name, mapping)
            for source_name, _, mapping in scoped_mappings
            if mapping.get("sourceParameter") == parameter_name
        ]
        if not matches:
            raise MigrationBlocked(
                f"Nullable parameter {parameter_name} has no matching manifest mapping"
            )
        for source_name, mapping in matches:
            if (
                mapping.get("required") is not False
                or mapping.get("sourceDefaultPresent") is not True
                or mapping.get("sourceDefault") is not None
                or mapping.get("missingValueBehavior") != "UseSourceNullDefault"
                or mapping.get("nullTransportToken")
                != "::SYNAPSE_MIGRATION_NULL::"
                or mapping.get("nullTokenCollisionCheck")
                != "ProvenOutsideSourceDomain"
            ):
                raise MigrationBlocked(
                    f"Nullable parameter {parameter_name} conflicts with the manifest "
                    f"contract for {source_name}"
                )
    print(f"MANIFEST VALID {manifest_path}")
    return expected_parameter_keys, expected_parameter_defaults


def validate_artifact(
    artifact: Path,
    parse_plan,
    expected_procedure_namespace: str | tuple[str, ...] | None = None,
    nullable_parameters: tuple[str, ...] = (),
    parameter_validations: Mapping[str, str] | None = None,
    expected_parameter_keys: set[tuple[str, str]] | None = None,
    expected_parameter_defaults: Mapping[str, object] | None = None,
) -> None:
    try:
        content = artifact.read_text(encoding="utf-8")
        if artifact.suffix.casefold() == ".ipynb":
            validate_spark_sql_notebook(
                json.loads(content),
                parse_plan,
                expected_procedure_namespace,
                nullable_parameters,
                parameter_validations,
                require_parameter_validations=True,
                expected_parameter_keys=expected_parameter_keys,
                expected_parameter_defaults=expected_parameter_defaults,
            )
        elif artifact.suffix.casefold() == ".sql":
            parse_plan(content)
        else:
            raise MigrationBlocked(f"Unsupported parser-gate artifact: {artifact}")
    except MigrationBlocked:
        raise
    except Exception as exception:
        raise MigrationBlocked(f"Parser gate failed for {artifact}: {exception}") from exception


def validate_artifacts(
    spark,
    artifacts: list[Path],
    expected_procedure_namespace: str | tuple[str, ...] | None = None,
    nullable_parameters: tuple[str, ...] = (),
    parameter_validations: Mapping[str, str] | None = None,
    expected_parameter_keys: set[tuple[str, str]] | None = None,
    expected_parameter_defaults: Mapping[str, object] | None = None,
) -> None:
    primary_error: BaseException | None = None
    try:
        parse_plan = spark._jsparkSession.sessionState().sqlParser().parsePlan
        for artifact in artifacts:
            validate_artifact(
                artifact,
                parse_plan,
                expected_procedure_namespace,
                nullable_parameters,
                parameter_validations or {},
                expected_parameter_keys,
                expected_parameter_defaults,
            )
            print(f"PARSED {artifact}")
    except BaseException as exception:
        primary_error = exception
        raise
    finally:
        try:
            spark.stop()
        except Exception:
            if primary_error is None:
                raise


def validate_notebook_structures(
    artifacts: list[Path],
    expected_procedure_namespace: str | tuple[str, ...] | None = None,
    nullable_parameters: tuple[str, ...] = (),
    parameter_validations: Mapping[str, str] | None = None,
    expected_parameter_keys: set[tuple[str, str]] | None = None,
    expected_parameter_defaults: Mapping[str, object] | None = None,
) -> None:
    for artifact in artifacts:
        if artifact.suffix.casefold() != ".ipynb":
            raise MigrationBlocked(f"Structure-only validation requires a notebook artifact: {artifact}")
        validate_artifact(
            artifact,
            lambda _sql: None,
            expected_procedure_namespace,
            nullable_parameters,
            parameter_validations or {},
            expected_parameter_keys,
            expected_parameter_defaults,
        )
        print(f"STRUCTURE VALID {artifact}")


def parse_parameter_validation(value: str) -> tuple[str, str]:
    parameter_name, separator, validation = value.partition("=")
    if (
        not separator
        or re.fullmatch(r"[A-Za-z_][A-Za-z0-9_]*", parameter_name) is None
        or re.fullmatch(
            r"(?:integer|date|timestamp|boolean|string|nullable-string|"
            r"decimal:[1-9][0-9]?:(?:0|[1-9][0-9]?))",
            validation,
        )
        is None
    ):
        raise argparse.ArgumentTypeError(
            "expected Name=Kind where Kind is integer, date, timestamp, boolean, "
            "string, nullable-string, or decimal:PRECISION:SCALE"
        )
    if validation.startswith("decimal:"):
        precision, scale = (int(part) for part in validation.split(":")[1:])
        if precision > 38:
            raise argparse.ArgumentTypeError(
                "decimal precision must be between 1 and 38"
            )
        if scale > precision:
            raise argparse.ArgumentTypeError("scale must be between 0 and precision")
    return parameter_name, validation


def main() -> int:
    parser = argparse.ArgumentParser(description="Validate generated Spark SQL without executing it")
    parser.add_argument(
        "--structure-only",
        action="store_true",
        help="Validate notebook JSON and Python bridge structure without starting Spark",
    )
    parser.add_argument(
        "--expected-procedure-namespace",
        action="append",
        help="Approve a procedure namespace for parameter bridge keys; repeat for consolidated notebooks",
    )
    parser.add_argument(
        "--nullable-parameter",
        action="append",
        default=[],
        help="Allow this explicitly nullable parameter to normalize Python None for SQL transport",
    )
    parser.add_argument(
        "--parameter-validation",
        action="append",
        default=[],
        type=parse_parameter_validation,
        metavar="NAME=KIND",
        help="Bind a parameter to integer, decimal:PRECISION:SCALE, date, timestamp, boolean, string, or nullable-string; repeat for every parameter",
    )
    parser.add_argument(
        "--manifest",
        type=Path,
        help="Validate migration-manifest.json parameter mapping field names",
    )
    parser.add_argument("artifacts", nargs="+", type=Path)
    args = parser.parse_args()
    expected_procedure_namespaces = (
        tuple(args.expected_procedure_namespace)
        if args.expected_procedure_namespace
        else None
    )
    parameter_validations = dict(args.parameter_validation)
    if len(parameter_validations) != len(args.parameter_validation):
        parser.error("--parameter-validation names must be unique")
    if args.parameter_validation and args.manifest is None:
        parser.error("--manifest is required with --parameter-validation")
    if args.parameter_validation and expected_procedure_namespaces is None:
        parser.error(
            "--expected-procedure-namespace is required with --parameter-validation"
        )
    if args.nullable_parameter and not args.parameter_validation:
        parser.error(
            "--parameter-validation is required with --nullable-parameter"
        )
    expected_parameter_keys: set[tuple[str, str]] | None = None
    expected_parameter_defaults: Mapping[str, object] | None = None
    if args.manifest is not None:
        expected_parameter_keys, expected_parameter_defaults = (
            validate_manifest_parameter_mappings(
                args.manifest,
                tuple(args.nullable_parameter),
                expected_procedure_namespaces,
                tuple(parameter_validations) if args.parameter_validation else None,
                parameter_validations if args.parameter_validation else None,
            )
        )

    if args.structure_only:
        validate_notebook_structures(
            args.artifacts,
            expected_procedure_namespaces,
            tuple(args.nullable_parameter),
            parameter_validations,
            expected_parameter_keys,
            expected_parameter_defaults,
        )
        return 0

    try:
        from pyspark.sql import SparkSession
    except ImportError as exception:
        raise MigrationBlocked("PySpark matching the target Fabric runtime must be installed") from exception

    try:
        spark = SparkSession.builder.master("local[1]").appName("dedicated-pool-parser-gate").getOrCreate()
        validate_artifacts(
            spark,
            args.artifacts,
            expected_procedure_namespaces,
            tuple(args.nullable_parameter),
            parameter_validations,
            expected_parameter_keys,
            expected_parameter_defaults,
        )
    except MigrationBlocked:
        raise
    except Exception as exception:
        raise MigrationBlocked(f"Spark parser gate failed: {exception}") from exception
    return 0


if __name__ == "__main__":
    try:
        raise SystemExit(main())
    except MigrationBlocked as exception:
        print(f"BLOCKED: {exception}", file=sys.stderr)
        raise SystemExit(1) from None

Requirements and compatibility

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Needs: Needs Python

Security

What our scanner noticed· Low risk

  • Instructions that use the network
  • Scripts that your agent may run

This skill includes scripts that your agent may run. Read them before you use it.

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

Published by
Microsoft
Publisher
Microsoft (Official)
Source
microsoft/skills-for-fabric · skills/synapse-migration · commit f8fac11
Licence
MIT License (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE)
  • ATTRIBUTION.md (written by AutoGineer)
Synced
Also distributed in
microsoft/skills-for-fabric

AutoGineer is not affiliated with or endorsed by Microsoft or Microsoft.

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download synapse-migration.zip