active-dbml 0.2.1 → 0.2.3
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/lib/active/dbml/version.rb +1 -1
- data/lib/active/dbml.rb +61 -57
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 883f97dab6da278ac16901b94d60b2288cbcad0dc84fda907c6f316fd4de5859
|
4
|
+
data.tar.gz: bf8cf386d3a53c7aa3dd04f5704ab50fa6fbb695d1c81eeeb266d109d416bbad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60e2e63cbd3c2c932430388a6c99bb8ba7a634097e50cbe9d0c0c950c13d1cdd0885f9bf28140d139156ab61c418fe36cdf69b63939757a9035face489641184
|
7
|
+
data.tar.gz: 00ab782368ffdeabbd31b0e3c2ee94d1a08dc23ee5aed42456eb4233e9864d94d4b0583c7d4c396d0d947316f3a3f3f9c19c2c0aa5301a10824add607c380e85
|
data/lib/active/dbml/version.rb
CHANGED
data/lib/active/dbml.rb
CHANGED
@@ -11,45 +11,45 @@ module Active
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.generate_dbml(models)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
14
|
+
begin
|
15
|
+
dbml_output = []
|
16
|
+
# 出力済みのEnumを追跡
|
17
|
+
enums_generated = Set.new
|
18
|
+
|
19
|
+
models.each do |model|
|
20
|
+
if ActiveRecord::Base.connection.table_exists?(model.table_name)
|
21
|
+
# 抽象クラスはスキップ
|
22
|
+
next if model.abstract_class?
|
23
|
+
|
24
|
+
primary_key = get_primary_key(model)
|
25
|
+
foreign_keys = get_foreign_keys(model)
|
26
|
+
|
27
|
+
dbml_output << "Table #{model.table_name} {"
|
28
|
+
|
29
|
+
# Enumを取得
|
30
|
+
defined_enums = model.defined_enums.keys
|
31
|
+
|
32
|
+
# カラム情報を生成
|
33
|
+
generate_columns(dbml_output, model, primary_key, foreign_keys, defined_enums)
|
34
|
+
|
35
|
+
# Index情報の取得
|
36
|
+
generate_indexes(dbml_output, model)
|
37
|
+
|
38
|
+
# テーブルコメントの取得
|
39
|
+
generate_table_comment(dbml_output, model)
|
40
|
+
|
41
|
+
# テーブルを閉じる
|
42
|
+
dbml_output << "}\n"
|
43
|
+
|
44
|
+
# Enumの詳細を取得
|
45
|
+
generate_enums(dbml_output, model, enums_generated)
|
46
|
+
end
|
45
47
|
end
|
48
|
+
|
49
|
+
dbml_output.join("\n")
|
50
|
+
rescue => exception
|
51
|
+
Rails.logger.error exception
|
46
52
|
end
|
47
|
-
|
48
|
-
dbml_output.join("\n")
|
49
|
-
# begin
|
50
|
-
# rescue => exception
|
51
|
-
# Rails.logger.error exception
|
52
|
-
# end
|
53
53
|
end
|
54
54
|
|
55
55
|
private
|
@@ -62,29 +62,33 @@ module Active
|
|
62
62
|
|
63
63
|
# get foreign key only belongs_to association
|
64
64
|
model.reflect_on_all_associations(:belongs_to).each do |association|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
65
|
+
begin
|
66
|
+
# NOTE: Check model type
|
67
|
+
# Skip anything other than ActiveRecord::Base
|
68
|
+
if association.class_name.constantize < ActiveRecord::Base
|
69
|
+
association.class_name.constantize.reflect_on_all_associations.each do |relation_association|
|
70
|
+
if model.table_name.eql?(relation_association.plural_name)
|
71
|
+
foreign_key = association.options[:foreign_key]
|
72
|
+
foreign_key_destination = "#{association.plural_name}.#{association.class_name.constantize.primary_key}"
|
73
|
+
|
74
|
+
case relation_association.macro
|
75
|
+
when :has_one
|
76
|
+
foreign_keys[foreign_key] = { destination: foreign_key_destination, relation_type: '-' }
|
77
|
+
when :has_many
|
78
|
+
foreign_keys[foreign_key] = { destination: foreign_key_destination, relation_type: '>' }
|
79
|
+
else
|
80
|
+
end
|
79
81
|
end
|
80
82
|
end
|
83
|
+
elsif association.class_name.constantize < ActiveYaml::Base
|
84
|
+
puts "⚠ #{association.class_name.constantize} is an ActiveYaml model."
|
85
|
+
elsif association.class_name.constantize < ActiveHash::Base
|
86
|
+
puts "⚠ #{association.class_name.constantize} is an ActiveHash model."
|
87
|
+
else
|
88
|
+
puts "⚠ Cannot determine type of #{association.class_name.constantize}"
|
81
89
|
end
|
82
|
-
|
83
|
-
|
84
|
-
elsif association.class_name.constantize < ActiveHash::Base
|
85
|
-
puts "⚠ #{association.class_name.constantize} is an ActiveHash model."
|
86
|
-
else
|
87
|
-
puts "⚠ Cannot determine type of #{association.class_name.constantize}"
|
90
|
+
rescue => exception
|
91
|
+
Rails.logger.error exception
|
88
92
|
end
|
89
93
|
end
|
90
94
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active-dbml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ukmshi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-07-
|
11
|
+
date: 2023-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|