File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed
Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -73,16 +73,28 @@ def sqlmesh_config(
7373 if threads is not None :
7474 # the to_sqlmesh() function on TargetConfig maps self.threads -> concurrent_tasks
7575 profile .target .threads = threads
76-
76+
7777 gateway_kwargs = {}
7878 if infer_state_schema_name :
7979 profile_name = context .profile_name
80+
8081 # Note: we deliberately isolate state based on the target *schema* and not the target name.
8182 # It is assumed that the project will define a target, eg 'dev', and then in each users own ~/.dbt/profiles.yml the schema
8283 # for the 'dev' target is overriden to something user-specific, rather than making the target name itself user-specific.
8384 # This means that the schema name is the indicator of isolated state, not the target name which may be re-used across multiple schemas.
8485 target_schema = profile .target .schema_
85- gateway_kwargs ["state_schema" ] = f"sqlmesh_state_{ profile_name } _{ target_schema } "
86+
87+ # dbt-core doesnt allow schema to be undefined, but it does allow an empty string, and then just
88+ # fails at runtime when `CREATE SCHEMA ""` doesnt work
89+ if not target_schema :
90+ raise ConfigError (
91+ f"Target '{ profile .target_name } ' does not specify a schema.\n "
92+ "A schema is required in order to infer where to store SQLMesh state"
93+ )
94+
95+ inferred_state_schema_name = f"sqlmesh_state_{ profile_name } _{ target_schema } "
96+ logger .info ("Inferring state schema: %s" , inferred_state_schema_name )
97+ gateway_kwargs ["state_schema" ] = inferred_state_schema_name
8698
8799 return Config (
88100 loader = loader ,
You can’t perform that action at this time.
0 commit comments