Customizing SQLMesh
SQLMesh supports the workflows used by the vast majority of data engineering teams. However, your company may have bespoke processes or tools that require special integration with SQLMesh.
Fortunately, SQLMesh is an open-source Python library, so you can view its underlying code and customize it for your needs.
Customization generally involves subclassing SQLMesh classes to extend or modify their functionality.
Caution
Customize SQLMesh with extreme caution. Errors may cause SQLMesh to produce unexpected results.
Custom loader
Loading is the process of reading project files and converting their contents into SQLMesh's internal Python objects.
The loading stage is a convenient place to customize SQLMesh behavior because you can access a project's objects after they've been ingested from file but before SQLMesh uses them.
SQLMesh's SqlMeshLoader
class handles the loading process - customize it by subclassing it and overriding its methods.
Python configuration only
Custom loaders require using the Python configuration format (YAML is not supported).
Modify every model
One reason to customize the loading process is to do something to every model. For example, you might want to add a post-statement to every model.
The loading process parses all model SQL statements, so new or modified SQL must be parsed by SQLGlot before being passed to a model object.
This custom loader example adds a post-statement to every model: