activerecord-dbt 0.1.0 → 0.3.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 +192 -106
- data/lib/active_record/dbt/column/column.rb +4 -13
- data/lib/active_record/dbt/column/testable/accepted_values_testable.rb +3 -7
- data/lib/active_record/dbt/column/testable/not_null_testable.rb +9 -7
- data/lib/active_record/dbt/column/testable/relationships_testable.rb +4 -8
- data/lib/active_record/dbt/column/testable/unique_testable.rb +2 -6
- data/lib/active_record/dbt/config.rb +3 -30
- data/lib/active_record/dbt/configuration/dwh_platform.rb +39 -0
- 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 +103 -0
- data/lib/active_record/dbt/dbt_package/dbt_utils/table/testable/unique_combination_of_columns_testable.rb +18 -11
- data/lib/active_record/dbt/dbt_package/dbterd/column/testable/relationships_meta_relationship_type.rb +22 -19
- data/lib/active_record/dbt/factory/model/staging_factory.rb +3 -3
- data/lib/active_record/dbt/factory/source_factory.rb +1 -2
- data/lib/active_record/dbt/i18n_wrapper/translate.rb +34 -0
- data/lib/active_record/dbt/model/staging/yml.rb +10 -6
- data/lib/active_record/dbt/required_methods.rb +17 -0
- 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 +6 -2
- data/lib/active_record/dbt/table/yml.rb +1 -4
- data/lib/active_record/dbt/version.rb +1 -1
- data/lib/active_record/dbt.rb +0 -2
- data/lib/generators/active_record/dbt/config/templates/source_config.yml.tt +3 -0
- 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 +1 -0
- data/lib/generators/active_record/dbt/staging_model/staging_model_generator.rb +2 -2
- metadata +13 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: affd8c9f9864d11cbaf5c35a759ea603c72784b9eae777987debad89fd8cd509
|
4
|
+
data.tar.gz: 6b8ca507c1e413143f3d0a7330451767190b3acb731e70c8b2beb87bff9df64b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2798392f8cdcb454a64957a005d7d16e3eeec7e1648234ba5c598cbacb6b683198493337619c9e0a9f17f67a231f6a3fc6f34658651671de3776c7caf28093c9
|
7
|
+
data.tar.gz: d417dfdd69d8a0c41baee03a41a0880ecba05abbbb61c86b80ed1ef48021bcdda16a4e2b43dd414a29d7f56ad9cf92a0e3afe0a693b5ae4aa3a38e0bbeb9f03d
|
data/README.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# ActiveRecord::Dbt
|
2
2
|
|
3
|
-
|
3
|
+
[](https://badge.fury.io/rb/activerecord-dbt)
|
4
|
+
[](https://codeclimate.com/github/yamotech/activerecord-dbt/maintainability)
|
5
|
+
[](https://github.com/yamotech/activerecord-dbt/actions/workflows/ruby-ci.yml)
|
6
|
+
|
7
|
+
`ActiveRecord::Dbt` generates [dbt](https://www.getdbt.com/) files from the information of the database connected via ActiveRecord.
|
4
8
|
|
5
9
|
Currently, it can generate `yaml` files for `sources` and `models` files for `staging`.
|
6
10
|
|
@@ -50,9 +54,28 @@ Configuration | Description
|
|
50
54
|
--------- | ---------
|
51
55
|
config_directory_path | The path to the directory where files generated by `bin/rails generate active_record:dbt:*` are stored. The default is `lib/dbt`.
|
52
56
|
export_directory_path | The path to the directory where configuration files are stored. The default is `doc/dbt`.
|
57
|
+
dwh_platform | Specify the data warehouse platform to which dbt connects. The default is `bigquery`.
|
53
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`.
|
54
59
|
logger | The destination for log output. The default is `Logger.new('./log/active_record_dbt.log')`.
|
55
60
|
used_dbt_package_names | An array of `dbt` package names to use.
|
61
|
+
locale | I18n locale. The default is `I18n.locale`.
|
62
|
+
|
63
|
+
List of platforms that can currently be set with `dwh_platform`.
|
64
|
+
|
65
|
+
Data Warehouse Platform | Link
|
66
|
+
--------- | ---------
|
67
|
+
bigquery | [BigQuery enterprise data warehouse - Google Cloud](https://cloud.google.com/bigquery?hl=en)
|
68
|
+
postgres | [PostgreSQL: The world's most advanced open source database](https://www.postgresql.org/)
|
69
|
+
redshift | [Cloud Data Warehouse - Amazon Redshift - AWS](https://aws.amazon.com/redshift/)
|
70
|
+
snowflake | [The Snowflake AI Data Cloud - Mobilize Data, Apps, and AI](https://www.snowflake.com/en/)
|
71
|
+
spark | [Apache Spark™ - Unified Engine for large-scale data analytics](https://spark.apache.org/)
|
72
|
+
|
73
|
+
List of packages that can currently be set with `used_dbt_package_names`.
|
74
|
+
|
75
|
+
dbt Package Name | Link
|
76
|
+
--------- | ---------
|
77
|
+
dbt-labs/dbt-utils | [dbt-labs/dbt-utils: Utility functions for dbt projects.](https://github.com/dbt-labs/dbt-utils)
|
78
|
+
datnguye/dbterd | [datnguye/dbterd: Generate the ERD as a code from dbt artifacts](https://github.com/datnguye/dbterd)
|
56
79
|
|
57
80
|
Example:
|
58
81
|
|
@@ -143,10 +166,10 @@ table_overrides:
|
|
143
166
|
|
144
167
|
##### defaults
|
145
168
|
|
146
|
-
Set default
|
169
|
+
Set the default value for the `description`(`logical_name`, `description`) of `tables`.
|
147
170
|
|
148
|
-
In `logical_name` and `description` of `table_descriptions`, you can refer to the table name with `{{ table_name }}`.
|
149
|
-
In the `description` of `columns`, you can refer to the table name with `{{ table_name }}` and the column name with `{{ column_name }}`.
|
171
|
+
In the `logical_name` and `description` of `table_descriptions`, you can refer to the table name with `{{ table_name }}`.
|
172
|
+
In the `description` of `table_descriptions.columns`, you can refer to the table name with `{{ table_name }}` and the column name with `{{ column_name }}`.
|
150
173
|
|
151
174
|
Example:
|
152
175
|
|
@@ -294,25 +317,21 @@ sources:
|
|
294
317
|
columns:
|
295
318
|
- name: key
|
296
319
|
description: Key
|
297
|
-
|
298
|
-
column_type: string
|
320
|
+
data_type: string
|
299
321
|
tests:
|
300
322
|
- unique
|
301
323
|
- not_null
|
302
324
|
- name: value
|
303
325
|
description: Value
|
304
|
-
|
305
|
-
column_type: string
|
326
|
+
data_type: string
|
306
327
|
- name: created_at
|
307
328
|
description: Created At
|
308
|
-
|
309
|
-
column_type: datetime
|
329
|
+
data_type: datetime
|
310
330
|
tests:
|
311
331
|
- not_null
|
312
332
|
- name: updated_at
|
313
333
|
description: Updated At
|
314
|
-
|
315
|
-
column_type: datetime
|
334
|
+
data_type: datetime
|
316
335
|
tests:
|
317
336
|
- not_null
|
318
337
|
- name: companies
|
@@ -320,29 +339,24 @@ sources:
|
|
320
339
|
columns:
|
321
340
|
- name: id
|
322
341
|
description: id
|
323
|
-
|
324
|
-
column_type: integer
|
342
|
+
data_type: int64
|
325
343
|
tests:
|
326
344
|
- unique
|
327
345
|
- not_null
|
328
346
|
- name: name
|
329
347
|
description: Write a description of the 'companies.name' column.
|
330
|
-
|
331
|
-
column_type: string
|
348
|
+
data_type: string
|
332
349
|
tests:
|
333
350
|
- not_null
|
334
351
|
- name: establishment_date
|
335
352
|
description: Write a description of the 'companies.establishment_date' column.
|
336
|
-
|
337
|
-
column_type: string
|
353
|
+
data_type: string
|
338
354
|
- name: average_age
|
339
355
|
description: Write a description of the 'companies.average_age' column.
|
340
|
-
|
341
|
-
column_type: float
|
356
|
+
data_type: float64
|
342
357
|
- name: published
|
343
358
|
description: Write a description of the 'companies.published' column.
|
344
|
-
|
345
|
-
column_type: boolean
|
359
|
+
data_type: bool
|
346
360
|
tests:
|
347
361
|
- not_null
|
348
362
|
- accepted_values:
|
@@ -352,14 +366,12 @@ sources:
|
|
352
366
|
quote: false
|
353
367
|
- name: created_at
|
354
368
|
description: Created At
|
355
|
-
|
356
|
-
column_type: datetime
|
369
|
+
data_type: datetime
|
357
370
|
tests:
|
358
371
|
- not_null
|
359
372
|
- name: updated_at
|
360
373
|
description: Updated At
|
361
|
-
|
362
|
-
column_type: datetime
|
374
|
+
data_type: datetime
|
363
375
|
tests:
|
364
376
|
- not_null
|
365
377
|
- name: posts
|
@@ -367,15 +379,13 @@ sources:
|
|
367
379
|
columns:
|
368
380
|
- name: id
|
369
381
|
description: ID
|
370
|
-
|
371
|
-
column_type: integer
|
382
|
+
data_type: int64
|
372
383
|
tests:
|
373
384
|
- unique
|
374
385
|
- not_null
|
375
386
|
- name: user_id
|
376
387
|
description: User
|
377
|
-
|
378
|
-
column_type: integer
|
388
|
+
data_type: int64
|
379
389
|
tests:
|
380
390
|
- not_null
|
381
391
|
- relationships:
|
@@ -385,28 +395,23 @@ sources:
|
|
385
395
|
relationship_type: many-to-one
|
386
396
|
- name: title
|
387
397
|
description: Title
|
388
|
-
|
389
|
-
column_type: string
|
398
|
+
data_type: string
|
390
399
|
- name: content
|
391
400
|
description: Content
|
392
|
-
|
393
|
-
column_type: text
|
401
|
+
data_type: string
|
394
402
|
- name: created_at
|
395
403
|
description: Post Created At
|
396
|
-
|
397
|
-
column_type: datetime
|
404
|
+
data_type: datetime
|
398
405
|
tests:
|
399
406
|
- not_null
|
400
407
|
- name: updated_at
|
401
408
|
description: Post Updated At
|
402
|
-
|
403
|
-
column_type: datetime
|
409
|
+
data_type: datetime
|
404
410
|
tests:
|
405
411
|
- not_null
|
406
412
|
- name: status
|
407
413
|
description: Write a description of the 'posts.status' column.
|
408
|
-
|
409
|
-
column_type: integer
|
414
|
+
data_type: int64
|
410
415
|
tests:
|
411
416
|
- accepted_values:
|
412
417
|
values:
|
@@ -424,8 +429,7 @@ sources:
|
|
424
429
|
columns:
|
425
430
|
- name: post_id
|
426
431
|
description: post_id
|
427
|
-
|
428
|
-
column_type: integer
|
432
|
+
data_type: int64
|
429
433
|
tests:
|
430
434
|
- not_null
|
431
435
|
- relationships:
|
@@ -438,8 +442,7 @@ sources:
|
|
438
442
|
message: uninitialized constant PostsTag
|
439
443
|
- name: tag_id
|
440
444
|
description: tag_id
|
441
|
-
|
442
|
-
column_type: integer
|
445
|
+
data_type: int64
|
443
446
|
tests:
|
444
447
|
- not_null
|
445
448
|
- relationships:
|
@@ -455,15 +458,13 @@ sources:
|
|
455
458
|
columns:
|
456
459
|
- name: id
|
457
460
|
description: id
|
458
|
-
|
459
|
-
column_type: integer
|
461
|
+
data_type: int64
|
460
462
|
tests:
|
461
463
|
- unique
|
462
464
|
- not_null
|
463
465
|
- name: user_id
|
464
466
|
description: user_id
|
465
|
-
|
466
|
-
column_type: integer
|
467
|
+
data_type: int64
|
467
468
|
tests:
|
468
469
|
- unique
|
469
470
|
- not_null
|
@@ -474,26 +475,22 @@ sources:
|
|
474
475
|
relationship_type: one-to-one
|
475
476
|
- name: first_name
|
476
477
|
description: Write a description of the 'profiles.first_name' column.
|
477
|
-
|
478
|
-
column_type: string
|
478
|
+
data_type: string
|
479
479
|
tests:
|
480
480
|
- not_null
|
481
481
|
- name: last_name
|
482
482
|
description: Write a description of the 'profiles.last_name' column.
|
483
|
-
|
484
|
-
column_type: string
|
483
|
+
data_type: string
|
485
484
|
tests:
|
486
485
|
- not_null
|
487
486
|
- name: created_at
|
488
487
|
description: Created At
|
489
|
-
|
490
|
-
column_type: datetime
|
488
|
+
data_type: datetime
|
491
489
|
tests:
|
492
490
|
- not_null
|
493
491
|
- name: updated_at
|
494
492
|
description: Updated At
|
495
|
-
|
496
|
-
column_type: datetime
|
493
|
+
data_type: datetime
|
497
494
|
tests:
|
498
495
|
- not_null
|
499
496
|
- name: relationships
|
@@ -506,15 +503,13 @@ sources:
|
|
506
503
|
columns:
|
507
504
|
- name: id
|
508
505
|
description: id
|
509
|
-
|
510
|
-
column_type: integer
|
506
|
+
data_type: int64
|
511
507
|
tests:
|
512
508
|
- unique
|
513
509
|
- not_null
|
514
510
|
- name: follower_id
|
515
511
|
description: follower_id
|
516
|
-
|
517
|
-
column_type: integer
|
512
|
+
data_type: int64
|
518
513
|
tests:
|
519
514
|
- not_null
|
520
515
|
- relationships:
|
@@ -524,8 +519,7 @@ sources:
|
|
524
519
|
relationship_type: many-to-one
|
525
520
|
- name: followed_id
|
526
521
|
description: followed_id
|
527
|
-
|
528
|
-
column_type: integer
|
522
|
+
data_type: int64
|
529
523
|
tests:
|
530
524
|
- not_null
|
531
525
|
- relationships:
|
@@ -535,14 +529,12 @@ sources:
|
|
535
529
|
relationship_type: many-to-one
|
536
530
|
- name: created_at
|
537
531
|
description: Created At
|
538
|
-
|
539
|
-
column_type: datetime
|
532
|
+
data_type: datetime
|
540
533
|
tests:
|
541
534
|
- not_null
|
542
535
|
- name: updated_at
|
543
536
|
description: Updated At
|
544
|
-
|
545
|
-
column_type: datetime
|
537
|
+
data_type: datetime
|
546
538
|
tests:
|
547
539
|
- not_null
|
548
540
|
- name: schema_migrations
|
@@ -553,8 +545,7 @@ sources:
|
|
553
545
|
columns:
|
554
546
|
- name: version
|
555
547
|
description: The version number of the migration.
|
556
|
-
|
557
|
-
column_type: string
|
548
|
+
data_type: string
|
558
549
|
tests:
|
559
550
|
- unique
|
560
551
|
- not_null
|
@@ -563,28 +554,24 @@ sources:
|
|
563
554
|
columns:
|
564
555
|
- name: id
|
565
556
|
description: id
|
566
|
-
|
567
|
-
column_type: integer
|
557
|
+
data_type: int64
|
568
558
|
tests:
|
569
559
|
- unique
|
570
560
|
- not_null
|
571
561
|
- name: name
|
572
562
|
description: Write a description of the 'tags.name' column.
|
573
|
-
|
574
|
-
column_type: string
|
563
|
+
data_type: string
|
575
564
|
tests:
|
576
565
|
- unique
|
577
566
|
- not_null
|
578
567
|
- name: created_at
|
579
568
|
description: Created At
|
580
|
-
|
581
|
-
column_type: datetime
|
569
|
+
data_type: datetime
|
582
570
|
tests:
|
583
571
|
- not_null
|
584
572
|
- name: updated_at
|
585
573
|
description: Updated At
|
586
|
-
|
587
|
-
column_type: datetime
|
574
|
+
data_type: datetime
|
588
575
|
tests:
|
589
576
|
- not_null
|
590
577
|
- name: user_tags
|
@@ -597,15 +584,13 @@ sources:
|
|
597
584
|
columns:
|
598
585
|
- name: id
|
599
586
|
description: id
|
600
|
-
|
601
|
-
column_type: integer
|
587
|
+
data_type: int64
|
602
588
|
tests:
|
603
589
|
- unique
|
604
590
|
- not_null
|
605
591
|
- name: user_id
|
606
592
|
description: user_id
|
607
|
-
|
608
|
-
column_type: integer
|
593
|
+
data_type: int64
|
609
594
|
tests:
|
610
595
|
- not_null
|
611
596
|
- relationships:
|
@@ -615,8 +600,7 @@ sources:
|
|
615
600
|
relationship_type: many-to-one
|
616
601
|
- name: tag_id
|
617
602
|
description: tag_id
|
618
|
-
|
619
|
-
column_type: integer
|
603
|
+
data_type: int64
|
620
604
|
tests:
|
621
605
|
- not_null
|
622
606
|
- relationships:
|
@@ -626,14 +610,12 @@ sources:
|
|
626
610
|
relationship_type: many-to-one
|
627
611
|
- name: created_at
|
628
612
|
description: Created At
|
629
|
-
|
630
|
-
column_type: datetime
|
613
|
+
data_type: datetime
|
631
614
|
tests:
|
632
615
|
- not_null
|
633
616
|
- name: updated_at
|
634
617
|
description: Updated At
|
635
|
-
|
636
|
-
column_type: datetime
|
618
|
+
data_type: datetime
|
637
619
|
tests:
|
638
620
|
- not_null
|
639
621
|
- name: users
|
@@ -649,28 +631,24 @@ sources:
|
|
649
631
|
columns:
|
650
632
|
- name: id
|
651
633
|
description: ID
|
652
|
-
|
653
|
-
column_type: integer
|
634
|
+
data_type: int64
|
654
635
|
tests:
|
655
636
|
- unique
|
656
637
|
- not_null
|
657
638
|
- name: created_at
|
658
639
|
description: User Created At
|
659
|
-
|
660
|
-
column_type: datetime
|
640
|
+
data_type: datetime
|
661
641
|
tests:
|
662
642
|
- not_null:
|
663
643
|
where: id != 1
|
664
644
|
- name: updated_at
|
665
645
|
description: User Updated At
|
666
|
-
|
667
|
-
column_type: datetime
|
646
|
+
data_type: datetime
|
668
647
|
tests:
|
669
648
|
- not_null
|
670
649
|
- name: company_id
|
671
650
|
description: company_id
|
672
|
-
|
673
|
-
column_type: integer
|
651
|
+
data_type: int64
|
674
652
|
tests:
|
675
653
|
- relationships:
|
676
654
|
to: source('dummy', 'companies')
|
@@ -854,6 +832,10 @@ from final
|
|
854
832
|
|
855
833
|
Example:
|
856
834
|
|
835
|
+
> [!NOTE]
|
836
|
+
>
|
837
|
+
> The output will be as shown below. It is recommended to indent the YAML file with a tool of your choice.
|
838
|
+
|
857
839
|
```yaml
|
858
840
|
---
|
859
841
|
version: 2
|
@@ -863,8 +845,7 @@ models:
|
|
863
845
|
columns:
|
864
846
|
- name: profile_id
|
865
847
|
description: profile_id
|
866
|
-
|
867
|
-
column_type: integer
|
848
|
+
data_type: int64
|
868
849
|
tests:
|
869
850
|
- unique
|
870
851
|
- not_null
|
@@ -875,8 +856,7 @@ models:
|
|
875
856
|
relationship_type: one-to-one
|
876
857
|
- name: user_id
|
877
858
|
description: user_id
|
878
|
-
|
879
|
-
column_type: integer
|
859
|
+
data_type: int64
|
880
860
|
tests:
|
881
861
|
- unique
|
882
862
|
- not_null
|
@@ -887,31 +867,137 @@ models:
|
|
887
867
|
relationship_type: one-to-one
|
888
868
|
- name: first_name
|
889
869
|
description: Write a description of the 'profiles.first_name' column.
|
890
|
-
|
891
|
-
column_type: string
|
870
|
+
data_type: string
|
892
871
|
tests:
|
893
872
|
- not_null
|
894
873
|
- name: last_name
|
895
874
|
description: Write a description of the 'profiles.last_name' column.
|
896
|
-
|
897
|
-
column_type: string
|
875
|
+
data_type: string
|
898
876
|
tests:
|
899
877
|
- not_null
|
900
878
|
- name: created_at
|
901
879
|
description: Created At
|
902
|
-
|
903
|
-
column_type: datetime
|
880
|
+
data_type: datetime
|
904
881
|
tests:
|
905
882
|
- not_null
|
906
883
|
- name: updated_at
|
907
884
|
description: Updated At
|
908
|
-
|
909
|
-
column_type: datetime
|
885
|
+
data_type: datetime
|
910
886
|
tests:
|
911
887
|
- not_null
|
912
888
|
|
913
889
|
```
|
914
890
|
|
891
|
+
### Generated dbt Seed Files
|
892
|
+
|
893
|
+
#### dbt Seed Configuration
|
894
|
+
|
895
|
+
In the `#{config_directory_path}/source_config.yml` file, describe the properties you want to set for the seed enum.
|
896
|
+
You can configure `defaults` in this file.
|
897
|
+
|
898
|
+
##### defaults
|
899
|
+
|
900
|
+
Set the default value for the `description` of the `seeds` enum.
|
901
|
+
|
902
|
+
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 }}`.
|
903
|
+
|
904
|
+
Example:
|
905
|
+
|
906
|
+
```yml
|
907
|
+
defaults:
|
908
|
+
seed_descriptions:
|
909
|
+
enum:
|
910
|
+
description: "{{ source_name }} {{ translated_table_name }} {{ translated_attribute_name }} enum"
|
911
|
+
|
912
|
+
```
|
913
|
+
|
914
|
+
If nothing is set, it defaults to the following:
|
915
|
+
|
916
|
+
```yml
|
917
|
+
defaults:
|
918
|
+
seed_descriptions:
|
919
|
+
enum:
|
920
|
+
description: "{{ source_name }} {{ translated_table_name }} {{ translated_attribute_name }} enum"
|
921
|
+
|
922
|
+
```
|
923
|
+
|
924
|
+
#### Generate dbt Seed Enum Files
|
925
|
+
|
926
|
+
Generate seed enum files for dbt:
|
927
|
+
|
928
|
+
```bash
|
929
|
+
$ bin/rails generate active_record:dbt:enum TABLE_NAME ENUM_COLUMN_NAME
|
930
|
+
```
|
931
|
+
|
932
|
+
Generate seed enum files for dbt from the specified `TABLE_NAME` and `ENUM_COLUMN_NAME`.
|
933
|
+
|
934
|
+
File | Description
|
935
|
+
--------- | ---------
|
936
|
+
`#{export_directory_path}/seed_#{source_name}__#{table_name_singularize}_enum_#{enum_pluralized}.csv` | Seed enum file for dbt.
|
937
|
+
`#{export_directory_path}/seed_#{source_name}__#{table_name_singularize}_enum_#{enum_pluralized}.yml` | Seed enum documentation file for dbt.
|
938
|
+
|
939
|
+
Example:
|
940
|
+
|
941
|
+
```bash
|
942
|
+
$ bin/rails generate active_record:dbt:enum posts status
|
943
|
+
```
|
944
|
+
|
945
|
+
##### Generate `#{export_directory_path}/seed_#{source_name}__#{table_name_singularize}_enum_#{enum_pluralized}.csv`
|
946
|
+
|
947
|
+
Example:
|
948
|
+
|
949
|
+
```csv
|
950
|
+
status_before_type_of_cast,status_key,status_en,status_ja
|
951
|
+
0,draft,Draft,下書き
|
952
|
+
1,published,Published,公開
|
953
|
+
2,deleted,Deleted,削除
|
954
|
+
|
955
|
+
```
|
956
|
+
|
957
|
+
##### Generate `#{export_directory_path}/seed_#{source_name}__#{table_name_singularize}_enum_#{enum_pluralized}.yml`
|
958
|
+
|
959
|
+
Example:
|
960
|
+
|
961
|
+
> [!NOTE]
|
962
|
+
>
|
963
|
+
> The output will be as shown below. It is recommended to indent the YAML file with a tool of your choice.
|
964
|
+
|
965
|
+
```yaml
|
966
|
+
---
|
967
|
+
version: 2
|
968
|
+
seeds:
|
969
|
+
- name: seed_dummy__post_enum_statuses
|
970
|
+
description: dummy Post Status enum
|
971
|
+
config:
|
972
|
+
column_types:
|
973
|
+
status_before_type_of_cast: int64
|
974
|
+
status_key: string
|
975
|
+
status_en: string
|
976
|
+
status_ja: string
|
977
|
+
columns:
|
978
|
+
- name: status_before_type_of_cast
|
979
|
+
description: Status
|
980
|
+
tests:
|
981
|
+
- unique
|
982
|
+
- not_null
|
983
|
+
- name: status_key
|
984
|
+
description: Status(key)
|
985
|
+
tests:
|
986
|
+
- unique
|
987
|
+
- not_null
|
988
|
+
- name: status_en
|
989
|
+
description: Status(en)
|
990
|
+
tests:
|
991
|
+
- unique
|
992
|
+
- not_null
|
993
|
+
- name: status_ja
|
994
|
+
description: Status(ja)
|
995
|
+
tests:
|
996
|
+
- unique
|
997
|
+
- not_null
|
998
|
+
|
999
|
+
```
|
1000
|
+
|
915
1001
|
## Contributing
|
916
1002
|
|
917
1003
|
Contribution directions go here.
|
@@ -4,6 +4,9 @@ module ActiveRecord
|
|
4
4
|
module Dbt
|
5
5
|
module Column
|
6
6
|
class Column
|
7
|
+
include ActiveRecord::Dbt::DataType::Mapper
|
8
|
+
include ActiveRecord::Dbt::I18nWrapper::Translate
|
9
|
+
|
7
10
|
attr_reader :table_name, :column, :column_test, :primary_keys
|
8
11
|
|
9
12
|
delegate :name, :comment, to: :column, prefix: true
|
@@ -21,7 +24,7 @@ module ActiveRecord
|
|
21
24
|
{
|
22
25
|
'name' => column_name,
|
23
26
|
'description' => description,
|
24
|
-
'
|
27
|
+
'data_type' => data_type(column.type),
|
25
28
|
**column_overrides.except(:tests),
|
26
29
|
'tests' => column_test.config
|
27
30
|
}.compact
|
@@ -43,18 +46,6 @@ module ActiveRecord
|
|
43
46
|
source_config.dig(:table_descriptions, table_name, :columns, column_name)
|
44
47
|
end
|
45
48
|
|
46
|
-
def translated_attribute_name
|
47
|
-
translated_column_name || translated_default_column_name
|
48
|
-
end
|
49
|
-
|
50
|
-
def translated_column_name
|
51
|
-
I18n.t("activerecord.attributes.#{table_name.singularize}.#{column_name}", default: nil)
|
52
|
-
end
|
53
|
-
|
54
|
-
def translated_default_column_name
|
55
|
-
I18n.t("attributes.#{column_name}", default: nil)
|
56
|
-
end
|
57
|
-
|
58
49
|
def key_column_name
|
59
50
|
column_name if primary_key? || foreign_key?
|
60
51
|
end
|
@@ -5,17 +5,13 @@ module ActiveRecord
|
|
5
5
|
module Column
|
6
6
|
module Testable
|
7
7
|
module AcceptedValuesTestable
|
8
|
-
|
8
|
+
extend ActiveRecord::Dbt::RequiredMethods
|
9
|
+
|
10
|
+
define_required_methods :@config, :column, :table_name, :column_name
|
9
11
|
|
10
12
|
delegate :type, to: :column, prefix: true
|
11
13
|
delegate :add_log, to: :@config
|
12
14
|
|
13
|
-
REQUIRED_ACCEPTED_VALUES_TESTABLE_METHODS.each do |method_name|
|
14
|
-
define_method(method_name) do
|
15
|
-
raise NotImplementedError, "You must implement #{self.class}##{__method__}"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
15
|
def accepted_values_test
|
20
16
|
return nil unless column_type == :boolean || enum_values.present?
|
21
17
|
|
@@ -5,16 +5,18 @@ module ActiveRecord
|
|
5
5
|
module Column
|
6
6
|
module Testable
|
7
7
|
module NotNullTestable
|
8
|
-
|
8
|
+
extend ActiveRecord::Dbt::RequiredMethods
|
9
9
|
|
10
|
-
|
11
|
-
define_method(method_name) do
|
12
|
-
raise NotImplementedError, "You must implement #{self.class}##{__method__}"
|
13
|
-
end
|
14
|
-
end
|
10
|
+
define_required_methods :column
|
15
11
|
|
16
12
|
def not_null_test
|
17
|
-
|
13
|
+
null? ? nil : 'not_null'
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def null?
|
19
|
+
column.null == true
|
18
20
|
end
|
19
21
|
end
|
20
22
|
end
|