{
  "nbformat": 4,
  "nbformat_minor": 5,
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "name": "python",
      "version": "3.13.0"
    },
    "blog_metadata": {
      "topic": "Incremental Migration to Fabric Warehouse: A Safer Path Off Legacy Database Objects",
      "slug": "incremental-migration-to-fabric-warehouse-a-safer-path-off-l",
      "generated_by": "LinkedIn Post Generator + Azure OpenAI",
      "generated_at": "2026-10-22T18:38:00.702Z"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Incremental Migration to Fabric Warehouse: A Safer Path Off Legacy Database Objects\n",
        "\n",
        "This notebook turns the blog post into a hands-on validation workflow for phased migration planning. It focuses on scoring legacy database objects into migration waves, identifying re-migration triggers when source systems change, and documenting a practical decision framework where evidence matters more than cutover dates."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "%pip install pandas matplotlib seaborn"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "import pandas as pd\n",
        "import matplotlib.pyplot as plt\n",
        "import seaborn as sns\n",
        "from IPython.display import display\n",
        "\n",
        "sns.set_theme(style='whitegrid')\n",
        "pd.set_option('display.max_columns', None)\n",
        "pd.set_option('display.width', 120)"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Why phased migration works better\n",
        "\n",
        "A legacy analytics estate is more than a set of tables. It includes dependencies, naming conventions, timing assumptions, semantic models, reports, and business-critical procedures. The practical migration pattern is to mirror source data early, classify objects by risk and ownership, migrate in bounded waves, and promote only after validation.\n",
        "\n",
        "The first hands-on example builds a migration-wave scorecard from an object inventory so you can prioritize low-risk objects first."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "# Python: Build a migration-wave scorecard from an object inventory\n",
        "import pandas as pd\n",
        "\n",
        "inventory = pd.DataFrame([\n",
        "    {\"object\": \"dbo.vw_sales\", \"deps\": 2, \"owner\": \"known\", \"criticality\": \"high\", \"validated\": True, \"retrigger\": False},\n",
        "    {\"object\": \"dbo.usp_close_month\", \"deps\": 7, \"owner\": \"unknown\", \"criticality\": \"high\", \"validated\": False, \"retrigger\": True},\n",
        "    {\"object\": \"dbo.dim_customer\", \"deps\": 1, \"owner\": \"known\", \"criticality\": \"medium\", \"validated\": True, \"retrigger\": False},\n",
        "])\n",
        "\n",
        "crit_weight = {\"low\": 1, \"medium\": 2, \"high\": 3}\n",
        "inventory[\"score\"] = (\n",
        "    inventory[\"deps\"] * 2\n",
        "    + inventory[\"criticality\"].map(crit_weight)\n",
        "    + inventory[\"owner\"].eq(\"unknown\").mul(3)\n",
        "    + (~inventory[\"validated\"]).mul(4)\n",
        "    + inventory[\"retrigger\"].mul(5)\n",
        ")\n",
        "inventory[\"wave\"] = pd.cut(\n",
        "    inventory[\"score\"],\n",
        "    bins=[-1, 5, 11, 99],\n",
        "    labels=[\"Wave 1\", \"Wave 2\", \"Wave 3\"]\n",
        ")\n",
        "\n",
        "scorecard = inventory[[\"object\", \"score\", \"wave\", \"validated\", \"retrigger\"]].sort_values(\"score\").reset_index(drop=True)\n",
        "print(\"Migration wave scorecard:\")\n",
        "print(scorecard)\n",
        "\n",
        "# Optional quick visualization\n",
        "plt.figure(figsize=(8, 4))\n",
        "plot_df = scorecard.copy()\n",
        "plot_df[\"wave\"] = plot_df[\"wave\"].astype(str)\n",
        "sns.barplot(data=plot_df, x=\"object\", y=\"score\", hue=\"wave\", dodge=False)\n",
        "plt.title(\"Migration Wave Score by Object\")\n",
        "plt.xlabel(\"Object\")\n",
        "plt.ylabel(\"Score\")\n",
        "plt.xticks(rotation=20)\n",
        "plt.tight_layout()\n",
        "plt.show()"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Re-migration is part of long-running programs\n",
        "\n",
        "One of the key ideas in the post is that migration is not a one-time export followed by a final cutover. Source schemas drift, dependencies change, and new consumers appear. The next example flags objects that should be re-migrated after source changes."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "# Python: Flag objects that should be re-migrated after source changes\n",
        "import pandas as pd\n",
        "\n",
        "changes = pd.DataFrame([\n",
        "    {\"object\": \"dbo.vw_sales\", \"schema_hash_changed\": False, \"dependency_changed\": True},\n",
        "    {\"object\": \"dbo.usp_close_month\", \"schema_hash_changed\": True, \"dependency_changed\": True},\n",
        "    {\"object\": \"dbo.dim_customer\", \"schema_hash_changed\": False, \"dependency_changed\": False},\n",
        "])\n",
        "\n",
        "changes[\"retrigger\"] = changes[\"schema_hash_changed\"] | changes[\"dependency_changed\"]\n",
        "retrigger_df = changes[changes[\"retrigger\"]][[\"object\", \"retrigger\"]].reset_index(drop=True)\n",
        "\n",
        "print(\"Objects requiring re-migration:\")\n",
        "print(retrigger_df)\n",
        "\n",
        "# Optional summary\n",
        "summary = changes[[\"schema_hash_changed\", \"dependency_changed\", \"retrigger\"]].sum().rename(\"count\")\n",
        "print(\"\\nChange summary:\")\n",
        "print(summary)"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Simulating a repeatable SQL object inventory in Python\n",
        "\n",
        "The original post includes a PowerShell example that exports SQL object metadata for migration-wave tracking. Since this notebook is Python-first, the next cell simulates the same outcome by creating a repeatable object inventory DataFrame and saving it as a CSV. In a real environment, this would typically come from a database query against system catalog views."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "# Python equivalent: Export a repeatable SQL object inventory for migration-wave tracking\n",
        "import pandas as pd\n",
        "from pathlib import Path\n",
        "\n",
        "object_inventory = pd.DataFrame([\n",
        "    {\"schema_name\": \"dbo\", \"object_name\": \"dim_customer\", \"type_desc\": \"USER_TABLE\", \"create_date\": \"2022-01-10\", \"modify_date\": \"2024-10-01\"},\n",
        "    {\"schema_name\": \"dbo\", \"object_name\": \"vw_sales\", \"type_desc\": \"VIEW\", \"create_date\": \"2022-03-15\", \"modify_date\": \"2024-11-20\"},\n",
        "    {\"schema_name\": \"dbo\", \"object_name\": \"usp_close_month\", \"type_desc\": \"SQL_STORED_PROCEDURE\", \"create_date\": \"2021-07-01\", \"modify_date\": \"2024-12-05\"},\n",
        "])\n",
        "\n",
        "output_path = Path(\"object-inventory.csv\")\n",
        "object_inventory.to_csv(output_path, index=False)\n",
        "\n",
        "print(f\"Saved inventory to: {output_path.resolve()}\")\n",
        "display(object_inventory)"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Adding metadata for dependency review and ownership gaps\n",
        "\n",
        "The post also shows a lightweight enrichment step to prepare migration-wave inputs. This includes owner status, criticality, and validation status. The next cell reads the exported inventory and adds those fields so the result can feed a scorecard or review workflow."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "# Python equivalent: Add lightweight metadata for dependency review and ownership gaps\n",
        "import pandas as pd\n",
        "from pathlib import Path\n",
        "\n",
        "inventory_path = Path(\"object-inventory.csv\")\n",
        "inventory = pd.read_csv(inventory_path)\n",
        "\n",
        "migration_wave_input = pd.DataFrame({\n",
        "    \"object_name\": inventory[\"schema_name\"] + \".\" + inventory[\"object_name\"],\n",
        "    \"type_desc\": inventory[\"type_desc\"],\n",
        "    \"owner_status\": inventory[\"schema_name\"].apply(lambda x: \"known\" if x == \"dbo\" else \"review\"),\n",
        "    \"criticality\": inventory[\"type_desc\"].apply(lambda x: \"high\" if x == \"SQL_STORED_PROCEDURE\" else \"medium\"),\n",
        "    \"validation_status\": \"pending\"\n",
        "})\n",
        "\n",
        "output_path = Path(\"migration-wave-input.csv\")\n",
        "migration_wave_input.to_csv(output_path, index=False)\n",
        "\n",
        "print(f\"Saved enriched migration input to: {output_path.resolve()}\")\n",
        "display(migration_wave_input)"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## End-to-end validation flow\n",
        "\n",
        "The blog’s migration pattern can be summarized as a simple operational loop: inventory legacy objects, export repeatable metadata, score and assign waves, migrate low-risk objects first, validate outputs, and retrigger migration when source changes occur. The next cell renders that flow as a compact table and checklist you can adapt for your own program."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "# Python representation of the migration flow described in the post\n",
        "import pandas as pd\n",
        "\n",
        "flow_steps = pd.DataFrame([\n",
        "    {\"step\": 1, \"stage\": \"Legacy SQL object inventory\", \"purpose\": \"Capture tables, views, and procedures in scope\"},\n",
        "    {\"step\": 2, \"stage\": \"Export repeatable metadata\", \"purpose\": \"Create a stable inventory snapshot for tracking\"},\n",
        "    {\"step\": 3, \"stage\": \"Scorecard\", \"purpose\": \"Rank by dependencies, owner, criticality, and validation\"},\n",
        "    {\"step\": 4, \"stage\": \"Wave assignment\", \"purpose\": \"Group objects into bounded migration waves\"},\n",
        "    {\"step\": 5, \"stage\": \"Fabric Warehouse migration\", \"purpose\": \"Move low-risk objects first\"},\n",
        "    {\"step\": 6, \"stage\": \"Validate outputs\", \"purpose\": \"Confirm data, semantics, and performance\"},\n",
        "    {\"step\": 7, \"stage\": \"Source changed?\", \"purpose\": \"Detect schema or dependency drift\"},\n",
        "    {\"step\": 8, \"stage\": \"Re-migration trigger or close wave\", \"purpose\": \"Retrigger if needed, otherwise keep wave closed\"},\n",
        "])\n",
        "\n",
        "display(flow_steps)\n",
        "\n",
        "print(\"Validation checklist:\")\n",
        "checklist = [\n",
        "    \"Reconciled data\",\n",
        "    \"Functional test pass\",\n",
        "    \"Security review\",\n",
        "    \"Representative performance validation\",\n",
        "    \"Named owner\",\n",
        "    \"Documented rollback path\",\n",
        "]\n",
        "for i, item in enumerate(checklist, start=1):\n",
        "    print(f\"{i}. {item}\")"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Next Steps\n",
        "\n",
        "Use this notebook as a starting point for your own phased Fabric Warehouse migration plan. Replace the sample inventory with real metadata, expand the scoring model to include business value and reversibility, and define evidence-based exit criteria for each wave.\n",
        "\n",
        "A practical next iteration would be to connect this workflow to your actual object inventory, dependency graph, semantic model validation, and performance benchmarks so migration decisions are driven by proof rather than optimism."
      ]
    }
  ]
}