Skip to content

Feat: Add support for pre, post, on_virtual_update statements in config#4995

Merged
themisvaltinos merged 4 commits intomainfrom
themis/prepostdefaults
Jul 24, 2025
Merged

Feat: Add support for pre, post, on_virtual_update statements in config#4995
themisvaltinos merged 4 commits intomainfrom
themis/prepostdefaults

Conversation

@themisvaltinos
Copy link
Contributor

This update enables defining pre_statements, post_statements and on_virtual_update statements at the project level in the configuration that will be applied to all models.

Example:

    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"

These default statements are merged with any model-specific statements, with default statements executing first followed by the model-specific ones.

Copy link
Collaborator

@erindru erindru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

# Verify statements are in the model and python environment has been popuplated
assert len(model.pre_statements) == 2
assert len(model.post_statements) == 1
assert model.python_env["__sqlmesh__vars__"].payload == "{'var1': 4}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert model.python_env["__sqlmesh__vars__"].payload == "{'var1': 4}"
assert model.python_env[c.SQLMESH_VARS].payload == "{'var1': 4}"

@themisvaltinos themisvaltinos force-pushed the themis/prepostdefaults branch from 78949d4 to 91b64f4 Compare July 24, 2025 19:59
@themisvaltinos themisvaltinos merged commit a1ab547 into main Jul 24, 2025
27 checks passed
@themisvaltinos themisvaltinos deleted the themis/prepostdefaults branch July 24, 2025 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants