{"title":"Medallion architecture with dbt","description":"Turn raw data accessed through Altertable federation into tested, business-ready tables with dbt, reusable business rules, and marts your teams can rely on.","order":10,"askSuggestions":["Should staging models be tables or views?","How do I keep dev runs from overwriting production models?","How do I use an external catalog as a dbt source?"],"navigation":true,"body":{"code":"var Component=(()=>{var m=Object.create;var s=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var f=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),_=(r,e)=>{for(var a in e)s(r,a,{get:e[a],enumerable:!0})},o=(r,e,a,d)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let n of g(e))!y.call(r,n)&&n!==a&&s(r,n,{get:()=>e[n],enumerable:!(d=p(e,n))||d.enumerable});return r};var w=(r,e,a)=>(a=r!=null?m(b(r)):{},o(e||!r||!r.__esModule?s(a,\"default\",{value:r,enumerable:!0}):a,r)),v=r=>o(s({},\"__esModule\",{value:!0}),r);var c=f((T,l)=>{l.exports=_jsx_runtime});var k={};_(k,{default:()=>u,frontmatter:()=>x});var t=w(c()),x={title:\"Medallion architecture with dbt\",description:\"Turn raw data accessed through Altertable federation into tested, business-ready tables with dbt, reusable business rules, and marts your teams can rely on.\",order:10,askSuggestions:[\"Should staging models be tables or views?\",\"How do I keep dev runs from overwriting production models?\",\"How do I use an external catalog as a dbt source?\"]};function h(r){let e={a:\"a\",code:\"code\",h1:\"h1\",h2:\"h2\",li:\"li\",ol:\"ol\",p:\"p\",pre:\"pre\",strong:\"strong\",table:\"table\",tbody:\"tbody\",td:\"td\",th:\"th\",thead:\"thead\",tr:\"tr\",ul:\"ul\",...r.components},{DocsMedallionDiagram:a,DocsPreviewDocument:d,DocsPreviewSection:n}=e;return a||i(\"DocsMedallionDiagram\",!0),d||i(\"DocsPreviewDocument\",!0),n||i(\"DocsPreviewSection\",!0),(0,t.jsxs)(d,{anchors:\"medallion-architecture-with-dbt materialize-at-the-staging-layer before-you-start organize-the-project map-folders-to-altertable-schemas declare-the-bronze-source build-the-silver-models publish-a-gold-mart build-and-verify schedule-dbt-in-altertable\",children:[(0,t.jsxs)(n,{sectionId:\"medallion-architecture-with-dbt\",anchors:\"\",ancestors:\"\",index:\"0\",children:[(0,t.jsx)(e.h1,{id:\"medallion-architecture-with-dbt\",children:\"Medallion architecture with dbt\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"Turn raw orders into tested tables your teams can use to report on sales. With Altertable federation, dbt reads the orders where they already live, without copying them first. Your dbt models then clean them into staging tables in your lakehouse, apply shared business rules, and publish a mart, all running through \",(0,t.jsx)(e.a,{href:\"https://github.com/altertable-ai/dbt-altertable\",children:\"dbt-altertable\"}),\".\"]}),`\n`,(0,t.jsx)(e.p,{children:\"This guide walks through an orders pipeline from a connected database to a completed-orders mart, then uses that mart to calculate daily sales.\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"We recommend following dbt's \",(0,t.jsx)(e.a,{href:\"https://docs.getdbt.com/best-practices/how-we-structure/1-guide-overview?version=2\",children:\"project structure\"}),\": organize models into \",(0,t.jsx)(e.code,{children:\"staging\"}),\", \",(0,t.jsx)(e.code,{children:\"intermediate\"}),\", and \",(0,t.jsx)(e.code,{children:\"marts\"}),\". Medallion names describe the data's role:\"]}),`\n`,(0,t.jsxs)(e.table,{children:[(0,t.jsx)(e.thead,{children:(0,t.jsxs)(e.tr,{children:[(0,t.jsx)(e.th,{children:\"Layer\"}),(0,t.jsx)(e.th,{children:\"dbt equivalent\"}),(0,t.jsx)(e.th,{children:\"Responsibility\"})]})}),(0,t.jsxs)(e.tbody,{children:[(0,t.jsxs)(e.tr,{children:[(0,t.jsx)(e.td,{children:\"Bronze\"}),(0,t.jsx)(e.td,{children:\"Sources\"}),(0,t.jsx)(e.td,{children:\"Read raw records from external catalogs or ingested tables.\"})]}),(0,t.jsxs)(e.tr,{children:[(0,t.jsx)(e.td,{children:\"Silver\"}),(0,t.jsx)(e.td,{children:\"Staging and intermediate models\"}),(0,t.jsx)(e.td,{children:\"Clean, type, and deduplicate raw records into one row per entity, then apply shared business rules.\"})]}),(0,t.jsxs)(e.tr,{children:[(0,t.jsx)(e.td,{children:\"Gold\"}),(0,t.jsx)(e.td,{children:\"Marts\"}),(0,t.jsx)(e.td,{children:\"Publish tested, business-ready tables your dashboards and teams query directly.\"})]})]})]}),`\n`,(0,t.jsxs)(e.p,{children:[\"The pipeline starts at Bronze. Connect an \",(0,t.jsx)(e.a,{href:\"/docs/lakehouse/external-catalogs\",children:\"external catalog\"}),\" and read its raw tables through \",(0,t.jsx)(e.code,{children:\"source()\"}),\", without first copying them into a separate raw schema in Altertable. Already-ingested raw tables work too. Downstream models use \",(0,t.jsx)(e.code,{children:\"ref()\"}),\" to declare their dependencies.\"]}),`\n`]}),(0,t.jsxs)(n,{sectionId:\"materialize-at-the-staging-layer\",anchors:\"\",ancestors:\"\",index:\"1\",children:[(0,t.jsx)(e.h2,{id:\"materialize-at-the-staging-layer\",children:\"Materialize at the staging layer\"}),`\n`,(0,t.jsx)(e.p,{children:\"Use federation for source access and staging tables for repeated analytical work:\"}),`\n`,(0,t.jsx)(a,{}),`\n`,(0,t.jsx)(e.p,{children:\"Each staging build reads the source through Altertable, cleans and types its records, and stores the normalized rows in a managed table. Intermediate models and marts reuse those prepared rows without repeating the cleanup or querying the external source again. The staging refresh still puts load on the source; choose its frequency and scope accordingly.\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"Organize your dbt models into three folders: \",(0,t.jsx)(e.code,{children:\"staging\"}),\" for cleaning source records, \",(0,t.jsx)(e.code,{children:\"intermediate\"}),\" for reusable transformations, and \",(0,t.jsx)(e.code,{children:\"marts\"}),\" for datasets ready for analysis. This guide uses SQL models.\"]}),`\n`,(0,t.jsxs)(e.p,{children:[\"For the staging models, set \",(0,t.jsx)(e.code,{children:\"+materialized: table\"}),\" in \",(0,t.jsx)(e.code,{children:\"dbt_project.yml\"}),\", as shown below. This tells dbt to run each staging query and save its results as a table in Altertable. The next dbt build refreshes that table. Using \",(0,t.jsx)(e.code,{children:\"view\"}),\" would save only the query definition, so reading it would query the external source again.\"]}),`\n`,(0,t.jsxs)(e.p,{children:[\"Federation exposes the data the source retains; it does not create an immutable bronze history. If you need replay after source updates or deletes, retain raw history upstream or \",(0,t.jsx)(e.a,{href:\"/docs/lakehouse/ingest\",children:\"ingest an archival copy\"}),\" before transforming it. Rebuilding a staging table replaces its prior contents.\"]}),`\n`]}),(0,t.jsxs)(n,{sectionId:\"before-you-start\",anchors:\"\",ancestors:\"\",index:\"2\",children:[(0,t.jsx)(e.h2,{id:\"before-you-start\",children:\"Before you start\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[\"Create a writable \",(0,t.jsx)(e.a,{href:\"/docs/lakehouse/catalogs\",children:\"Altertable catalog\"}),\". This example uses \",(0,t.jsx)(e.code,{children:\"analytics\"}),\"; substitute your catalog name throughout.\"]}),`\n`,(0,t.jsxs)(e.li,{children:[\"Install and configure the \",(0,t.jsx)(e.a,{href:\"/docs/lakehouse/modeling/dbt\",children:\"dbt adapter\"}),\" with your \",(0,t.jsx)(e.a,{href:\"/docs/administration/lakehouse-credentials\",children:\"lakehouse credentials\"}),\".\"]}),`\n`,(0,t.jsxs)(e.li,{children:[\"Check the adapter's \",(0,t.jsx)(e.a,{href:\"https://github.com/altertable-ai/dbt-altertable#readme\",children:\"README\"}),\" for current Python and dbt version requirements and supported features. The dbt best-practice links describe project organization.\"]}),`\n`,(0,t.jsxs)(e.li,{children:[\"Connect your source database as an \",(0,t.jsx)(e.a,{href:\"/docs/lakehouse/external-catalogs\",children:\"external catalog\"}),\". This example calls it \",(0,t.jsx)(e.code,{children:\"app_postgres\"}),\" and expects \",(0,t.jsx)(e.code,{children:\"app_postgres.public.orders\"}),\" with \",(0,t.jsx)(e.code,{children:\"id\"}),\", \",(0,t.jsx)(e.code,{children:\"ordered_at\"}),\", \",(0,t.jsx)(e.code,{children:\"amount_cents\"}),\", and \",(0,t.jsx)(e.code,{children:\"status\"}),\", with one row per order and amounts in a single currency. Substitute your external catalog and schema names.\"]}),`\n`]}),`\n`,(0,t.jsx)(e.p,{children:\"Keep raw values and any source identifiers or ingestion timestamps you need to replay and audit data. This example reads a source with one row per order. If your source contains duplicates or multiple versions of each order, deduplicate in staging using the source's change timestamps and delete markers before applying the completed-order rule.\"}),`\n`]}),(0,t.jsxs)(n,{sectionId:\"organize-the-project\",anchors:\"\",ancestors:\"\",index:\"3\",children:[(0,t.jsx)(e.h2,{id:\"organize-the-project\",children:\"Organize the project\"}),`\n`,(0,t.jsx)(e.p,{children:\"Create these files in your dbt project:\"}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-text\",children:`dbt_project.yml\nmodels/\n  staging/\n    app/\n      _sources.yml\n      _models.yml\n      stg_app__orders.sql\n  intermediate/\n    int_orders__completed.sql\n  marts/\n    sales/\n      orders.sql\n      _models.yml\n`})}),`\n`,(0,t.jsxs)(e.p,{children:[\"In \",(0,t.jsx)(e.code,{children:\"dbt_project.yml\"}),\", configure the project and folder defaults:\"]}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-yaml\",children:`name: orders_analytics\nprofile: orders_analytics\n\nmodels:\n  orders_analytics:\n    staging:\n      +schema: staging\n      +materialized: table\n    intermediate:\n      +schema: intermediate\n      +materialized: view\n    marts:\n      +schema: marts\n      +materialized: table\n`})}),`\n`,(0,t.jsxs)(e.p,{children:[\"The key under \",(0,t.jsx)(e.code,{children:\"models\"}),\" must match the project's \",(0,t.jsx)(e.code,{children:\"name\"}),\".\"]}),`\n`]}),(0,t.jsxs)(n,{sectionId:\"map-folders-to-altertable-schemas\",anchors:\"\",ancestors:\"\",index:\"4\",children:[(0,t.jsx)(e.h2,{id:\"map-folders-to-altertable-schemas\",children:\"Map folders to Altertable schemas\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"The adapter's \",(0,t.jsx)(e.code,{children:\"database\"}),\" field identifies an Altertable catalog. \",(0,t.jsx)(e.code,{children:\"schema\"}),\" identifies the target namespace inside it. Set up two targets in \",(0,t.jsx)(e.code,{children:\"~/.dbt/profiles.yml\"}),\", supplying credentials through environment variables:\"]}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-yaml\",children:`orders_analytics:\n  target: dev\n  outputs:\n    dev:\n      type: altertable\n      username: \"{{ env_var('ALTERTABLE_LAKEHOUSE_USERNAME') }}\"\n      password: \"{{ env_var('ALTERTABLE_LAKEHOUSE_PASSWORD') }}\"\n      database: analytics\n      schema: alice_dev\n    prod:\n      type: altertable\n      username: \"{{ env_var('ALTERTABLE_LAKEHOUSE_USERNAME') }}\"\n      password: \"{{ env_var('ALTERTABLE_LAKEHOUSE_PASSWORD') }}\"\n      database: analytics\n      schema: analytics_prod\n`})}),`\n`,(0,t.jsxs)(e.p,{children:[\"Replace \",(0,t.jsx)(e.code,{children:\"alice_dev\"}),\" with a developer-specific name. This example uses one Altertable environment and catalog, with separate output schemas. dbt target names do not create or select Altertable environments; use the appropriate environment's credentials and catalog when separating environments.\"]}),`\n`,(0,t.jsxs)(e.p,{children:[\"Following dbt's \",(0,t.jsx)(e.a,{href:\"https://docs.getdbt.com/best-practices/how-we-structure/6-mapping-folders-to-warehouse?version=2\",children:\"folder-to-schema mapping\"}),\", keep its default \",(0,t.jsx)(e.code,{children:\"<target_schema>_<custom_schema>\"}),\" naming:\"]}),`\n`,(0,t.jsxs)(e.table,{children:[(0,t.jsx)(e.thead,{children:(0,t.jsxs)(e.tr,{children:[(0,t.jsx)(e.th,{children:\"Folder\"}),(0,t.jsx)(e.th,{children:\"Development schema\"}),(0,t.jsx)(e.th,{children:\"Production schema\"})]})}),(0,t.jsxs)(e.tbody,{children:[(0,t.jsxs)(e.tr,{children:[(0,t.jsx)(e.td,{children:(0,t.jsx)(e.code,{children:\"staging\"})}),(0,t.jsx)(e.td,{children:(0,t.jsx)(e.code,{children:\"alice_dev_staging\"})}),(0,t.jsx)(e.td,{children:(0,t.jsx)(e.code,{children:\"analytics_prod_staging\"})})]}),(0,t.jsxs)(e.tr,{children:[(0,t.jsx)(e.td,{children:(0,t.jsx)(e.code,{children:\"intermediate\"})}),(0,t.jsx)(e.td,{children:(0,t.jsx)(e.code,{children:\"alice_dev_intermediate\"})}),(0,t.jsx)(e.td,{children:(0,t.jsx)(e.code,{children:\"analytics_prod_intermediate\"})})]}),(0,t.jsxs)(e.tr,{children:[(0,t.jsx)(e.td,{children:(0,t.jsx)(e.code,{children:\"marts\"})}),(0,t.jsx)(e.td,{children:(0,t.jsx)(e.code,{children:\"alice_dev_marts\"})}),(0,t.jsx)(e.td,{children:(0,t.jsx)(e.code,{children:\"analytics_prod_marts\"})})]})]})]}),`\n`,(0,t.jsxs)(e.p,{children:[\"All these output schemas live in \",(0,t.jsx)(e.code,{children:\"analytics\"}),\". Both targets read \",(0,t.jsx)(e.code,{children:\"app_postgres.public.orders\"}),\" through federation; neither writes models into the external catalog. Avoid replacing dbt's schema-generation macro just to remove the prefix: shared output names can let a development run overwrite production models.\"]}),`\n`,(0,t.jsxs)(e.p,{children:[\"You can use \",(0,t.jsx)(e.code,{children:\"+schema: silver\"}),\" and \",(0,t.jsx)(e.code,{children:\"+schema: gold\"}),\" if your team requires medallion names. Assigning \",(0,t.jsx)(e.code,{children:\"silver\"}),\" to both staging and intermediate puts them in the same schema. Keeping folder names makes those transformation steps easier to distinguish.\"]}),`\n`]}),(0,t.jsxs)(n,{sectionId:\"declare-the-bronze-source\",anchors:\"\",ancestors:\"\",index:\"5\",children:[(0,t.jsx)(e.h2,{id:\"declare-the-bronze-source\",children:\"Declare the bronze source\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"In \",(0,t.jsx)(e.code,{children:\"models/staging/app/_sources.yml\"}),\", point dbt at the table exposed by the external catalog. This source's \",(0,t.jsx)(e.code,{children:\"database\"}),\" differs from the output catalog in your profile:\"]}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-yaml\",children:`version: 2\n\nsources:\n  - name: app\n    database: app_postgres\n    schema: public\n    tables:\n      - name: orders\n        description: Source orders with amounts in cents, in a single currency.\n        columns:\n          - name: id\n            tests:\n              - not_null\n`})}),`\n`,(0,t.jsx)(e.p,{children:\"Declaring a source does not connect the external catalog or create a table. Configure the connection in Altertable first and make sure your dbt credentials can read it. dbt connects to Altertable; Altertable accesses the external system using that catalog's connection.\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"If you already ingest raw orders into \",(0,t.jsx)(e.code,{children:\"analytics.raw.orders\"}),\", use \",(0,t.jsx)(e.code,{children:\"database: analytics\"}),\" and \",(0,t.jsx)(e.code,{children:\"schema: raw\"}),\" in this source definition instead. The transformation models stay the same.\"]}),`\n`]}),(0,t.jsxs)(n,{sectionId:\"build-the-silver-models\",anchors:\"\",ancestors:\"\",index:\"6\",children:[(0,t.jsx)(e.h2,{id:\"build-the-silver-models\",children:\"Build the silver models\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"In \",(0,t.jsx)(e.code,{children:\"models/staging/app/stg_app__orders.sql\"}),\", normalize the source fields with DuckDB-compatible SQL:\"]}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-sql\",children:`select\n    cast(id as bigint) as order_id,\n    cast(ordered_at as timestamp) as ordered_at,\n    cast(amount_cents as decimal(18, 2)) / 100.0 as amount,\n    lower(trim(status)) as status\nfrom {{ source('app', 'orders') }}\n`})}),`\n`,(0,t.jsxs)(e.p,{children:[\"With the folder configuration above, dbt reads \",(0,t.jsx)(e.code,{children:\"app_postgres.public.orders\"}),\" and materializes this model as \",(0,t.jsx)(e.code,{children:\"analytics.alice_dev_staging.stg_app__orders\"}),\" in development. Its \",(0,t.jsx)(e.code,{children:\"source()\"}),\" reference crosses catalogs; downstream \",(0,t.jsx)(e.code,{children:\"ref()\"}),\" references resolve to models in \",(0,t.jsx)(e.code,{children:\"analytics\"}),\".\"]}),`\n`,(0,t.jsxs)(e.p,{children:[\"In \",(0,t.jsx)(e.code,{children:\"models/staging/app/_models.yml\"}),\", test that Silver has one row per order. Bronze records may contain duplicates; the uniqueness check belongs on the prepared staging model:\"]}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-yaml\",children:`version: 2\n\nmodels:\n  - name: stg_app__orders\n    description: Cleaned orders with one row per order.\n    columns:\n      - name: order_id\n        tests:\n          - not_null\n          - unique\n`})}),`\n`,(0,t.jsxs)(e.p,{children:[\"Choose a timestamp convention that matches your source. This example assumes \",(0,t.jsx)(e.code,{children:\"ordered_at\"}),\" is already expressed in the timezone you use for daily reporting.\"]}),`\n`,(0,t.jsxs)(e.p,{children:[\"In \",(0,t.jsx)(e.code,{children:\"models/intermediate/int_orders__completed.sql\"}),\", isolate the completed-order rule:\"]}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-sql\",children:`select\n    order_id,\n    cast(ordered_at as date) as order_date,\n    amount\nfrom {{ ref('stg_app__orders') }}\nwhere status = 'completed'\n`})}),`\n`,(0,t.jsx)(e.p,{children:\"This step gives other models a shared definition of a completed order. Add intermediate models when they isolate useful logic; a small pipeline can go directly from staging to a mart.\"}),`\n`]}),(0,t.jsxs)(n,{sectionId:\"publish-a-gold-mart\",anchors:\"\",ancestors:\"\",index:\"7\",children:[(0,t.jsx)(e.h2,{id:\"publish-a-gold-mart\",children:\"Publish a gold mart\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"In \",(0,t.jsx)(e.code,{children:\"models/marts/sales/orders.sql\"}),\", publish one row per completed order. Following dbt's \",(0,t.jsx)(e.a,{href:\"https://docs.getdbt.com/best-practices/how-we-structure/4-marts\",children:\"mart guidance\"}),\", keep the mart at the order grain so consumers can calculate daily sales or group by other reporting periods:\"]}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-sql\",children:`select\n    order_id,\n    order_date,\n    amount\nfrom {{ ref('int_orders__completed') }}\n`})}),`\n`,(0,t.jsxs)(e.p,{children:[\"In \",(0,t.jsx)(e.code,{children:\"models/marts/sales/_models.yml\"}),\", document the grain and test it:\"]}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-yaml\",children:`version: 2\n\nmodels:\n  - name: orders\n    description: One row per completed order, with amounts in the source currency.\n    columns:\n      - name: order_id\n        tests:\n          - not_null\n          - unique\n      - name: order_date\n        description: Calendar date of the completed order.\n        tests:\n          - not_null\n      - name: amount\n        tests:\n          - not_null\n`})}),`\n`,(0,t.jsx)(e.p,{children:\"These are dbt data tests that query the data, not database constraints. Add business-specific checks for cancellations, refunds, currencies, and late-arriving updates before treating this as a financial reporting model.\"}),`\n`]}),(0,t.jsxs)(n,{sectionId:\"build-and-verify\",anchors:\"\",ancestors:\"\",index:\"8\",children:[(0,t.jsx)(e.h2,{id:\"build-and-verify\",children:\"Build and verify\"}),`\n`,(0,t.jsx)(e.p,{children:\"From the project directory, verify the connection, test the raw input, and build the models:\"}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-bash\",children:`dbt debug --target dev\ndbt test --select source:app.orders --target dev\ndbt build --target dev\n`})}),`\n`,(0,t.jsx)(e.p,{children:\"Source tests query the external system through federation too. Proceed only if they pass. After a successful build, inspect the materialized staging table in Altertable:\"}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-sql\",children:`select *\nfrom analytics.alice_dev_staging.stg_app__orders\nlimit 10;\n`})}),`\n`,(0,t.jsx)(e.p,{children:\"Then calculate daily sales from the development mart. This query aggregates the order-level data into daily metrics:\"}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-sql\",children:`select\n    order_date,\n    count(*) as completed_orders,\n    sum(amount) as completed_order_amount\nfrom analytics.alice_dev_marts.orders\ngroup by order_date\norder by order_date desc;\n`})}),`\n`,(0,t.jsx)(e.p,{children:\"After reviewing the results, run the same source checks and build against production:\"}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-bash\",children:`dbt test --select source:app.orders --target prod\ndbt build --target prod\n`})}),`\n`,(0,t.jsxs)(e.p,{children:[\"Point production queries, insights, and dashboards at \",(0,t.jsx)(e.code,{children:\"analytics.analytics_prod_marts.orders\"}),\". The daily sales query returns dates with completed orders; add a date spine if consumers need rows for days with no orders.\"]}),`\n`]}),(0,t.jsxs)(n,{sectionId:\"schedule-dbt-in-altertable\",anchors:\"\",ancestors:\"\",index:\"9\",children:[(0,t.jsx)(e.h2,{id:\"schedule-dbt-in-altertable\",children:\"Schedule dbt in Altertable\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"Altertable can run this project for you on a schedule with a \",(0,t.jsx)(e.strong,{children:\"dbt task\"}),\". Each run executes a dbt command from a connected repository and writes models into your chosen Altertable catalog.\"]}),`\n`,(0,t.jsxs)(e.ol,{children:[`\n`,(0,t.jsxs)(e.li,{children:[\"Commit the dbt project to a \",(0,t.jsx)(e.a,{href:\"/docs/agents/knowledge/entries#dbt-repositories\",children:\"connected knowledge repository\"}),\".\"]}),`\n`,(0,t.jsxs)(e.li,{children:[\"Open \",(0,t.jsx)(e.strong,{children:\"Tasks\"}),\", open the \",(0,t.jsx)(e.strong,{children:\"New task\"}),\" menu, and choose \",(0,t.jsx)(e.strong,{children:\"dbt task\"}),\".\"]}),`\n`,(0,t.jsxs)(e.li,{children:[\"Select your \",(0,t.jsx)(e.strong,{children:\"Repository\"}),\". Set \",(0,t.jsx)(e.strong,{children:\"Project directory\"}),\" if \",(0,t.jsx)(e.code,{children:\"dbt_project.yml\"}),\" is in a subdirectory; otherwise leave it empty. Set \",(0,t.jsx)(e.strong,{children:\"Git ref\"}),\" to the branch, tag, or commit you want to run, or leave it empty for the default branch.\"]}),`\n`,(0,t.jsx)(e.li,{children:\"Configure the command and destination:\"}),`\n`]}),`\n`,(0,t.jsxs)(e.table,{children:[(0,t.jsx)(e.thead,{children:(0,t.jsxs)(e.tr,{children:[(0,t.jsx)(e.th,{children:\"Field\"}),(0,t.jsx)(e.th,{children:\"Value for this guide\"}),(0,t.jsx)(e.th,{children:\"Purpose\"})]})}),(0,t.jsxs)(e.tbody,{children:[(0,t.jsxs)(e.tr,{children:[(0,t.jsx)(e.td,{children:\"dbt command\"}),(0,t.jsx)(e.td,{children:(0,t.jsx)(e.code,{children:\"build\"})}),(0,t.jsx)(e.td,{children:\"Build the models and run their tests.\"})]}),(0,t.jsxs)(e.tr,{children:[(0,t.jsx)(e.td,{children:\"Selector\"}),(0,t.jsx)(e.td,{children:(0,t.jsx)(e.code,{children:\"*\"})}),(0,t.jsx)(e.td,{children:\"Include all models in this example project.\"})]}),(0,t.jsxs)(e.tr,{children:[(0,t.jsx)(e.td,{children:\"Target\"}),(0,t.jsx)(e.td,{children:(0,t.jsx)(e.code,{children:\"prod\"})}),(0,t.jsxs)(e.td,{children:[\"Expose \",(0,t.jsx)(e.code,{children:\"prod\"}),\" as \",(0,t.jsx)(e.code,{children:\"target.name\"}),\" in the project.\"]})]}),(0,t.jsxs)(e.tr,{children:[(0,t.jsx)(e.td,{children:\"Catalog\"}),(0,t.jsx)(e.td,{children:(0,t.jsx)(e.code,{children:\"analytics\"})}),(0,t.jsx)(e.td,{children:\"Store the resulting tables and views in Altertable.\"})]}),(0,t.jsxs)(e.tr,{children:[(0,t.jsx)(e.td,{children:\"Schema\"}),(0,t.jsx)(e.td,{children:(0,t.jsx)(e.code,{children:\"analytics_prod\"})}),(0,t.jsx)(e.td,{children:\"Set the base schema used by dbt's custom schema naming.\"})]})]})]}),`\n`,(0,t.jsxs)(e.p,{children:[\"With the project's \",(0,t.jsx)(e.code,{children:\"+schema\"}),\" settings, the outputs go into \",(0,t.jsx)(e.code,{children:\"analytics_prod_staging\"}),\", \",(0,t.jsx)(e.code,{children:\"analytics_prod_intermediate\"}),\", and \",(0,t.jsx)(e.code,{children:\"analytics_prod_marts\"}),\". The \",(0,t.jsx)(e.strong,{children:\"Target\"}),\" name and destination are separate settings: entering \",(0,t.jsx)(e.code,{children:\"prod\"}),\" does not select a catalog or schema for you.\"]}),`\n`,(0,t.jsxs)(e.ol,{start:\"5\",children:[`\n`,(0,t.jsxs)(e.li,{children:[\"Choose \",(0,t.jsx)(e.strong,{children:\"Hourly\"}),\", \",(0,t.jsx)(e.strong,{children:\"Daily\"}),\", \",(0,t.jsx)(e.strong,{children:\"Weekly\"}),\", or \",(0,t.jsx)(e.strong,{children:\"Custom cron\"}),\" in \",(0,t.jsx)(e.strong,{children:\"Schedule\"}),\". Schedule times are in UTC. For example, \",(0,t.jsx)(e.code,{children:\"0 6 * * *\"}),\" runs every day at 06:00 UTC. Choose a time after your upstream data is ready.\"]}),`\n`,(0,t.jsx)(e.li,{children:\"Create the task. You can also leave it on a manual schedule, run it from its task page, and inspect the run history before setting up recurring runs.\"}),`\n`]}),`\n`,(0,t.jsxs)(e.p,{children:[\"Each scheduled build refreshes the staging tables from the federated source, then builds the dependent intermediate models and marts. For a larger project, narrow \",(0,t.jsx)(e.strong,{children:\"Selector\"}),\" to the models or tags you want to refresh. The task also supports \",(0,t.jsx)(e.code,{children:\"run\"}),\" for model execution without tests and \",(0,t.jsx)(e.strong,{children:\"source freshness\"}),\" for checking configured source freshness thresholds.\"]}),`\n`,(0,t.jsxs)(e.p,{children:[\"Repository knowledge sync and dbt execution are separate: \",(0,t.jsx)(e.a,{href:\"/docs/lakehouse/modeling/dbt#sync-project-knowledge\",children:\"syncing project metadata\"}),\" makes definitions and lineage available to Altertable; the dbt task executes the transformations. See \",(0,t.jsx)(e.a,{href:\"/docs/automation/tasks\",children:\"Tasks\"}),\" for more about scheduled work.\"]})]})]})}function u(r={}){let{wrapper:e}=r.components||{};return e?(0,t.jsx)(e,{...r,children:(0,t.jsx)(h,{...r})}):h(r)}function i(r,e){throw new Error(\"Expected \"+(e?\"component\":\"object\")+\" `\"+r+\"` to be defined: you likely forgot to import, pass, or provide it.\")}return v(k);})();\n;return Component;"},"_id":"docs/lakehouse/modeling/medallion-architecture.mdx","_raw":{"sourceFilePath":"docs/lakehouse/modeling/medallion-architecture.mdx","sourceFileName":"medallion-architecture.mdx","sourceFileDir":"docs/lakehouse/modeling","contentType":"mdx","flattenedPath":"docs/lakehouse/modeling/medallion-architecture"},"type":"Docs","path":"/lakehouse/modeling/medallion-architecture","level":3,"parent":"lakehouse/modeling"}