A demonstration project showcasing how to use SQLMesh with Microsoft Fabric for building production-ready data transformation pipelines.
This project demonstrates:
- Building incremental and full-refresh data models with SQLMesh
- Integration with Microsoft Fabric Warehouse as the execution engine
- Automated testing and data quality audits
- CI/CD-ready data pipeline deployment
sqlmesh_fabric_demo/
├── models/ # SQLMesh model definitions
│ ├── seed_model.sql # Base model from seed data
│ ├── incremental_model.sql # Time-based incremental model
│ └── full_model.sql # Full refresh aggregation
├── seeds/ # Static CSV data
├── audits/ # Data quality checks
├── tests/ # Unit tests for models
├── notebooks/ # Jupyter notebooks (import these to Fabric)
└── config.yaml # SQLMesh configuration
The demo implements a simple e-commerce analytics pipeline:
graph LR
A[seed_data.csv] --> B[seed_model]
B --> C[incremental_model]
C --> D[full_model]
D --> E[audit: positive_order_ids]
- seed_model: Loads static reference data
- incremental_model: Processes events incrementally by date range
- full_model: Aggregates order counts by item with data quality audits
- Python 3.11
- Microsoft Fabric workspace
- Azure Service Principal with Fabric access
- SQL Database for SQLMesh state management
- Clone the repository:
git clone https://github.com/mattiasthalen/sqlmesh-fabric-demo.git
cd sqlmesh_fabric_demo
- Install dependencies:
# Using uv (recommended)
uv sync
# Or using pip
pip install "sqlmesh[fabric,mssql,lsp]"
- Set environment variables:
export CREDENTIALS__AZURE_TENANT_ID="your_azure_tenant_id"
export CREDENTIALS__AZURE_CLIENT_ID="your_azure_client_id"
export CREDENTIALS__AZURE_CLIENT_SECRET="your_azure_client_secret"
export FABRIC__WORKSPACE_ID="your_fabric_workspace_id"
export FABRIC__SQL_ENDPOINT_ID="your_fabric_sql_endpoint_uuid"
export FABRIC__WAREHOUSE_ENDPOINT="${FABRIC__SQL_ENDPOINT_ID}.datawarehouse.fabric.microsoft.com"
export FABRIC__STATE_ENDPOINT="${FABRIC__SQL_ENDPOINT_ID}.database.fabric.microsoft.com"
export FABRIC__STATE_DATABASE="your_state_database"
# Validate configuration and models
uv run sqlmesh validate
# Run tests
uv run sqlmesh test
# Preview changes for development
uv run sqlmesh plan dev
# Deploy to production
uv run sqlmesh plan prod --auto-apply
# Launch interactive UI
uv run sqlmesh ui
-
Import the notebook into your Fabric workspace:
- Navigate to your Fabric workspace
- Import
notebooks/sqlmesh__runner.ipynb
- The notebook will be created in your workspace
-
Add the codebase Lakehouse as a resource:
- Open the imported notebook
- Add your codebase Lakehouse as a default lakehouse resource
- This provides storage for the cloned repository
-
Configure Azure Key Vault with these secrets:
CREDENTIALS--AZURE-TENANT-ID
CREDENTIALS--AZURE-CLIENT-ID
CREDENTIALS--AZURE-CLIENT-SECRET
FABRIC--WORKSPACE-ID
FABRIC--WAREHOUSE-ENDPOINT
FABRIC--STATE-ENDPOINT
FABRIC--STATE-DATABASE
GIT-PAT
(Personal Access Token for Azure DevOps)
-
Update the notebook with your configuration:
- Azure Key Vault URL
- Azure DevOps organization name
- Azure DevOps project name
- Repository name
-
Run the notebook to execute SQLMesh plans in Fabric
The notebook automates:
- Secret retrieval from Azure Key Vault
- Git repository cloning from Azure DevOps
- SQLMesh installation and execution
- Automatic plan application to production
The project includes:
- Unit tests for model logic (
tests/test_full_model.yaml
) - Data audits that run after model execution (
audits/assert_positive_order_ids.sql
)
Run all tests:
uv run sqlmesh test
uv run sqlmesh audit
Models are configured with:
- Kind:
FULL
orINCREMENTAL_BY_TIME_RANGE
- Grain: Unique key columns
- Cron: Schedule (default:
@daily
) - Audits: Post-execution quality checks
Example from models/incremental_model.sql
:
MODEL (
name sqlmesh_example.incremental_model,
kind INCREMENTAL_BY_TIME_RANGE (
time_column event_date
),
start '2020-01-01',
cron '@daily',
grain (id, event_date)
);
Edit config.yaml
to configure:
- Fabric Warehouse connection
- State database connection
- Model defaults
- Linting rules
# Run with local changes
uv run sqlmesh plan dev
# Test before deployment
uv run sqlmesh test
Import and run notebooks/sqlmesh__runner.ipynb
in your Fabric workspace for automated execution.
# In your pipeline
uv run sqlmesh plan prod --auto-apply --no-prompts
-
Azure Service Principal with:
Item.ReadWrite.All
Fabric API scope- Contributor role on Fabric workspace
db_owner
on state database
-
Fabric Resources:
- Workspace with contributor access
- Warehouse named
demo
- SQL Database for state management
See Microsoft's Service Principal documentation for detailed setup.
- Create a feature branch
- Make your changes
- Run tests:
sqlmesh test
- Validate:
sqlmesh validate
- Submit a pull request
This is a demo project for educational purposes.