{"id":15151183,"url":"https://github.com/yamotech/activerecord-dbt","last_synced_at":"2026-02-10T04:36:09.590Z","repository":{"id":249377593,"uuid":"827310704","full_name":"yamotech/activerecord-dbt","owner":"yamotech","description":"Generate dbt files from the information of the database connected by ActiveRecord.","archived":false,"fork":false,"pushed_at":"2024-12-10T14:56:57.000Z","size":346,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-29T08:41:36.358Z","etag":null,"topics":["dbt","gem","rails","ruby","ruby-on-rails"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/activerecord-dbt","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yamotech.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-11T12:01:20.000Z","updated_at":"2025-01-14T01:01:34.000Z","dependencies_parsed_at":"2024-07-20T11:05:31.514Z","dependency_job_id":"eb9f6847-639d-49ed-91d4-83c2d6345bad","html_url":"https://github.com/yamotech/activerecord-dbt","commit_stats":{"total_commits":193,"total_committers":1,"mean_commits":193.0,"dds":0.0,"last_synced_commit":"28f6cb47587a09b7e008f1468c83997174afdd2e"},"previous_names":["yamotech/activerecord-dbt"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yamotech%2Factiverecord-dbt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yamotech%2Factiverecord-dbt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yamotech%2Factiverecord-dbt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yamotech%2Factiverecord-dbt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yamotech","download_url":"https://codeload.github.com/yamotech/activerecord-dbt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237932070,"owners_count":19389560,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["dbt","gem","rails","ruby","ruby-on-rails"],"created_at":"2024-09-26T15:00:51.472Z","updated_at":"2026-02-10T04:36:09.575Z","avatar_url":"https://github.com/yamotech.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ActiveRecord::Dbt\n\n[![Gem Version](https://badge.fury.io/rb/activerecord-dbt.svg)](https://badge.fury.io/rb/activerecord-dbt)\n[![Maintainability](https://api.codeclimate.com/v1/badges/ef9a0a71c73dae7b8156/maintainability)](https://codeclimate.com/github/yamotech/activerecord-dbt/maintainability)\n[![Ruby CI](https://github.com/yamotech/activerecord-dbt/actions/workflows/ruby-ci.yml/badge.svg)](https://github.com/yamotech/activerecord-dbt/actions/workflows/ruby-ci.yml)\n\n`ActiveRecord::Dbt` generates [dbt](https://www.getdbt.com/) files from the information of the database connected via ActiveRecord.\n\nCurrently, it can generate:\n\n- Sources: `YAML` files\n- Staging models: `SQL` and `YAML` files\n- Seeds: `CSV` and `YAML` files (based on `ActiveRecord` enum values)\n\n\u003e [!WARNING]\n\u003e\n\u003e dbt Version Compatibility\n\u003e\n\u003e Generated files are optimized for dbt v1.10+. For older versions, the following manual changes are required:\n\u003e\n\u003e | dbt Version | Required Changes |\n\u003e |-------------|------------------|\n\u003e | v1.7 or below | Rename `data_tests:` to `tests:` ([reference](https://docs.getdbt.com/docs/build/data-tests#new-data_tests-syntax)) |\n\u003e | v1.9 or below | Move properties from under `config:` to the top level ([reference](https://docs.getdbt.com/docs/dbt-versions/core-upgrade/upgrading-to-v1.10#custom-inputs)) |\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n  - [Configuration](#configuration)\n  - [Generate dbt Source File](#generate-dbt-source-file)\n  - [Generate dbt Staging Files](#generate-dbt-staging-files)\n  - [Generate dbt Seed Files](#generate-dbt-seed-files)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Installation\n\nTo install `activerecord-dbt`, add this line to your application's Gemfile:\n\n```ruby\ngem 'activerecord-dbt'\n```\n\nSince it is only used in the development environment, it is recommended to add it to the development group:\n\n```ruby\ngroup :development do\n  gem 'activerecord-dbt'\nend\n```\n\nThen run:\n\n```bash\n$ bundle\n```\n\nAlternatively, you can install it manually by running:\n\n```bash\n$ gem install activerecord-dbt\n```\n\n## Usage\n\n### Configuration\n\n#### ActiveRecord::Dbt Configuration\n\nCreate an initializer file for dbt:\n\n```bash\n$ bin/rails generate active_record:dbt:initializer\n```\n\nThis will generate the `config/initializers/dbt.rb` file.\n\nConfiguration | Description\n--------- | ---------\nconfig_directory_path | The path to the directory where configuration files are stored. The default is `lib/dbt`.\nexport_directory_path | The path to the directory where files generated by `bin/rails generate active_record:dbt:*` are stored. The default is `doc/dbt`.\ndwh_platform | Specify the data warehouse platform to which dbt connects. The default is `bigquery`.\ndata_sync_delayed | Indicates whether there is a data delay. If set to `true`, `severity: warn` is applied to the `relationships` test. The default is `false`.\nlogger | The destination for log output. The default is `Logger.new('./log/active_record_dbt.log')`.\nused_dbt_package_names | An array of `dbt` package names to use.\nlocale | I18n locale. The default is `I18n.locale`.\n\nList of platforms that can currently be set with `dwh_platform`.\n\nData Warehouse Platform | Link\n--------- | ---------\nbigquery | [BigQuery enterprise data warehouse - Google Cloud](https://cloud.google.com/bigquery?hl=en)\npostgres | [PostgreSQL: The world's most advanced open source database](https://www.postgresql.org/)\nredshift | [Cloud Data Warehouse - Amazon Redshift - AWS](https://aws.amazon.com/redshift/)\nsnowflake | [The Snowflake AI Data Cloud - Mobilize Data, Apps, and AI](https://www.snowflake.com/en/)\nspark | [Apache Spark™ - Unified Engine for large-scale data analytics](https://spark.apache.org/)\n\nList of packages that can currently be set with `used_dbt_package_names`.\n\ndbt Package Name | Link\n--------- | ---------\ndbt-labs/dbt-utils | [dbt-labs/dbt-utils: Utility functions for dbt projects.](https://github.com/dbt-labs/dbt-utils)\ndatnguye/dbterd | [datnguye/dbterd: Generate the ERD as a code from dbt artifacts](https://github.com/datnguye/dbterd)\n\nExample:\n\nAdjust the settings according to your environment.\n\n```ruby\n# frozen_string_literal: true\n\nif Rails.env.development?\n  require 'active_record/dbt'\n\n  ActiveRecord::Dbt.configure do |c|\n    c.config_directory_path = 'lib/dbt'\n    c.export_directory_path = 'doc/dbt'\n    c.data_sync_delayed = false\n    c.used_dbt_package_names = [\n      'dbt-labs/dbt_utils',\n      'datnguye/dbterd'\n    ]\n  end\nend\n\n```\n\n#### Create Configuration Files\n\nCreate configuration files for dbt:\n\n```bash\n$ bin/rails generate active_record:dbt:config\n```\n\nThis will create the following files.\n\nFile | Description\n--------- | ---------\n`#{config_directory_path}/source_config.yml` | Used to generate `#{export_directory_path}/models/sources/#{source_name}/src_#{source_name}.yml`.\n`#{config_directory_path}/staging_model.sql.tt` | Used to generate `#{export_directory_path}/models/staging/#{source_name}/stg_#{source_name}__#{table_name}.sql`.\n\n### Generate dbt Source File\n\n#### dbt Source Configuration\n\nIn the `#{config_directory_path}/source_config.yml` file, describe the properties you want to set for the source.\nYou can configure `sources`, `table_overrides`, `defaults`, and `table_descriptions` in this file.\n\nThe available properties for `sources` and `table_overrides` are detailed in [Source properties | dbt Developer Hub](https://docs.getdbt.com/reference/source-properties).\n\n##### sources\n\nSet the configurations for `sources`.\n\nConfiguration | Description\n--------- | ---------\nproject_name | Written to the beginning of the table or model `description`.\ntable_names in `exclude` | Specify which table names you do not want output in `sources`.\n\nExample:\n\n```yml\nsources:\n  name: dummy\n  description: |-\n    Write a description of the 'dummy' source.\n    You can write multiple lines.\n  config:\n    meta:\n      project_name: dummy_project\n      generated_by: activerecord-dbt\n      exclude:\n        table_names:\n          - ar_internal_metadata\n          - schema_migrations\n\n```\n\n##### table_overrides\n\nSet all properties for `tables` except for `name` and `description`.\n\nExample:\n\n```yml\ntable_overrides:\n  users:\n    config:\n      freshness:\n        warn_after:\n          count: 3\n          period: day\n        error_after:\n          count: 5\n          period: day\n      loaded_at_field: created_at\n    columns:\n      created_at:\n        data_tests:\n          - not_null:\n              where: 'id != 1'\n\n```\n\n##### defaults\n\nSet the default value for the `description`(`logical_name`, `description`) of `tables`.\n\nIn the `logical_name` and `description` fields of `table_descriptions`, you can use `{{ table_name }}` to refer to the table name and `{{ project_name }}` to refer to the project name.\nIn the `description` of `table_descriptions.columns`, you can use `{{ table_name }}` to refer to the table name and `{{ column_name }}` to refer to the column name.\n\nExample:\n\n```yml\ndefaults:\n  table_descriptions:\n    logical_name: Write the logical_name of the '{{ table_name }}' table in '{{ project_name }}'.\n    columns:\n      description: Write a description of the '{{ table_name }}.{{ column_name }}' column.\n\n```\n\nIf nothing is set, it defaults to the following:\n\n```yml\ndefaults:\n  table_descriptions:\n    logical_name: Write the logical_name of the '{{ table_name }}' table in '{{ project_name }}'.\n    columns:\n      description: Write a description of the '{{ table_name }}.{{ column_name }}' column.\n\n```\n\n##### table_descriptions\n\nSet the `name` and `description` for `tables`.\n\nConfiguration | Description\n--------- | ---------\nlogical_name | A title or one-line description to be output in the dbt `description`.\ndescription | A detailed description of `logical_name` to be output in the dbt `description`.\n\nExample:\n\n```yml\ntable_descriptions:\n  ar_internal_metadata:\n    logical_name: Internal Metadata\n    description: |-\n      By default Rails will store information about your Rails environment and schema\n      in an internal table named `ar_internal_metadata`.\n    columns:\n      key: Key\n      value: Value\n      created_at: Created At\n      updated_at: Updated At\n  schema_migrations:\n    logical_name: Schema Migrations\n    description: |-\n      Rails keeps track of which migrations have been committed to the database and\n      stores them in a neighboring table in that same database called `schema_migrations`.\n    columns:\n      version: The version number of the migration.\n\n```\n\nAdjust the settings according to your environment.\n\n```yml\nsources:\n  name: dummy\n  description: |-\n    Write a description of the 'dummy' source.\n    You can write multiple lines.\n  config:\n    meta:\n      project_name: dummy_project\n      generated_by: activerecord-dbt\n      exclude:\n        table_names:\n          - hoges\n\ntable_overrides:\n  users:\n    config:\n      freshness:\n        warn_after:\n          count: 3\n          period: day\n        error_after:\n          count: 5\n          period: day\n      loaded_at_field: created_at\n    columns:\n      created_at:\n        data_tests:\n          - not_null:\n              where: 'id != 1'\n\ndefaults:\n  table_descriptions:\n    logical_name: Write the logical_name of the '{{ table_name }}' table in '{{ project_name }}'.\n    columns:\n      description: Write a description of the '{{ table_name }}.{{ column_name }}' column.\n  seed_descriptions:\n    enum:\n      description: \"{{ project_name }} {{ table_logical_name }} {{ column_description }} enum\"\n\ntable_descriptions:\n  ar_internal_metadata:\n    logical_name: Internal Metadata\n    description: |-\n      By default Rails will store information about your Rails environment and schema\n      in an internal table named `ar_internal_metadata`.\n    columns:\n      key: Key\n      value: Value\n      created_at: Created At\n      updated_at: Updated At\n  schema_migrations:\n    logical_name: Schema Migrations\n    description: |-\n      Rails keeps track of which migrations have been committed to the database and\n      stores them in a neighboring table in that same database called `schema_migrations`.\n    columns:\n      version: The version number of the migration.\n\n```\n\n#### Generate `#{export_directory_path}/models/sources/#{source_name}/src_#{source_name}.yml`\n\nGenerate a source file for dbt:\n\n```bash\n$ bin/rails generate active_record:dbt:source\n```\n\nGenerate `#{export_directory_path}/models/sources/#{source_name}/src_#{source_name}.yml`.\n\nExample:\n\n\u003e [!NOTE]\n\u003e\n\u003e The output will be as shown below. It is recommended to indent the YAML file with a tool of your choice.\n\n```yaml\n---\nversion: 2\nsources:\n- name: dummy\n  description: |-\n    Write a description of the 'dummy' source.\n    You can write multiple lines.\n  config:\n    meta:\n      project_name: dummy_project\n      generated_by: activerecord-dbt\n      exclude:\n        table_names:\n        - hoges\n  tables:\n  - name: ar_internal_metadata\n    description: |-\n      # dummy_project Internal Metadata\n      By default Rails will store information about your Rails environment and schema\n      in an internal table named `ar_internal_metadata`.\n    columns:\n    - name: key\n      description: Key\n      data_type: string\n      data_tests:\n      - unique\n      - not_null\n    - name: value\n      description: Value\n      data_type: string\n    - name: created_at\n      description: Created At\n      data_type: datetime\n      data_tests:\n      - not_null\n    - name: updated_at\n      description: Updated At\n      data_type: datetime\n      data_tests:\n      - not_null\n  - name: companies\n    description: Write the logical_name of the 'companies' table in 'dummy_project'.\n    columns:\n    - name: id\n      description: id\n      data_type: int64\n      data_tests:\n      - unique\n      - not_null\n    - name: name\n      description: Write a description of the 'companies.name' column.\n      data_type: string\n      data_tests:\n      - not_null\n    - name: establishment_date\n      description: Write a description of the 'companies.establishment_date' column.\n      data_type: string\n    - name: average_age\n      description: Write a description of the 'companies.average_age' column.\n      data_type: float64\n    - name: published\n      description: Write a description of the 'companies.published' column.\n      data_type: bool\n      data_tests:\n      - not_null\n      - accepted_values:\n          arguments:\n            values:\n            - true\n            - false\n            quote: false\n    - name: created_at\n      description: Created At\n      data_type: datetime\n      data_tests:\n      - not_null\n    - name: updated_at\n      description: Updated At\n      data_type: datetime\n      data_tests:\n      - not_null\n  - name: posts\n    description: dummy_project Post\n    columns:\n    - name: id\n      description: ID\n      data_type: int64\n      data_tests:\n      - unique\n      - not_null\n    - name: user_id\n      description: User\n      data_type: int64\n      data_tests:\n      - not_null\n      - relationships:\n          arguments:\n            to: source('dummy', 'users')\n            field: id\n            meta:\n              relationship_type: many-to-one\n    - name: title\n      description: Title\n      data_type: string\n    - name: content\n      description: Content\n      data_type: string\n    - name: created_at\n      description: Post Created At\n      data_type: datetime\n      data_tests:\n      - not_null\n    - name: updated_at\n      description: Post Updated At\n      data_type: datetime\n      data_tests:\n      - not_null\n    - name: status\n      description: Status\n      data_type: int64\n      data_tests:\n      - accepted_values:\n          arguments:\n            values:\n            - 0\n            - 1\n            - 2\n            quote: false\n  - name: posts_tags\n    description: Write the logical_name of the 'posts_tags' table in 'dummy_project'.\n    data_tests:\n    - dbt_utils.unique_combination_of_columns:\n        arguments:\n          combination_of_columns:\n          - post_id\n          - tag_id\n    columns:\n    - name: post_id\n      description: post_id\n      data_type: int64\n      data_tests:\n      - not_null\n      - relationships:\n          arguments:\n            to: source('dummy', 'posts')\n            field: id\n            meta:\n              relationship_type: many-to-one\n              active_record_dbt_error:\n                class: NameError\n                message: |-\n                  uninitialized constant PostsTag\n\n                        Object.const_get(camel_cased_word)\n                              ^^^^^^^^^^\n    - name: tag_id\n      description: tag_id\n      data_type: int64\n      data_tests:\n      - not_null\n      - relationships:\n          arguments:\n            to: source('dummy', 'tags')\n            field: id\n            meta:\n              relationship_type: many-to-one\n              active_record_dbt_error:\n                class: NameError\n                message: |-\n                  uninitialized constant PostsTag\n\n                        Object.const_get(camel_cased_word)\n                              ^^^^^^^^^^\n  - name: profiles\n    description: Write the logical_name of the 'profiles' table in 'dummy_project'.\n    columns:\n    - name: id\n      description: id\n      data_type: int64\n      data_tests:\n      - unique\n      - not_null\n    - name: user_id\n      description: user_id\n      data_type: int64\n      data_tests:\n      - unique\n      - not_null\n      - relationships:\n          arguments:\n            to: source('dummy', 'users')\n            field: id\n            meta:\n              relationship_type: one-to-one\n    - name: first_name\n      description: Write a description of the 'profiles.first_name' column.\n      data_type: string\n      data_tests:\n      - not_null\n    - name: last_name\n      description: Write a description of the 'profiles.last_name' column.\n      data_type: string\n      data_tests:\n      - not_null\n    - name: created_at\n      description: Created At\n      data_type: datetime\n      data_tests:\n      - not_null\n    - name: updated_at\n      description: Updated At\n      data_type: datetime\n      data_tests:\n      - not_null\n  - name: relationships\n    description: Write the logical_name of the 'relationships' table in 'dummy_project'.\n    data_tests:\n    - dbt_utils.unique_combination_of_columns:\n        arguments:\n          combination_of_columns:\n          - follower_id\n          - followed_id\n    columns:\n    - name: id\n      description: id\n      data_type: int64\n      data_tests:\n      - unique\n      - not_null\n    - name: follower_id\n      description: follower_id\n      data_type: int64\n      data_tests:\n      - not_null\n      - relationships:\n          arguments:\n            to: source('dummy', 'users')\n            field: id\n            meta:\n              relationship_type: many-to-one\n    - name: followed_id\n      description: followed_id\n      data_type: int64\n      data_tests:\n      - not_null\n      - relationships:\n          arguments:\n            to: source('dummy', 'users')\n            field: id\n            meta:\n              relationship_type: many-to-one\n    - name: created_at\n      description: Created At\n      data_type: datetime\n      data_tests:\n      - not_null\n    - name: updated_at\n      description: Updated At\n      data_type: datetime\n      data_tests:\n      - not_null\n  - name: schema_migrations\n    description: |-\n      # dummy_project Schema Migrations\n      Rails keeps track of which migrations have been committed to the database and\n      stores them in a neighboring table in that same database called `schema_migrations`.\n    columns:\n    - name: version\n      description: The version number of the migration.\n      data_type: string\n      data_tests:\n      - unique\n      - not_null\n  - name: tags\n    description: Write the logical_name of the 'tags' table in 'dummy_project'.\n    columns:\n    - name: id\n      description: id\n      data_type: int64\n      data_tests:\n      - unique\n      - not_null\n    - name: name\n      description: Write a description of the 'tags.name' column.\n      data_type: string\n      data_tests:\n      - unique\n      - not_null\n    - name: created_at\n      description: Created At\n      data_type: datetime\n      data_tests:\n      - not_null\n    - name: updated_at\n      description: Updated At\n      data_type: datetime\n      data_tests:\n      - not_null\n  - name: user_tags\n    description: Write the logical_name of the 'user_tags' table in 'dummy_project'.\n    data_tests:\n    - dbt_utils.unique_combination_of_columns:\n        arguments:\n          combination_of_columns:\n          - user_id\n          - tag_id\n    columns:\n    - name: id\n      description: id\n      data_type: int64\n      data_tests:\n      - unique\n      - not_null\n    - name: user_id\n      description: user_id\n      data_type: int64\n      data_tests:\n      - not_null\n      - relationships:\n          arguments:\n            to: source('dummy', 'users')\n            field: id\n            meta:\n              relationship_type: many-to-one\n    - name: tag_id\n      description: tag_id\n      data_type: int64\n      data_tests:\n      - not_null\n      - relationships:\n          arguments:\n            to: source('dummy', 'tags')\n            field: id\n            meta:\n              relationship_type: many-to-one\n    - name: created_at\n      description: Created At\n      data_type: datetime\n      data_tests:\n      - not_null\n    - name: updated_at\n      description: Updated At\n      data_type: datetime\n      data_tests:\n      - not_null\n  - name: users\n    description: dummy_project User\n    config:\n      freshness:\n        warn_after:\n          count: 3\n          period: day\n        error_after:\n          count: 5\n          period: day\n      loaded_at_field: created_at\n    columns:\n    - name: id\n      description: ID\n      data_type: int64\n      data_tests:\n      - unique\n      - not_null\n    - name: created_at\n      description: User Created At\n      data_type: datetime\n      data_tests:\n      - not_null:\n          where: id != 1\n    - name: updated_at\n      description: User Updated At\n      data_type: datetime\n      data_tests:\n      - not_null\n    - name: company_id\n      description: company_id\n      data_type: int64\n      data_tests:\n      - relationships:\n          arguments:\n            to: source('dummy', 'companies')\n            field: id\n            meta:\n              relationship_type: many-to-one\n\n```\n\n### Generate dbt Staging Files\n\n#### dbt Staging Configuration\n\nIn the `#{config_directory_path}/staging_model.sql.tt` file, write the SQL template for the `staging` model you want to create.\nYou can use `sql.source_name`, `sql.table_name`, `sql.select_column_names`, `sql.primary_key_eql_id?`, and `sql.rename_primary_id` within this file.\n\nExample:\n\n```sql\nwith\n\nsource as (\n\n    select * from {{ source('\u003c%= sql.source_name %\u003e', '\u003c%= sql.table_name %\u003e') }}\n\n),\n\nrenamed as (\n\n    select\n\n        \u003c%- sql.select_column_names.each_with_index do |(column_type, columns), column_type_index| -%\u003e\n          -- \u003c%= column_type %\u003e\n          \u003c%- columns.each_with_index do |column, column_index| -%\u003e\n          \u003c%- is_rename_primary_id = sql.primary_key_eql_id? \u0026\u0026 sql.primary_key?(column.name) -%\u003e\n          \u003c%- is_last_column = column_type_index == sql.select_column_names.size - 1 \u0026\u0026 column_index == columns.size - 1 -%\u003e\n          \u003c%= is_rename_primary_id ? \"id as #{sql.rename_primary_id}\" : column.name %\u003e\u003c% unless is_last_column -%\u003e,\u003c%- end %\u003e\n          \u003c%- if column_type_index != sql.select_column_names.size - 1 \u0026\u0026 column_index == columns.size - 1 -%\u003e\n\n          \u003c%- end -%\u003e\n          \u003c%- end -%\u003e\n        \u003c%- end -%\u003e\n\n    from source\n\n)\n\nselect * from renamed\n\n```\n\nDifferent Pattern:\n\n```sql\n#standardSQL\n\nwith source as (\n  select\n    \u003c%- if sql.primary_key_eql_id? -%\u003e\n    id as \u003c%= sql.rename_primary_id %\u003e\n    , * except(id)\n    \u003c%- else -%\u003e\n    *\n    \u003c%- end -%\u003e\n  from {{ source('\u003c%= sql.source_name %\u003e', '\u003c%= sql.table_name %\u003e') }}\n)\n\n, final as (\n  select\n  \u003c%- sql.select_column_names.each_with_index do |(column_type, columns), column_type_index| -%\u003e\n    -- \u003c%= column_type %\u003e\n    \u003c%- columns.each_with_index do |column, column_index| -%\u003e\n    \u003c% unless column_type_index == 0 \u0026\u0026 column_index == 0 -%\u003e, \u003c%- end %\u003e\u003c%= (sql.primary_key_eql_id? \u0026\u0026 sql.primary_key?(column.name) ? sql.rename_primary_id : column.name) %\u003e\n    \u003c%- if column_type_index != sql.select_column_names.size - 1 \u0026\u0026 column_index == columns.size - 1 -%\u003e\n\n    \u003c%- end -%\u003e\n    \u003c%- end -%\u003e\n  \u003c%- end -%\u003e\n  from source\n)\n\nselect\n  *\nfrom final\n\n```\n\n#### Generate dbt Staging Files\n\nGenerate staging model files for dbt:\n\n```bash\n$ bin/rails generate active_record:dbt:staging_model TABLE_NAME\n```\n\nGenerate staging model files for dbt that reference the specified `TABLE_NAME`.\n\nFile | Description\n--------- | ---------\n`#{export_directory_path}/models/staging/#{source_name}/stg_#{source_name}__#{table_name}.sql` | Staging model file for dbt.\n`#{export_directory_path}/models/staging/#{source_name}/stg_#{source_name}__#{table_name}.yml` | Staging model documentation file for dbt.\n\nExample:\n\n```bash\n$ bin/rails generate active_record:dbt:staging_model profiles\n```\n\n##### Generate `#{export_directory_path}/models/staging/#{source_name}/stg_#{source_name}__#{table_name}.sql`\n\nExample:\n\n```sql\nwith\n\nsource as (\n\n    select * from {{ source('dummy', 'profiles') }}\n\n),\n\nrenamed as (\n\n    select\n\n          -- ids\n          id as profile_id,\n          user_id,\n\n          -- strings\n          first_name,\n          last_name,\n\n          -- datetimes\n          created_at,\n          updated_at\n\n    from source\n\n)\n\nselect * from renamed\n\n```\n\nDifferent Pattern:\n\n```sql\n#standardSQL\n\nwith source as (\n  select\n    id as profile_id\n    , * except(id)\n  from {{ source('dummy', 'profiles') }}\n)\n\n, final as (\n  select\n    -- ids\n    profile_id\n    , user_id\n\n    -- strings\n    , first_name\n    , last_name\n\n    -- datetimes\n    , created_at\n    , updated_at\n  from source\n)\n\nselect\n  *\nfrom final\n\n```\n\n##### Generate `#{export_directory_path}/models/staging/#{source_name}/stg_#{source_name}__#{table_name}.yml`\n\nExample:\n\n\u003e [!NOTE]\n\u003e\n\u003e The output will be as shown below. It is recommended to indent the YAML file with a tool of your choice.\n\n```yaml\n---\nversion: 2\nmodels:\n- name: stg_dummy__profiles\n  description: Write the logical_name of the 'profiles' table in 'dummy_project'.\n  columns:\n  - name: profile_id\n    description: profile_id\n    data_type: int64\n    data_tests:\n    - unique\n    - not_null\n    - relationships:\n        arguments:\n          to: source('dummy', 'profiles')\n          field: id\n          meta:\n            relationship_type: one-to-one\n  - name: user_id\n    description: user_id\n    data_type: int64\n    data_tests:\n    - unique\n    - not_null\n    - relationships:\n        arguments:\n          to: source('dummy', 'users')\n          field: id\n          meta:\n            relationship_type: one-to-one\n  - name: first_name\n    description: Write a description of the 'profiles.first_name' column.\n    data_type: string\n    data_tests:\n    - not_null\n  - name: last_name\n    description: Write a description of the 'profiles.last_name' column.\n    data_type: string\n    data_tests:\n    - not_null\n  - name: created_at\n    description: Created At\n    data_type: datetime\n    data_tests:\n    - not_null\n  - name: updated_at\n    description: Updated At\n    data_type: datetime\n    data_tests:\n    - not_null\n\n```\n\n### Generate dbt Seed Files\n\n#### dbt Seed Configuration\n\nIn the `#{config_directory_path}/source_config.yml` file, describe the properties you want to set for the seed enum.\nYou can configure `defaults` in this file.\n\n##### defaults\n\nSet the default value for the `description` of the `seeds` enum.\n\nIn the `description` of `seed_descriptions.enum`, you can refer to the project name with `{{ project_name }}`, the table logical table name with `{{ table_logical_name }}`, and the column description with `{{ column_description }}`.\n\nExample:\n\n```yml\ndefaults:\n  seed_descriptions:\n    enum:\n      description: \"{{ project_name }} {{ table_logical_name }} {{ column_description }} enum\"\n\n```\n\nIf nothing is set, it defaults to the following:\n\n```yml\ndefaults:\n  seed_descriptions:\n    enum:\n      description: \"{{ project_name }} {{ table_logical_name }} {{ column_description }} enum\"\n\n```\n\n#### Generate dbt Seed Enum Files\n\nGenerate seed enum files for dbt:\n\n```bash\n$ bin/rails generate active_record:dbt:enum TABLE_NAME ENUM_COLUMN_NAME\n```\n\nGenerate seed enum files for dbt from the specified `TABLE_NAME` and `ENUM_COLUMN_NAME`.\n\nFile | Description\n--------- | ---------\n`#{export_directory_path}/seeds/#{source_name}/seed_#{source_name}__#{table_name_singularize}_enum_#{enum_pluralized}.csv` | Seed enum file for dbt.\n`#{export_directory_path}/seeds/#{source_name}/seed_#{source_name}__#{table_name_singularize}_enum_#{enum_pluralized}.yml` | Seed enum documentation file for dbt.\n\nExample:\n\n```bash\n$ bin/rails generate active_record:dbt:enum posts status\n```\n\n##### Generate `#{export_directory_path}/seeds/#{source_name}/seed_#{source_name}__#{table_name_singularize}_enum_#{enum_pluralized}.csv`\n\nExample:\n\n```csv\nstatus_before_type_of_cast,status_key,status_en,status_ja\n0,draft,Draft,下書き\n1,published,Published,公開\n2,deleted,Deleted,削除\n\n```\n\n##### Generate `#{export_directory_path}/seeds/#{source_name}/seed_#{source_name}__#{table_name_singularize}_enum_#{enum_pluralized}.yml`\n\nExample:\n\n\u003e [!NOTE]\n\u003e\n\u003e The output will be as shown below. It is recommended to indent the YAML file with a tool of your choice.\n\n```yaml\n---\nversion: 2\nseeds:\n- name: seed_dummy__post_enum_statuses\n  description: dummy_project Post Status enum\n  config:\n    column_types:\n      status_before_type_of_cast: int64\n      status_key: string\n      status_en: string\n      status_ja: string\n  columns:\n  - name: status_before_type_of_cast\n    description: Status(before_type_of_cast)\n    data_type: int64\n    data_tests:\n    - unique\n    - not_null\n  - name: status_key\n    description: Status(key)\n    data_type: string\n    data_tests:\n    - unique\n    - not_null\n  - name: status_en\n    description: Status(en)\n    data_type: string\n    data_tests:\n    - unique\n    - not_null\n  - name: status_ja\n    description: Status(ja)\n    data_type: string\n    data_tests:\n    - unique\n    - not_null\n\n```\n\n## Contributing\n\nContribution directions go here.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyamotech%2Factiverecord-dbt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyamotech%2Factiverecord-dbt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyamotech%2Factiverecord-dbt/lists"}