# Spatial9 M&E Data Model: Databricks Asset Bundle

A starter Solution Accelerator for the media and entertainment data model described in
https://spatial9.ai/blog/media-entertainment-data-model-databricks-snowflake-bigquery-aws-clickhouse

It creates a Unity Catalog catalog with bronze, silver and gold schemas, loads a small sample
(two titles, two rights grants, two playback events) and builds three gold marts:

- `gold.rights_availability`: can this work be offered in this territory and media today?
- `gold.daily_consumption`: viewers and hours per work, territory and day
- `gold.out_of_window_usage`: consumption with no valid right, a compliance alert

## Requirements

- Databricks workspace with Unity Catalog and a SQL warehouse (serverless recommended)
- Databricks CLI v0.218 or newer, authenticated (`databricks auth login`)
- Permission to create a catalog, or change `catalog` to one you own

## Deploy

```bash
databricks bundle validate --var="warehouse_id=<your-warehouse-id>"
databricks bundle deploy -t dev --var="warehouse_id=<your-warehouse-id>"
databricks bundle run me_model -t dev --var="warehouse_id=<your-warehouse-id>"
```

## Files

| File | What it does |
|---|---|
| `databricks.yml` | Bundle name, variables and dev / prod targets |
| `resources/me_model_job.yml` | Job with five SQL tasks in order |
| `src/00_setup_catalog.sql` | Catalog and schemas |
| `src/10_bronze.sql` | Raw landing tables and sample data |
| `src/20_silver.sql` | Conformed entities: work, version, asset, right_grant, playback_event |
| `src/30_gold.sql` | Rights, consumption and compliance marts |
| `src/40_quality_checks.sql` | Rules that fail the job if data breaks them |

## Next steps

1. Replace the sample INSERTs with Auto Loader or `COPY INTO` from your DDEX, EIDR, avails and player feeds.
2. Add the music subject area (composition by ISWC, recording by ISRC, release by UPC) and royalty lines.
3. Tag sensitive columns and add row filters per territory in Unity Catalog.
4. Point Genie, Mosaic AI agents or the Spatial9 MCP tools at the gold schema.

Need help adapting it? Spatial9 Agentic Enterprise Transformation: https://spatial9.ai/services/entertainment-ai-transformation

Provided as-is under the MIT License.
