Skip to content

Allow overriding the virtual layer schema name directly, not just via suffix mode #5955

Description

@boraaktas

Problem

environment_suffix_target (schema/table/catalog) always appends the environment
name as a fixed suffix: f"{schema}__{env_name}" in
sqlmesh/core/snapshot/definition.py (schema_name_for_environment). There's no
way to control the resulting name beyond choosing which of the three levels gets
the suffix.

This is inconsistent with the physical layer, where physical_schema_mapping
already lets you map a model's schema (by regex) to an arbitrary target schema
name of your choosing.

Use case

Our org has an existing naming convention for personal/ad hoc schemas:
dev_<user> as a prefix. We can already point a model's physical table
anywhere via physical_schema_mapping, but the virtual layer view for a dev
environment is always <model_schema>__dev_<user> (suffix), which we can't
make consistent with our naming convention. environment_suffix_target: table
and : catalog don't help either, they move where the suffix goes, but it's
still always a suffix.

Proposal

Add a config option (e.g. a virtual_schema_mapping, analogous to
physical_schema_mapping) that lets users map a model's schema name to an
arbitrary virtual schema name/template for non-prod environments, instead of
being limited to the fixed <schema>__<environment> formula.

Default behavior (schema/table/catalog suffix modes) would stay unchanged for
anyone not setting this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions