activerecord-dbt 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +213 -72
- data/lib/active_record/dbt/column/{test.rb → data_test.rb} +16 -16
- data/lib/active_record/dbt/column/{testable/accepted_values_testable.rb → data_testable/accepted_values_data_testable.rb} +2 -2
- data/lib/active_record/dbt/column/{testable/not_null_testable.rb → data_testable/not_null_data_testable.rb} +9 -3
- data/lib/active_record/dbt/column/{testable/relationships_testable.rb → data_testable/relationships_data_testable.rb} +3 -3
- data/lib/active_record/dbt/column/{testable/unique_testable.rb → data_testable/unique_data_testable.rb} +2 -2
- data/lib/active_record/dbt/column/{column.rb → yml.rb} +9 -20
- data/lib/active_record/dbt/config.rb +2 -30
- data/lib/active_record/dbt/configuration/i18n_configuration.rb +14 -0
- data/lib/active_record/dbt/configuration/source.rb +40 -0
- data/lib/active_record/dbt/data_type/mapper.rb +81 -14
- data/lib/active_record/dbt/dbt_package/dbt_utils/table/{testable/unique_combination_of_columns_testable.rb → data_testable/unique_combination_of_columns_data_testable.rb} +2 -2
- data/lib/active_record/dbt/dbt_package/dbterd/column/{testable → data_testable}/relationships_meta_relationship_type.rb +4 -5
- data/lib/active_record/dbt/factory/columns/yml_factory.rb +33 -0
- data/lib/active_record/dbt/factory/model/staging/yml_factory.rb +24 -0
- data/lib/active_record/dbt/factory/source/yml_factory.rb +17 -0
- data/lib/active_record/dbt/factory/table/yml_factory.rb +18 -0
- data/lib/active_record/dbt/factory/tables/yml_factory.rb +17 -0
- data/lib/active_record/dbt/i18n_wrapper/translate.rb +34 -0
- data/lib/active_record/dbt/model/staging/base.rb +1 -1
- data/lib/active_record/dbt/model/staging/yml.rb +10 -6
- data/lib/active_record/dbt/seed/enum/base.rb +48 -0
- data/lib/active_record/dbt/seed/enum/csv.rb +85 -0
- data/lib/active_record/dbt/seed/enum/yml.rb +128 -0
- data/lib/active_record/dbt/source/yml.rb +13 -5
- data/lib/active_record/dbt/table/{test.rb → data_test.rb} +3 -3
- data/lib/active_record/dbt/table/yml.rb +7 -10
- data/lib/active_record/dbt/version.rb +1 -1
- data/lib/generators/active_record/dbt/config/templates/source_config.yml.tt +5 -2
- data/lib/generators/active_record/dbt/enum/USAGE +9 -0
- data/lib/generators/active_record/dbt/enum/enum_generator.rb +31 -0
- data/lib/generators/active_record/dbt/initializer/templates/dbt.rb +9 -7
- data/lib/generators/active_record/dbt/source/USAGE +1 -1
- data/lib/generators/active_record/dbt/source/source_generator.rb +3 -4
- data/lib/generators/active_record/dbt/staging_model/USAGE +2 -2
- data/lib/generators/active_record/dbt/staging_model/staging_model_generator.rb +2 -2
- metadata +24 -21
- data/lib/active_record/dbt/data_type/dwh_platform/apache_spark.rb +0 -27
- data/lib/active_record/dbt/data_type/dwh_platform/bigquery.rb +0 -26
- data/lib/active_record/dbt/data_type/dwh_platform/postgre_sql.rb +0 -27
- data/lib/active_record/dbt/data_type/dwh_platform/redshift.rb +0 -27
- data/lib/active_record/dbt/data_type/dwh_platform/snowflake.rb +0 -27
- data/lib/active_record/dbt/factory/columns_factory.rb +0 -31
- data/lib/active_record/dbt/factory/model/staging_factory.rb +0 -22
- data/lib/active_record/dbt/factory/source_factory.rb +0 -16
- data/lib/active_record/dbt/factory/table_factory.rb +0 -16
- data/lib/active_record/dbt/factory/tables_factory.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 723d33af77e2e665a7baa13aeebdc892ebca6fad469622494591752e59ff3a4f
|
4
|
+
data.tar.gz: f3ced61ce633c40e8464fd5280f200b062d073f96809fae300de2592c15a10bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38293faab98d461a080d9699401ac8c5fb8f59c8f1f19cda3a8ed082fd0ebc8041aaf13a9a1ecf57e484fd3f66c976404cc1c3697f7b97d8c4ae9106f942f165
|
7
|
+
data.tar.gz: f966416f03dc58ba525488afac7f13df368607f1b57b3b6c6cf206a5ed56cf7757a52d20fab68f9463f9ab754f72eb622667b42e588abb02aa3a255d4e6c4c32
|
data/README.md
CHANGED
@@ -58,6 +58,7 @@ dwh_platform | Specify the data warehouse platform to which dbt connects. The de
|
|
58
58
|
data_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`.
|
59
59
|
logger | The destination for log output. The default is `Logger.new('./log/active_record_dbt.log')`.
|
60
60
|
used_dbt_package_names | An array of `dbt` package names to use.
|
61
|
+
locale | I18n locale. The default is `I18n.locale`.
|
61
62
|
|
62
63
|
List of platforms that can currently be set with `dwh_platform`.
|
63
64
|
|
@@ -83,16 +84,18 @@ Adjust the settings according to your environment.
|
|
83
84
|
```ruby
|
84
85
|
# frozen_string_literal: true
|
85
86
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
87
|
+
if Rails.env.development?
|
88
|
+
require 'active_record/dbt'
|
89
|
+
|
90
|
+
ActiveRecord::Dbt.configure do |c|
|
91
|
+
c.config_directory_path = 'lib/dbt'
|
92
|
+
c.export_directory_path = 'doc/dbt'
|
93
|
+
c.data_sync_delayed = false
|
94
|
+
c.used_dbt_package_names = [
|
95
|
+
'dbt-labs/dbt_utils',
|
96
|
+
'datnguye/dbterd'
|
97
|
+
]
|
98
|
+
end
|
96
99
|
end
|
97
100
|
|
98
101
|
```
|
@@ -109,8 +112,8 @@ This will create the following files.
|
|
109
112
|
|
110
113
|
File | Description
|
111
114
|
--------- | ---------
|
112
|
-
`#{config_directory_path}/source_config.yml` | Used to generate `#{export_directory_path}/src_#{source_name}.yml`.
|
113
|
-
`#{config_directory_path}/staging_model.sql.tt` | Used to generate `#{export_directory_path}/stg_#{source_name}__#{table_name}.sql`.
|
115
|
+
`#{config_directory_path}/source_config.yml` | Used to generate `#{export_directory_path}/models/sources/#{source_name}/src_#{source_name}.yml`.
|
116
|
+
`#{config_directory_path}/staging_model.sql.tt` | Used to generate `#{export_directory_path}/models/staging/#{source_name}/stg_#{source_name}__#{table_name}.sql`.
|
114
117
|
|
115
118
|
### Generate dbt Source File
|
116
119
|
|
@@ -157,7 +160,7 @@ table_overrides:
|
|
157
160
|
period: day
|
158
161
|
columns:
|
159
162
|
created_at:
|
160
|
-
|
163
|
+
data_tests:
|
161
164
|
- not_null:
|
162
165
|
where: 'id != 1'
|
163
166
|
|
@@ -165,10 +168,10 @@ table_overrides:
|
|
165
168
|
|
166
169
|
##### defaults
|
167
170
|
|
168
|
-
Set default
|
171
|
+
Set the default value for the `description`(`logical_name`, `description`) of `tables`.
|
169
172
|
|
170
|
-
In `logical_name` and `description` of `table_descriptions`, you can refer to the table name with `{{ table_name }}`.
|
171
|
-
In the `description` of `columns`, you can refer to the table name with `{{ table_name }}` and the column name with `{{ column_name }}`.
|
173
|
+
In the `logical_name` and `description` of `table_descriptions`, you can refer to the table name with `{{ table_name }}`.
|
174
|
+
In the `description` of `table_descriptions.columns`, you can refer to the table name with `{{ table_name }}` and the column name with `{{ column_name }}`.
|
172
175
|
|
173
176
|
Example:
|
174
177
|
|
@@ -250,7 +253,7 @@ table_overrides:
|
|
250
253
|
period: day
|
251
254
|
columns:
|
252
255
|
created_at:
|
253
|
-
|
256
|
+
data_tests:
|
254
257
|
- not_null:
|
255
258
|
where: 'id != 1'
|
256
259
|
|
@@ -281,7 +284,7 @@ table_descriptions:
|
|
281
284
|
|
282
285
|
```
|
283
286
|
|
284
|
-
#### Generate `#{export_directory_path}/src_#{source_name}.yml`
|
287
|
+
#### Generate `#{export_directory_path}/models/sources/#{source_name}/src_#{source_name}.yml`
|
285
288
|
|
286
289
|
Generate a source file for dbt:
|
287
290
|
|
@@ -289,7 +292,7 @@ Generate a source file for dbt:
|
|
289
292
|
$ bin/rails generate active_record:dbt:source
|
290
293
|
```
|
291
294
|
|
292
|
-
Generate `#{export_directory_path}/src_#{source_name}.yml`.
|
295
|
+
Generate `#{export_directory_path}/models/sources/#{source_name}/src_#{source_name}.yml`.
|
293
296
|
|
294
297
|
##### Example:
|
295
298
|
|
@@ -297,6 +300,14 @@ Generate `#{export_directory_path}/src_#{source_name}.yml`.
|
|
297
300
|
>
|
298
301
|
> The output will be as shown below. It is recommended to indent the YAML file with a tool of your choice.
|
299
302
|
|
303
|
+
> [!WARNING]
|
304
|
+
>
|
305
|
+
> If you are using a version of dbt lower than v1.8, replace `tests:` with `data_tests:` in the generated file.
|
306
|
+
>
|
307
|
+
> [Add data tests to your DAG | dbt Developer Hub](https://docs.getdbt.com/docs/build/data-tests#new-data_tests-syntax)
|
308
|
+
>
|
309
|
+
>> Data tests were historically called "tests" in dbt as the only form of testing available. With the introduction of unit tests in v1.8, the key was renamed from `tests:` to `data_tests:`.
|
310
|
+
|
300
311
|
```yaml
|
301
312
|
---
|
302
313
|
version: 2
|
@@ -317,7 +328,7 @@ sources:
|
|
317
328
|
- name: key
|
318
329
|
description: Key
|
319
330
|
data_type: string
|
320
|
-
|
331
|
+
data_tests:
|
321
332
|
- unique
|
322
333
|
- not_null
|
323
334
|
- name: value
|
@@ -326,12 +337,12 @@ sources:
|
|
326
337
|
- name: created_at
|
327
338
|
description: Created At
|
328
339
|
data_type: datetime
|
329
|
-
|
340
|
+
data_tests:
|
330
341
|
- not_null
|
331
342
|
- name: updated_at
|
332
343
|
description: Updated At
|
333
344
|
data_type: datetime
|
334
|
-
|
345
|
+
data_tests:
|
335
346
|
- not_null
|
336
347
|
- name: companies
|
337
348
|
description: Write a logical_name of the 'companies' table.
|
@@ -339,13 +350,13 @@ sources:
|
|
339
350
|
- name: id
|
340
351
|
description: id
|
341
352
|
data_type: int64
|
342
|
-
|
353
|
+
data_tests:
|
343
354
|
- unique
|
344
355
|
- not_null
|
345
356
|
- name: name
|
346
357
|
description: Write a description of the 'companies.name' column.
|
347
358
|
data_type: string
|
348
|
-
|
359
|
+
data_tests:
|
349
360
|
- not_null
|
350
361
|
- name: establishment_date
|
351
362
|
description: Write a description of the 'companies.establishment_date' column.
|
@@ -356,7 +367,7 @@ sources:
|
|
356
367
|
- name: published
|
357
368
|
description: Write a description of the 'companies.published' column.
|
358
369
|
data_type: bool
|
359
|
-
|
370
|
+
data_tests:
|
360
371
|
- not_null
|
361
372
|
- accepted_values:
|
362
373
|
values:
|
@@ -366,12 +377,12 @@ sources:
|
|
366
377
|
- name: created_at
|
367
378
|
description: Created At
|
368
379
|
data_type: datetime
|
369
|
-
|
380
|
+
data_tests:
|
370
381
|
- not_null
|
371
382
|
- name: updated_at
|
372
383
|
description: Updated At
|
373
384
|
data_type: datetime
|
374
|
-
|
385
|
+
data_tests:
|
375
386
|
- not_null
|
376
387
|
- name: posts
|
377
388
|
description: Post
|
@@ -379,13 +390,13 @@ sources:
|
|
379
390
|
- name: id
|
380
391
|
description: ID
|
381
392
|
data_type: int64
|
382
|
-
|
393
|
+
data_tests:
|
383
394
|
- unique
|
384
395
|
- not_null
|
385
396
|
- name: user_id
|
386
397
|
description: User
|
387
398
|
data_type: int64
|
388
|
-
|
399
|
+
data_tests:
|
389
400
|
- not_null
|
390
401
|
- relationships:
|
391
402
|
to: source('dummy', 'users')
|
@@ -401,17 +412,17 @@ sources:
|
|
401
412
|
- name: created_at
|
402
413
|
description: Post Created At
|
403
414
|
data_type: datetime
|
404
|
-
|
415
|
+
data_tests:
|
405
416
|
- not_null
|
406
417
|
- name: updated_at
|
407
418
|
description: Post Updated At
|
408
419
|
data_type: datetime
|
409
|
-
|
420
|
+
data_tests:
|
410
421
|
- not_null
|
411
422
|
- name: status
|
412
423
|
description: Write a description of the 'posts.status' column.
|
413
424
|
data_type: int64
|
414
|
-
|
425
|
+
data_tests:
|
415
426
|
- accepted_values:
|
416
427
|
values:
|
417
428
|
- 0
|
@@ -420,7 +431,7 @@ sources:
|
|
420
431
|
quote: false
|
421
432
|
- name: posts_tags
|
422
433
|
description: Write a logical_name of the 'posts_tags' table.
|
423
|
-
|
434
|
+
data_tests:
|
424
435
|
- dbt_utils.unique_combination_of_columns:
|
425
436
|
combination_of_columns:
|
426
437
|
- post_id
|
@@ -429,7 +440,7 @@ sources:
|
|
429
440
|
- name: post_id
|
430
441
|
description: post_id
|
431
442
|
data_type: int64
|
432
|
-
|
443
|
+
data_tests:
|
433
444
|
- not_null
|
434
445
|
- relationships:
|
435
446
|
to: source('dummy', 'posts')
|
@@ -442,7 +453,7 @@ sources:
|
|
442
453
|
- name: tag_id
|
443
454
|
description: tag_id
|
444
455
|
data_type: int64
|
445
|
-
|
456
|
+
data_tests:
|
446
457
|
- not_null
|
447
458
|
- relationships:
|
448
459
|
to: source('dummy', 'tags')
|
@@ -458,13 +469,13 @@ sources:
|
|
458
469
|
- name: id
|
459
470
|
description: id
|
460
471
|
data_type: int64
|
461
|
-
|
472
|
+
data_tests:
|
462
473
|
- unique
|
463
474
|
- not_null
|
464
475
|
- name: user_id
|
465
476
|
description: user_id
|
466
477
|
data_type: int64
|
467
|
-
|
478
|
+
data_tests:
|
468
479
|
- unique
|
469
480
|
- not_null
|
470
481
|
- relationships:
|
@@ -475,26 +486,26 @@ sources:
|
|
475
486
|
- name: first_name
|
476
487
|
description: Write a description of the 'profiles.first_name' column.
|
477
488
|
data_type: string
|
478
|
-
|
489
|
+
data_tests:
|
479
490
|
- not_null
|
480
491
|
- name: last_name
|
481
492
|
description: Write a description of the 'profiles.last_name' column.
|
482
493
|
data_type: string
|
483
|
-
|
494
|
+
data_tests:
|
484
495
|
- not_null
|
485
496
|
- name: created_at
|
486
497
|
description: Created At
|
487
498
|
data_type: datetime
|
488
|
-
|
499
|
+
data_tests:
|
489
500
|
- not_null
|
490
501
|
- name: updated_at
|
491
502
|
description: Updated At
|
492
503
|
data_type: datetime
|
493
|
-
|
504
|
+
data_tests:
|
494
505
|
- not_null
|
495
506
|
- name: relationships
|
496
507
|
description: Write a logical_name of the 'relationships' table.
|
497
|
-
|
508
|
+
data_tests:
|
498
509
|
- dbt_utils.unique_combination_of_columns:
|
499
510
|
combination_of_columns:
|
500
511
|
- follower_id
|
@@ -503,13 +514,13 @@ sources:
|
|
503
514
|
- name: id
|
504
515
|
description: id
|
505
516
|
data_type: int64
|
506
|
-
|
517
|
+
data_tests:
|
507
518
|
- unique
|
508
519
|
- not_null
|
509
520
|
- name: follower_id
|
510
521
|
description: follower_id
|
511
522
|
data_type: int64
|
512
|
-
|
523
|
+
data_tests:
|
513
524
|
- not_null
|
514
525
|
- relationships:
|
515
526
|
to: source('dummy', 'users')
|
@@ -519,7 +530,7 @@ sources:
|
|
519
530
|
- name: followed_id
|
520
531
|
description: followed_id
|
521
532
|
data_type: int64
|
522
|
-
|
533
|
+
data_tests:
|
523
534
|
- not_null
|
524
535
|
- relationships:
|
525
536
|
to: source('dummy', 'users')
|
@@ -529,12 +540,12 @@ sources:
|
|
529
540
|
- name: created_at
|
530
541
|
description: Created At
|
531
542
|
data_type: datetime
|
532
|
-
|
543
|
+
data_tests:
|
533
544
|
- not_null
|
534
545
|
- name: updated_at
|
535
546
|
description: Updated At
|
536
547
|
data_type: datetime
|
537
|
-
|
548
|
+
data_tests:
|
538
549
|
- not_null
|
539
550
|
- name: schema_migrations
|
540
551
|
description: |-
|
@@ -545,7 +556,7 @@ sources:
|
|
545
556
|
- name: version
|
546
557
|
description: The version number of the migration.
|
547
558
|
data_type: string
|
548
|
-
|
559
|
+
data_tests:
|
549
560
|
- unique
|
550
561
|
- not_null
|
551
562
|
- name: tags
|
@@ -554,28 +565,28 @@ sources:
|
|
554
565
|
- name: id
|
555
566
|
description: id
|
556
567
|
data_type: int64
|
557
|
-
|
568
|
+
data_tests:
|
558
569
|
- unique
|
559
570
|
- not_null
|
560
571
|
- name: name
|
561
572
|
description: Write a description of the 'tags.name' column.
|
562
573
|
data_type: string
|
563
|
-
|
574
|
+
data_tests:
|
564
575
|
- unique
|
565
576
|
- not_null
|
566
577
|
- name: created_at
|
567
578
|
description: Created At
|
568
579
|
data_type: datetime
|
569
|
-
|
580
|
+
data_tests:
|
570
581
|
- not_null
|
571
582
|
- name: updated_at
|
572
583
|
description: Updated At
|
573
584
|
data_type: datetime
|
574
|
-
|
585
|
+
data_tests:
|
575
586
|
- not_null
|
576
587
|
- name: user_tags
|
577
588
|
description: Write a logical_name of the 'user_tags' table.
|
578
|
-
|
589
|
+
data_tests:
|
579
590
|
- dbt_utils.unique_combination_of_columns:
|
580
591
|
combination_of_columns:
|
581
592
|
- user_id
|
@@ -584,13 +595,13 @@ sources:
|
|
584
595
|
- name: id
|
585
596
|
description: id
|
586
597
|
data_type: int64
|
587
|
-
|
598
|
+
data_tests:
|
588
599
|
- unique
|
589
600
|
- not_null
|
590
601
|
- name: user_id
|
591
602
|
description: user_id
|
592
603
|
data_type: int64
|
593
|
-
|
604
|
+
data_tests:
|
594
605
|
- not_null
|
595
606
|
- relationships:
|
596
607
|
to: source('dummy', 'users')
|
@@ -600,7 +611,7 @@ sources:
|
|
600
611
|
- name: tag_id
|
601
612
|
description: tag_id
|
602
613
|
data_type: int64
|
603
|
-
|
614
|
+
data_tests:
|
604
615
|
- not_null
|
605
616
|
- relationships:
|
606
617
|
to: source('dummy', 'tags')
|
@@ -610,12 +621,12 @@ sources:
|
|
610
621
|
- name: created_at
|
611
622
|
description: Created At
|
612
623
|
data_type: datetime
|
613
|
-
|
624
|
+
data_tests:
|
614
625
|
- not_null
|
615
626
|
- name: updated_at
|
616
627
|
description: Updated At
|
617
628
|
data_type: datetime
|
618
|
-
|
629
|
+
data_tests:
|
619
630
|
- not_null
|
620
631
|
- name: users
|
621
632
|
description: User
|
@@ -631,24 +642,24 @@ sources:
|
|
631
642
|
- name: id
|
632
643
|
description: ID
|
633
644
|
data_type: int64
|
634
|
-
|
645
|
+
data_tests:
|
635
646
|
- unique
|
636
647
|
- not_null
|
637
648
|
- name: created_at
|
638
649
|
description: User Created At
|
639
650
|
data_type: datetime
|
640
|
-
|
651
|
+
data_tests:
|
641
652
|
- not_null:
|
642
653
|
where: id != 1
|
643
654
|
- name: updated_at
|
644
655
|
description: User Updated At
|
645
656
|
data_type: datetime
|
646
|
-
|
657
|
+
data_tests:
|
647
658
|
- not_null
|
648
659
|
- name: company_id
|
649
660
|
description: company_id
|
650
661
|
data_type: int64
|
651
|
-
|
662
|
+
data_tests:
|
652
663
|
- relationships:
|
653
664
|
to: source('dummy', 'companies')
|
654
665
|
field: id
|
@@ -747,8 +758,8 @@ Generate staging model files for dbt that reference the specified `TABLE_NAME`.
|
|
747
758
|
|
748
759
|
File | Description
|
749
760
|
--------- | ---------
|
750
|
-
`#{export_directory_path}/stg_#{source_name}__#{table_name}.sql` | Staging model file for dbt.
|
751
|
-
`#{export_directory_path}/stg_#{source_name}__#{table_name}.yml` | Staging model documentation file for dbt.
|
761
|
+
`#{export_directory_path}/models/staging/#{source_name}/stg_#{source_name}__#{table_name}.sql` | Staging model file for dbt.
|
762
|
+
`#{export_directory_path}/models/staging/#{source_name}/stg_#{source_name}__#{table_name}.yml` | Staging model documentation file for dbt.
|
752
763
|
|
753
764
|
Example:
|
754
765
|
|
@@ -756,7 +767,7 @@ Example:
|
|
756
767
|
$ bin/rails generate active_record:dbt:staging_model profiles
|
757
768
|
```
|
758
769
|
|
759
|
-
##### Generate `#{export_directory_path}/stg_#{source_name}__#{table_name}.sql`
|
770
|
+
##### Generate `#{export_directory_path}/models/staging/#{source_name}/stg_#{source_name}__#{table_name}.sql`
|
760
771
|
|
761
772
|
Example:
|
762
773
|
|
@@ -827,10 +838,22 @@ from final
|
|
827
838
|
|
828
839
|
```
|
829
840
|
|
830
|
-
##### Generate `#{export_directory_path}/stg_#{source_name}__#{table_name}.yml`
|
841
|
+
##### Generate `#{export_directory_path}/models/staging/#{source_name}/stg_#{source_name}__#{table_name}.yml`
|
831
842
|
|
832
843
|
Example:
|
833
844
|
|
845
|
+
> [!NOTE]
|
846
|
+
>
|
847
|
+
> The output will be as shown below. It is recommended to indent the YAML file with a tool of your choice.
|
848
|
+
|
849
|
+
> [!WARNING]
|
850
|
+
>
|
851
|
+
> If you are using a version of dbt lower than v1.8, replace `tests:` with `data_tests:` in the generated file.
|
852
|
+
>
|
853
|
+
> [Add data tests to your DAG | dbt Developer Hub](https://docs.getdbt.com/docs/build/data-tests#new-data_tests-syntax)
|
854
|
+
>
|
855
|
+
>> Data tests were historically called "tests" in dbt as the only form of testing available. With the introduction of unit tests in v1.8, the key was renamed from `tests:` to `data_tests:`.
|
856
|
+
|
834
857
|
```yaml
|
835
858
|
---
|
836
859
|
version: 2
|
@@ -841,7 +864,7 @@ models:
|
|
841
864
|
- name: profile_id
|
842
865
|
description: profile_id
|
843
866
|
data_type: int64
|
844
|
-
|
867
|
+
data_tests:
|
845
868
|
- unique
|
846
869
|
- not_null
|
847
870
|
- relationships:
|
@@ -852,7 +875,7 @@ models:
|
|
852
875
|
- name: user_id
|
853
876
|
description: user_id
|
854
877
|
data_type: int64
|
855
|
-
|
878
|
+
data_tests:
|
856
879
|
- unique
|
857
880
|
- not_null
|
858
881
|
- relationships:
|
@@ -863,26 +886,144 @@ models:
|
|
863
886
|
- name: first_name
|
864
887
|
description: Write a description of the 'profiles.first_name' column.
|
865
888
|
data_type: string
|
866
|
-
|
889
|
+
data_tests:
|
867
890
|
- not_null
|
868
891
|
- name: last_name
|
869
892
|
description: Write a description of the 'profiles.last_name' column.
|
870
893
|
data_type: string
|
871
|
-
|
894
|
+
data_tests:
|
872
895
|
- not_null
|
873
896
|
- name: created_at
|
874
897
|
description: Created At
|
875
898
|
data_type: datetime
|
876
|
-
|
899
|
+
data_tests:
|
877
900
|
- not_null
|
878
901
|
- name: updated_at
|
879
902
|
description: Updated At
|
880
903
|
data_type: datetime
|
881
|
-
|
904
|
+
data_tests:
|
882
905
|
- not_null
|
883
906
|
|
884
907
|
```
|
885
908
|
|
909
|
+
### Generated dbt Seed Files
|
910
|
+
|
911
|
+
#### dbt Seed Configuration
|
912
|
+
|
913
|
+
In the `#{config_directory_path}/source_config.yml` file, describe the properties you want to set for the seed enum.
|
914
|
+
You can configure `defaults` in this file.
|
915
|
+
|
916
|
+
##### defaults
|
917
|
+
|
918
|
+
Set the default value for the `description` of the `seeds` enum.
|
919
|
+
|
920
|
+
In the `description` of `seed_descriptions.enum`, you can refer to the source name with `{{ source_name }}`, the translated table name with `{{ translated_table_name }}`, and the translated column name with `{{ translated_attribute_name }}`.
|
921
|
+
|
922
|
+
Example:
|
923
|
+
|
924
|
+
```yml
|
925
|
+
defaults:
|
926
|
+
seed_descriptions:
|
927
|
+
enum:
|
928
|
+
description: "{{ source_name }} {{ translated_table_name }} {{ translated_attribute_name }} enum"
|
929
|
+
|
930
|
+
```
|
931
|
+
|
932
|
+
If nothing is set, it defaults to the following:
|
933
|
+
|
934
|
+
```yml
|
935
|
+
defaults:
|
936
|
+
seed_descriptions:
|
937
|
+
enum:
|
938
|
+
description: "{{ source_name }} {{ translated_table_name }} {{ translated_attribute_name }} enum"
|
939
|
+
|
940
|
+
```
|
941
|
+
|
942
|
+
#### Generate dbt Seed Enum Files
|
943
|
+
|
944
|
+
Generate seed enum files for dbt:
|
945
|
+
|
946
|
+
```bash
|
947
|
+
$ bin/rails generate active_record:dbt:enum TABLE_NAME ENUM_COLUMN_NAME
|
948
|
+
```
|
949
|
+
|
950
|
+
Generate seed enum files for dbt from the specified `TABLE_NAME` and `ENUM_COLUMN_NAME`.
|
951
|
+
|
952
|
+
File | Description
|
953
|
+
--------- | ---------
|
954
|
+
`#{export_directory_path}/seeds/#{source_name}/seed_#{source_name}__#{table_name_singularize}_enum_#{enum_pluralized}.csv` | Seed enum file for dbt.
|
955
|
+
`#{export_directory_path}/seeds/#{source_name}/seed_#{source_name}__#{table_name_singularize}_enum_#{enum_pluralized}.yml` | Seed enum documentation file for dbt.
|
956
|
+
|
957
|
+
Example:
|
958
|
+
|
959
|
+
```bash
|
960
|
+
$ bin/rails generate active_record:dbt:enum posts status
|
961
|
+
```
|
962
|
+
|
963
|
+
##### Generate `#{export_directory_path}/seeds/#{source_name}/seed_#{source_name}__#{table_name_singularize}_enum_#{enum_pluralized}.csv`
|
964
|
+
|
965
|
+
Example:
|
966
|
+
|
967
|
+
```csv
|
968
|
+
status_before_type_of_cast,status_key,status_en,status_ja
|
969
|
+
0,draft,Draft,下書き
|
970
|
+
1,published,Published,公開
|
971
|
+
2,deleted,Deleted,削除
|
972
|
+
|
973
|
+
```
|
974
|
+
|
975
|
+
##### Generate `#{export_directory_path}/seeds/#{source_name}/seed_#{source_name}__#{table_name_singularize}_enum_#{enum_pluralized}.yml`
|
976
|
+
|
977
|
+
Example:
|
978
|
+
|
979
|
+
> [!NOTE]
|
980
|
+
>
|
981
|
+
> The output will be as shown below. It is recommended to indent the YAML file with a tool of your choice.
|
982
|
+
|
983
|
+
> [!WARNING]
|
984
|
+
>
|
985
|
+
> If you are using a version of dbt lower than v1.8, replace `tests:` with `data_tests:` in the generated file.
|
986
|
+
>
|
987
|
+
> [Add data tests to your DAG | dbt Developer Hub](https://docs.getdbt.com/docs/build/data-tests#new-data_tests-syntax)
|
988
|
+
>
|
989
|
+
>> Data tests were historically called "tests" in dbt as the only form of testing available. With the introduction of unit tests in v1.8, the key was renamed from `tests:` to `data_tests:`.
|
990
|
+
|
991
|
+
```yaml
|
992
|
+
---
|
993
|
+
version: 2
|
994
|
+
seeds:
|
995
|
+
- name: seed_dummy__post_enum_statuses
|
996
|
+
description: dummy Post Status enum
|
997
|
+
config:
|
998
|
+
column_types:
|
999
|
+
status_before_type_of_cast: int64
|
1000
|
+
status_key: string
|
1001
|
+
status_en: string
|
1002
|
+
status_ja: string
|
1003
|
+
columns:
|
1004
|
+
- name: status_before_type_of_cast
|
1005
|
+
description: Status
|
1006
|
+
data_tests:
|
1007
|
+
- unique
|
1008
|
+
- not_null
|
1009
|
+
- name: status_key
|
1010
|
+
description: Status(key)
|
1011
|
+
data_tests:
|
1012
|
+
- unique
|
1013
|
+
- not_null
|
1014
|
+
- name: status_en
|
1015
|
+
description: Status(en)
|
1016
|
+
data_tests:
|
1017
|
+
- unique
|
1018
|
+
- not_null
|
1019
|
+
- name: status_ja
|
1020
|
+
description: Status(ja)
|
1021
|
+
data_tests:
|
1022
|
+
- unique
|
1023
|
+
- not_null
|
1024
|
+
|
1025
|
+
```
|
1026
|
+
|
886
1027
|
## Contributing
|
887
1028
|
|
888
1029
|
Contribution directions go here.
|