sqlmesh icon indicating copy to clipboard operation
sqlmesh copied to clipboard

Add model defaults at the subfolder level within the `models/` directory

Open sungchun12 opened this issue 1 year ago • 3 comments

Let's make it easy to add model defaults to different subfolders within a sqlmesh project. We have it at the project level and individual model level, but nothing in between. This will be helpful for granting permissions, grouping together pre/post-statements, etc.

Similar to this recent PR: https://github.com/TobikoData/sqlmesh/pull/4995

Model config override behavior: model > subfolder > project

Quick and dirty mockup for config.yaml:

model_defaults:
  dialect: duckdb
  pre_statements:
    - "SET timeout = 300000"
  post_statements:
    - "@IF(@runtime_stage = 'evaluating', ANALYZE @this_model)"
  on_virtual_update:
    - "GRANT SELECT ON @this_model TO ROLE analyst_role"
  subfolder_a:
      dialect: snowflake
      pre_statements:
        - "SET timeout = 200000"
  subfolder_b:
      pre_statements:
        - "SET timeout = 400000"

sungchun12 avatar Jul 22 '25 16:07 sungchun12

@themisvaltinos how hard is this given what your recent PR referenced above?

sungchun12 avatar Jul 22 '25 16:07 sungchun12

@themisvaltinos how hard is this given what your recent PR referenced above?

This one's a tad trickier for folders, so the implementation would be a bit of a bigger lift. We do now support gateway-specific model defaults, but their resolution happens earlier. So for directory-specific we'd have to structure the loader to support a hierarchical config merging strategy: project → subfolder → model-specific, with proper handling of overrides. So I'd say it’s doable, but not as trivial

themisvaltinos avatar Jul 23 '25 09:07 themisvaltinos

+1 for this feature

alex-harness avatar Jul 30 '25 23:07 alex-harness