activerecord-dbt 0.4.0 → 0.5.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 +227 -172
- data/lib/active_record/dbt/column/data_test.rb +3 -2
- data/lib/active_record/dbt/column/data_testable/accepted_values_data_testable.rb +22 -6
- data/lib/active_record/dbt/column/data_testable/relationships_data_testable.rb +20 -6
- data/lib/active_record/dbt/column/yml.rb +30 -8
- data/lib/active_record/dbt/configuration/source.rb +12 -0
- data/lib/active_record/dbt/core_ext/active_record_ext.rb +17 -0
- data/lib/active_record/dbt/dbt_package/dbt_utils/table/data_testable/unique_combination_of_columns_data_testable.rb +32 -4
- data/lib/active_record/dbt/factory/enum/yml_factory.rb +27 -0
- data/lib/active_record/dbt/factory/tables/yml_factory.rb +4 -1
- data/lib/active_record/dbt/i18n_wrapper/translate.rb +5 -4
- data/lib/active_record/dbt/model/staging/base.rb +27 -1
- data/lib/active_record/dbt/model/staging/sql.rb +0 -24
- data/lib/active_record/dbt/model/staging/yml.rb +21 -16
- data/lib/active_record/dbt/seed/enum/base.rb +4 -2
- data/lib/active_record/dbt/seed/enum/yml.rb +28 -12
- data/lib/active_record/dbt/table/base.rb +3 -1
- data/lib/active_record/dbt/table/yml.rb +22 -10
- data/lib/active_record/dbt/validation/table_name_validator.rb +17 -0
- data/lib/active_record/dbt/version.rb +1 -1
- data/lib/generators/active_record/dbt/config/templates/source_config.yml.tt +23 -15
- data/lib/generators/active_record/dbt/enum/enum_generator.rb +1 -1
- metadata +33 -20
|
@@ -9,9 +9,9 @@ module ActiveRecord
|
|
|
9
9
|
|
|
10
10
|
attr_reader :table_data_test, :columns
|
|
11
11
|
|
|
12
|
-
delegate :source_config, to: :@config
|
|
12
|
+
delegate :project_name, :source_config, to: :@config
|
|
13
13
|
|
|
14
|
-
def initialize(table_name, table_data_test, columns)
|
|
14
|
+
def initialize(table_name, table_data_test = Struct.new(:properties).new, columns = [])
|
|
15
15
|
super(table_name)
|
|
16
16
|
@table_data_test = table_data_test
|
|
17
17
|
@columns = columns
|
|
@@ -24,6 +24,12 @@ module ActiveRecord
|
|
|
24
24
|
}.compact
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
+
def fetch_logical_name
|
|
28
|
+
@fetch_logical_name ||=
|
|
29
|
+
config_logical_name ||
|
|
30
|
+
translated_table_name
|
|
31
|
+
end
|
|
32
|
+
|
|
27
33
|
private
|
|
28
34
|
|
|
29
35
|
def table_properties
|
|
@@ -35,6 +41,11 @@ module ActiveRecord
|
|
|
35
41
|
}
|
|
36
42
|
end
|
|
37
43
|
|
|
44
|
+
def logical_name
|
|
45
|
+
@logical_name ||=
|
|
46
|
+
fetch_logical_name.present? ? "#{project_name} #{fetch_logical_name}" : default_logical_name
|
|
47
|
+
end
|
|
48
|
+
|
|
38
49
|
def description
|
|
39
50
|
return logical_name if table_description.blank?
|
|
40
51
|
|
|
@@ -44,17 +55,18 @@ module ActiveRecord
|
|
|
44
55
|
].join("\n")
|
|
45
56
|
end
|
|
46
57
|
|
|
47
|
-
def
|
|
48
|
-
|
|
49
|
-
source_config.dig(:table_descriptions, table_name, :logical_name) ||
|
|
50
|
-
translated_table_name ||
|
|
51
|
-
default_logical_name ||
|
|
52
|
-
"Write a logical_name of the '#{table_name}' table."
|
|
58
|
+
def config_logical_name
|
|
59
|
+
source_config.dig(:table_descriptions, table_name, :logical_name)
|
|
53
60
|
end
|
|
54
61
|
|
|
55
62
|
def default_logical_name
|
|
56
|
-
|
|
57
|
-
|
|
63
|
+
source_config_logical_name&.gsub(/{{\s*project_name\s*}}/, project_name)
|
|
64
|
+
&.gsub(/{{\s*table_name\s*}}/, table_name)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def source_config_logical_name
|
|
68
|
+
source_config.dig(:defaults, :table_descriptions, :logical_name) ||
|
|
69
|
+
"Write the logical_name of the '{{ table_name }}' table in '{{ project_name }}'."
|
|
58
70
|
end
|
|
59
71
|
|
|
60
72
|
def table_description
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ActiveRecord
|
|
4
|
+
module Dbt
|
|
5
|
+
module Validation
|
|
6
|
+
module TableNameValidator
|
|
7
|
+
def validate_table_name(table_name, config)
|
|
8
|
+
return table_name if config.exclude_table_names.exclude?(table_name)
|
|
9
|
+
|
|
10
|
+
raise TableNameIsExcludedError, "The table name '#{table_name}' is excluded in 'exclude_table_names'."
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class TableNameIsExcludedError < StandardError; end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -1,27 +1,34 @@
|
|
|
1
1
|
sources:
|
|
2
2
|
name: <%= application_name %>
|
|
3
|
-
meta:
|
|
4
|
-
generated_by: activerecord-dbt
|
|
5
3
|
description: |-
|
|
6
4
|
Write a description of the '<%= application_name %>' source.
|
|
7
5
|
You can write multiple lines.
|
|
6
|
+
config:
|
|
7
|
+
meta:
|
|
8
|
+
project_name: <%= application_name %>
|
|
9
|
+
generated_by: activerecord-dbt
|
|
10
|
+
exclude:
|
|
11
|
+
table_names:
|
|
12
|
+
- ar_internal_metadata
|
|
13
|
+
- schema_migrations
|
|
8
14
|
|
|
9
15
|
table_overrides:
|
|
10
16
|
<table_name>:
|
|
11
|
-
meta: {<dictionary>}
|
|
12
17
|
identifier: <table_name>
|
|
13
|
-
|
|
18
|
+
config:
|
|
19
|
+
meta: {<dictionary>}
|
|
20
|
+
freshness:
|
|
21
|
+
warn_after:
|
|
22
|
+
count: <positive_integer>
|
|
23
|
+
period: minute | hour | day
|
|
24
|
+
error_after:
|
|
25
|
+
count: <positive_integer>
|
|
26
|
+
period: minute | hour | day
|
|
27
|
+
filter: <where-condition>
|
|
28
|
+
loaded_at_field: <column_name>
|
|
14
29
|
data_tests:
|
|
15
30
|
- <test>
|
|
16
31
|
tags: [<string>]
|
|
17
|
-
freshness:
|
|
18
|
-
warn_after:
|
|
19
|
-
count: <positive_integer>
|
|
20
|
-
period: minute | hour | day
|
|
21
|
-
error_after:
|
|
22
|
-
count: <positive_integer>
|
|
23
|
-
period: minute | hour | day
|
|
24
|
-
filter: <where-condition>
|
|
25
32
|
quoting:
|
|
26
33
|
database: true | false
|
|
27
34
|
schema: true | false
|
|
@@ -29,7 +36,8 @@ table_overrides:
|
|
|
29
36
|
external: {<dictionary>}
|
|
30
37
|
columns:
|
|
31
38
|
<column_name>:
|
|
32
|
-
|
|
39
|
+
config:
|
|
40
|
+
meta: {<dictionary>}
|
|
33
41
|
quote: true | false
|
|
34
42
|
data_tests:
|
|
35
43
|
- <test>
|
|
@@ -37,12 +45,12 @@ table_overrides:
|
|
|
37
45
|
|
|
38
46
|
defaults:
|
|
39
47
|
table_descriptions:
|
|
40
|
-
logical_name: Write
|
|
48
|
+
logical_name: Write the logical_name of the '{{ table_name }}' table in '{{ project_name }}'.
|
|
41
49
|
columns:
|
|
42
50
|
description: Write a description of the '{{ table_name }}.{{ column_name }}' column.
|
|
43
51
|
seed_descriptions:
|
|
44
52
|
enum:
|
|
45
|
-
description: "{{
|
|
53
|
+
description: "{{ project_name }} {{ table_logical_name }} {{ column_description }} enum"
|
|
46
54
|
|
|
47
55
|
table_descriptions:
|
|
48
56
|
ar_internal_metadata:
|
metadata
CHANGED
|
@@ -1,59 +1,72 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: activerecord-dbt
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- yamotech
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: activerecord
|
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
|
16
15
|
requirements:
|
|
17
|
-
- - "
|
|
16
|
+
- - "~>"
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
18
|
+
version: '8.0'
|
|
20
19
|
type: :runtime
|
|
21
20
|
prerelease: false
|
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
22
|
requirements:
|
|
24
|
-
- - "
|
|
23
|
+
- - "~>"
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
25
|
+
version: '8.0'
|
|
27
26
|
- !ruby/object:Gem::Dependency
|
|
28
27
|
name: activesupport
|
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
|
30
29
|
requirements:
|
|
31
|
-
- - "
|
|
30
|
+
- - "~>"
|
|
32
31
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '
|
|
32
|
+
version: '8.0'
|
|
34
33
|
type: :runtime
|
|
35
34
|
prerelease: false
|
|
36
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
36
|
requirements:
|
|
38
|
-
- - "
|
|
37
|
+
- - "~>"
|
|
39
38
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '
|
|
39
|
+
version: '8.0'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: csv
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '3.0'
|
|
47
|
+
type: :runtime
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - "~>"
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '3.0'
|
|
41
54
|
- !ruby/object:Gem::Dependency
|
|
42
55
|
name: zeitwerk
|
|
43
56
|
requirement: !ruby/object:Gem::Requirement
|
|
44
57
|
requirements:
|
|
45
|
-
- - "
|
|
58
|
+
- - "~>"
|
|
46
59
|
- !ruby/object:Gem::Version
|
|
47
60
|
version: '2.6'
|
|
48
61
|
type: :runtime
|
|
49
62
|
prerelease: false
|
|
50
63
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
64
|
requirements:
|
|
52
|
-
- - "
|
|
65
|
+
- - "~>"
|
|
53
66
|
- !ruby/object:Gem::Version
|
|
54
67
|
version: '2.6'
|
|
55
|
-
description:
|
|
56
|
-
|
|
68
|
+
description: A Rails generator to create dbt sources, models, and seeds from ActiveRecord
|
|
69
|
+
schema and enums.
|
|
57
70
|
email:
|
|
58
71
|
- nothings.2c9@gmail.com
|
|
59
72
|
executables: []
|
|
@@ -78,10 +91,12 @@ files:
|
|
|
78
91
|
- lib/active_record/dbt/configuration/parser.rb
|
|
79
92
|
- lib/active_record/dbt/configuration/source.rb
|
|
80
93
|
- lib/active_record/dbt/configuration/used_dbt_package.rb
|
|
94
|
+
- lib/active_record/dbt/core_ext/active_record_ext.rb
|
|
81
95
|
- lib/active_record/dbt/data_type/mapper.rb
|
|
82
96
|
- lib/active_record/dbt/dbt_package/dbt_utils/table/data_testable/unique_combination_of_columns_data_testable.rb
|
|
83
97
|
- lib/active_record/dbt/dbt_package/dbterd/column/data_testable/relationships_meta_relationship_type.rb
|
|
84
98
|
- lib/active_record/dbt/factory/columns/yml_factory.rb
|
|
99
|
+
- lib/active_record/dbt/factory/enum/yml_factory.rb
|
|
85
100
|
- lib/active_record/dbt/factory/model/staging/yml_factory.rb
|
|
86
101
|
- lib/active_record/dbt/factory/source/yml_factory.rb
|
|
87
102
|
- lib/active_record/dbt/factory/table/yml_factory.rb
|
|
@@ -99,6 +114,7 @@ files:
|
|
|
99
114
|
- lib/active_record/dbt/table/base.rb
|
|
100
115
|
- lib/active_record/dbt/table/data_test.rb
|
|
101
116
|
- lib/active_record/dbt/table/yml.rb
|
|
117
|
+
- lib/active_record/dbt/validation/table_name_validator.rb
|
|
102
118
|
- lib/active_record/dbt/version.rb
|
|
103
119
|
- lib/generators/active_record/dbt/config/USAGE
|
|
104
120
|
- lib/generators/active_record/dbt/config/config_generator.rb
|
|
@@ -118,11 +134,9 @@ homepage: https://github.com/yamotech/activerecord-dbt
|
|
|
118
134
|
licenses:
|
|
119
135
|
- MIT
|
|
120
136
|
metadata:
|
|
121
|
-
homepage_uri: https://github.com/yamotech/activerecord-dbt
|
|
122
137
|
source_code_uri: https://github.com/yamotech/activerecord-dbt
|
|
123
138
|
changelog_uri: https://github.com/yamotech/activerecord-dbt/blob/main/CHANGELOG.md
|
|
124
139
|
rubygems_mfa_required: 'true'
|
|
125
|
-
post_install_message:
|
|
126
140
|
rdoc_options: []
|
|
127
141
|
require_paths:
|
|
128
142
|
- lib
|
|
@@ -130,15 +144,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
130
144
|
requirements:
|
|
131
145
|
- - ">="
|
|
132
146
|
- !ruby/object:Gem::Version
|
|
133
|
-
version: '3.
|
|
147
|
+
version: '3.2'
|
|
134
148
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
149
|
requirements:
|
|
136
150
|
- - ">="
|
|
137
151
|
- !ruby/object:Gem::Version
|
|
138
152
|
version: '0'
|
|
139
153
|
requirements: []
|
|
140
|
-
rubygems_version: 3.
|
|
141
|
-
signing_key:
|
|
154
|
+
rubygems_version: 3.6.9
|
|
142
155
|
specification_version: 4
|
|
143
156
|
summary: Generate dbt files from the information of the database connected by ActiveRecord.
|
|
144
157
|
test_files: []
|