|
| 1 | +# M2 Target Schema And This Compile Context Slice |
| 2 | + |
| 3 | +This slice extends dxt's render-only compiler with a narrow profile-derived |
| 4 | +target context and current-model relation context. It does not execute SQL, |
| 5 | +validate credentials, implement custom schema or alias generation, render |
| 6 | +arbitrary Jinja expressions, or open adapter connections. |
| 7 | + |
| 8 | +## Upstream References |
| 9 | + |
| 10 | +dbt Core v1, branch `1.latest`, commit `566b75d`: |
| 11 | + |
| 12 | +- `core/dbt/config/profile.py::Profile.render_profile` selects the target from |
| 13 | + CLI override, profile `target:`, then `default`. |
| 14 | +- `core/dbt/config/profile.py::Profile.to_target_dict` exposes selected target |
| 15 | + credentials plus `type`, `threads`, `name`, `target_name`, and |
| 16 | + `profile_name`. |
| 17 | +- `core/dbt/context/target.py::TargetContext.target` defines the shared |
| 18 | + `target` context, including `name`, `schema`, `type`, and `threads`. |
| 19 | +- `core/dbt/context/providers.py::ModelContext.this` exposes the current model |
| 20 | + as an adapter relation; its documented values include `{{ this }}`, |
| 21 | + `{{ this.schema }}`, `{{ this.table }}`, and `{{ this.name }}`. |
| 22 | +- `core/dbt/context/providers.py::generate_parser_model_context` and |
| 23 | + `generate_runtime_model_context` keep the model context shape stable while |
| 24 | + provider behavior changes between parse and runtime. |
| 25 | +- `core/dbt/parser/base.py::ConfiguredParser.update_parsed_node_relation_names` |
| 26 | + and `_update_node_relation_name` assign relation names through the adapter |
| 27 | + relation class after database, schema, and alias resolution. |
| 28 | +- `core/dbt/compilation.py::Compiler._create_node_context`, `_compile_code`, |
| 29 | + and `compile_node` render raw SQL through the model context before writing |
| 30 | + compiled output. |
| 31 | + |
| 32 | +dbt Core v2 / Fusion foundation, branch `main`, commit `0529e06`: |
| 33 | + |
| 34 | +- `crates/dbt-profile/src/resolve.rs::resolve_target`, |
| 35 | + `resolve_with_env`, `ResolvedProfile::schema`, and |
| 36 | + `ResolvedProfile::database` keep profile target resolution and default |
| 37 | + database/schema identity as data. |
| 38 | +- `crates/dbt-jinja-utils/src/phases/utils.rs::build_target_context_map` |
| 39 | + inserts `profile_name`, `name`, and `target_name` into the target map. |
| 40 | +- `crates/dbt-schemas/src/schemas/profiles.rs::TargetContext`, |
| 41 | + `CommonTargetContext`, and `TryFrom<DbConfig> for TargetContext` define |
| 42 | + common `database`, `schema`, `type`, and `threads`; DuckDB defaults missing |
| 43 | + schema to `main`. |
| 44 | +- `crates/dbt-jinja-utils/src/phases/compile/compile_node_context.rs` builds |
| 45 | + compile-time `this` relation data and exposes `this`, `database`, `schema`, |
| 46 | + and `identifier`. |
| 47 | +- `crates/dbt-jinja-ctx/src/compile.rs::CompileNodeCtx` defines the typed |
| 48 | + compile context contract. |
| 49 | +- `crates/dbt-adapter/src/relation/relation_impl.rs` and |
| 50 | + `crates/dbt-schemas/src/schemas/relations/base.rs` define adapter relation |
| 51 | + rendering and include-policy behavior. |
| 52 | + |
| 53 | +## dxt Ownership |
| 54 | + |
| 55 | +- `src/project/profile.zig` parses selected profile output scalar `type` and |
| 56 | + now scalar `schema`. |
| 57 | +- `src/project/types.zig` carries `Graph.target_schema` and |
| 58 | + `AdapterIdentity.target_schema`. |
| 59 | +- `src/project/loader.zig` copies profile-derived target schema into the graph |
| 60 | + before parser and compiler use. |
| 61 | +- `src/project/compiler.zig` owns the render-only relation formatter and the |
| 62 | + narrow `target.*` / `this` expression surface. |
| 63 | +- `src/project.zig` keeps the compile orchestration path and assigns manifest |
| 64 | + `relation_name` through the compiler. |
| 65 | + |
| 66 | +## Supported Surface |
| 67 | + |
| 68 | +- Select profile from CLI `--profile`, falling back to `dbt_project.yml` |
| 69 | + `profile:`. |
| 70 | +- Select target from CLI `--target`, falling back to profile `target:`, then |
| 71 | + `default`. |
| 72 | +- Read selected output scalar `schema`; default to `main` only for selected |
| 73 | + DuckDB targets when missing. |
| 74 | +- Render supported model/ref relations with the graph target schema. |
| 75 | +- Render literal compile expressions: |
| 76 | + - `target.name` |
| 77 | + - `target.target_name` |
| 78 | + - `target.schema` |
| 79 | + - `target.type` |
| 80 | + - `target.profile_name` |
| 81 | + - `this` |
| 82 | + - `this.schema` |
| 83 | + - `this.name` |
| 84 | + - `this.table` |
| 85 | + - `this.identifier` |
| 86 | + |
| 87 | +## Unsupported Surface |
| 88 | + |
| 89 | +- General Jinja expression evaluation, filters, indexing, conditionals, loops, |
| 90 | + concatenation, macro execution, and adapter calls. |
| 91 | +- Adapter-specific target fields such as database, dbname, project, dataset, |
| 92 | + host, user, warehouse, or role. |
| 93 | +- Node-level custom schema, alias, database, config rendering, and |
| 94 | + `generate_schema_name` / `generate_alias_name` / `generate_database_name`. |
| 95 | +- Ephemeral/deferred/unit-test `this`, operation context, source freshness |
| 96 | + context, hooks, and materialization runtime behavior. |
| 97 | +- Adapter include policy beyond the current two-part quoted |
| 98 | + `schema.identifier` model relation format. |
| 99 | + |
| 100 | +## Validation |
| 101 | + |
| 102 | +- Native Zig tests cover profile schema extraction/defaulting, target-schema |
| 103 | + relation rendering for refs, and compile rendering for `target.*` plus |
| 104 | + `this` fields. |
| 105 | +- Pytest fixture `profile_target_context` validates the native CLI compile |
| 106 | + path, selected profile target schema/type/name/profile fields, ref rendering, |
| 107 | + compiled SQL files, manifest `relation_name`, and manifest schema slice. |
| 108 | +- Schema validation is run against the fixture `manifest.json`. |
| 109 | + |
| 110 | +## Stop Conditions |
| 111 | + |
| 112 | +- Stop before adding arbitrary Jinja expression support. |
| 113 | +- Stop before implementing custom schema/alias/database semantics. |
| 114 | +- Stop before adding live adapter connections, materialization SQL execution, |
| 115 | + catalog introspection, or run-results artifacts. |
| 116 | +- Stop if a fixture requires secrets, private profile values, live credentials, |
| 117 | + or local absolute paths. |
0 commit comments