{"id":23886128,"url":"https://github.com/dpguthrie/dbt-multi-tenant-example","last_synced_at":"2026-02-26T23:33:12.637Z","repository":{"id":42463335,"uuid":"476754351","full_name":"dpguthrie/dbt-multi-tenant-example","owner":"dpguthrie","description":null,"archived":false,"fork":false,"pushed_at":"2022-10-03T15:18:00.000Z","size":32,"stargazers_count":5,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-23T03:28:55.096Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dpguthrie.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-04-01T14:31:59.000Z","updated_at":"2024-10-30T03:56:48.000Z","dependencies_parsed_at":"2023-01-19T01:05:17.159Z","dependency_job_id":null,"html_url":"https://github.com/dpguthrie/dbt-multi-tenant-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dpguthrie/dbt-multi-tenant-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpguthrie%2Fdbt-multi-tenant-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpguthrie%2Fdbt-multi-tenant-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpguthrie%2Fdbt-multi-tenant-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpguthrie%2Fdbt-multi-tenant-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dpguthrie","download_url":"https://codeload.github.com/dpguthrie/dbt-multi-tenant-example/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpguthrie%2Fdbt-multi-tenant-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29876981,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-26T22:37:10.609Z","status":"ssl_error","status_checked_at":"2026-02-26T22:37:09.019Z","response_time":89,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-04T05:56:51.040Z","updated_at":"2026-02-26T23:33:12.613Z","avatar_url":"https://github.com/dpguthrie.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Schema-Based Multitenancy\n\nThis project is meant to showcase options for data modeling where each customer has their own individual schema within a database\n\n**Update (9/29/22) - [Another option](#option-3-best-of-both-worlds) was added that the loom video below and code within this repo does not cover.**\n\n## Loom\n\nWatch a ~15 minute video detailing the options below:  https://www.loom.com/share/0461b3473e34495586fbeed54671425e\n\n## Requirements\n\nThe [dbt_utils](https://hub.getdbt.com/dbt-labs/dbt_utils/latest/) package is used in this project.  Specifically:\n\n- [`get_relations_by_pattern`](https://github.com/dbt-labs/dbt-utils/tree/0.8.2/#get_relations_by_pattern-source)\n- [`star`](https://github.com/dbt-labs/dbt-utils/tree/0.8.2/#star-source)\n- [`union_relations`](https://github.com/dbt-labs/dbt-utils/tree/0.8.2/#union_relations-source)\n\n## Options\n\nEach of the options have a couple shared requirements:\n\n- [`union_source`](macros/union_source.sql) macro will be used to create staging models that contain data for all customers\n- [`customer_model`](macros/customer_model.sql) macro will be used to select from the \"master\" table (contains all customer data) and filter down to the appropriate customer.\n\n### Option 1 (Explicit But Hard to Maintain)\n\nThis option requires that you explicitly create the models you'd like to replicate for each customer.  Some basic math:\n\n- 5 dim/fct models to replicate for each customer\n- 100 customers\n- 500 models you'll need to create\n- Each model will have to be prefixed with the customer (`cust_1_dim_customers.sql`, `cust_2_dim_customers.sql`, ..., `cust_n_dim_customers.sql`)\n\nThe benefit here is that we have explicitly defined our models and they'll be included in our lineage graph.  The downside of this approach is that it is not scalable and becomes very hard to maintain as more customers are added.\n\n### Option 2 (Programmatic But Not Explicit)\n\nThis option requires that we create those same customer-specific fct/dim models through the use of a macro.  The macro will loop through each customer schema and defined set of models\nand create tables by explicitly defining DDL.  We'll lose the lineage here but will be much more scalable as both customers and models to share increase.\n\nThe job for this option should be defined with at least the following commands (and in this order):\n\n1. dbt run\n2. dbt run-operation create_customer_tables\n\nThe first command will create the tables containing all customer data and the second command will run the macro to create customer-specific models.\n\n### Option 3 (Best of Both Worlds)\n\nThis option would leverage a package called [dbt-dynamic-models](https://github.com/dpguthrie/dbt-dynamic-models).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdpguthrie%2Fdbt-multi-tenant-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdpguthrie%2Fdbt-multi-tenant-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdpguthrie%2Fdbt-multi-tenant-example/lists"}