schemard 0.3.1 → 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.ja.md +29 -13
- data/README.md +53 -5
- data/lib/schemard/relation_generator.rb +18 -8
- data/lib/schemard.rb +1 -1
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce4c14510a96e6b9ecbeb11c07c791f6dac2d397
|
4
|
+
data.tar.gz: c1b1e3e296f590e8f1ad905ea5896856d3b1e210
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a771fa891f159f992c3076ec2424c83ac077633812b303a3dac12daf65edb928fc2960ffcdfe3ff26af04e348f6f128245e2e12dbf98b8a25733ccbbbf864217
|
7
|
+
data.tar.gz: 9af6e49421c170b3e1c4745347b90ce26f1e86c89b12cc02a6504ed43eff1e451ef0cee4ee25c89fc952fffd4ee5ada134606757db1bc1d01a1362364316376d
|
data/README.ja.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
## 概要
|
4
4
|
|
5
5
|
SchemaRD は、Railsアプリケーションで利用する schema.rb を元にER図を生成するツールです。
|
6
|
-
生成されたER図は、Web
|
6
|
+
生成されたER図は、Webブラウザで閲覧することができます。
|
7
7
|
|
8
8
|
## 使い方
|
9
9
|
|
@@ -28,15 +28,16 @@ Webブラウザで`http://localhost:10080`にアクセスすると生成され
|
|
28
28
|
|
29
29
|
<img src="https://raw.githubusercontent.com/wiki/xketanaka/schemard/images/init_layout_ja.png" width="700px" >
|
30
30
|
|
31
|
-
|
31
|
+
無作為に配置されたテーブルを任意の位置にレイアウトするには、図の左上の「テーブルの位置を編集」をチェックし、テーブルをドラッグします。
|
32
32
|
|
33
33
|
<img src="https://raw.githubusercontent.com/wiki/xketanaka/schemard/images/edit_layout_ja.png" width="700px" >
|
34
34
|
|
35
|
+
レイアウト調整が完了したら、「テーブル位置を編集」のチェックを外します。
|
35
36
|
|
36
37
|
### リレーション追加
|
37
38
|
|
38
39
|
デフォルトで生成されるER図には、テーブル同士のリレーション情報がありません。
|
39
|
-
ER
|
40
|
+
ER図にリレーションを追加するには、schema.rb とは別にリレーション情報を与える必要があります。
|
40
41
|
|
41
42
|
リレーション情報を与える方法はいくつかありますが、ここではRailsアプリケーションのモデル情報を元にリレーション情報を追加する手順を説明します。先程と同様に、RubyOnRailsチュートリアルのソースコードを用いて説明します。
|
42
43
|
|
@@ -64,22 +65,22 @@ tables:
|
|
64
65
|
- users
|
65
66
|
```
|
66
67
|
|
67
|
-
3.
|
68
|
+
3. 抽出したリレーション情報を読み込ませるには以下のように -f オプションを指定して実行します。
|
68
69
|
```
|
69
70
|
$ schemard -f db/relation.metadata
|
70
71
|
```
|
71
72
|
|
72
|
-
4. Webブラウザで`http://localhost:10080
|
73
|
+
4. 抽出したリレーションがER図に反映されています。Webブラウザで`http://localhost:10080`にアクセスすることで確認できます。
|
73
74
|
|
74
75
|
<img src="https://raw.githubusercontent.com/wiki/xketanaka/schemard/images/relation_added.png" width="700px" >
|
75
76
|
|
76
77
|
### 日本語化
|
77
78
|
|
78
79
|
デフォルトで生成されるER図では、テーブル名・カラム名は物理名で表示されます。
|
79
|
-
|
80
|
-
ここでは、ActiveRecord
|
80
|
+
テーブル名・カラム名を物理名以外の別名(論理名・日本語名)で表示する方法はいくつかありますが、
|
81
|
+
ここでは、ActiveRecordのモデル名・属性名の翻訳辞書ファイルを利用する手順を説明します。
|
81
82
|
|
82
|
-
1.
|
83
|
+
1. 以下の形式の翻訳辞書ファイルが`config/locale/ja.yml`に存在するものとします。
|
83
84
|
```
|
84
85
|
ja:
|
85
86
|
activerecord:
|
@@ -93,22 +94,30 @@ ja:
|
|
93
94
|
<column_name>: <column_name>
|
94
95
|
```
|
95
96
|
|
96
|
-
2.
|
97
|
+
2. 以下のようにオプションで翻訳辞書ファイルを指定して実行します。
|
97
98
|
```
|
98
99
|
$ schemard -f db/relation.metadata -f config/locale/ja.yml
|
99
100
|
```
|
100
101
|
|
101
|
-
3. Webブラウザで `http://localhost:10080`
|
102
|
+
3. Webブラウザで `http://localhost:10080` にアクセスするとテーブル名・カラム名が翻訳辞書ファイルに記述された表示名で表示されます。
|
102
103
|
|
103
104
|
## オプション
|
104
105
|
|
105
106
|
以下のコマンドラインオプションが指定可能です。
|
106
107
|
|
107
|
-
*
|
108
|
+
* -i, --input-file ... `schema.rb`ファイルを指定します。デフォルトは`db/schema.rb`です。
|
109
|
+
* -o, --output-file ... レイアウト情報を出力するファイルを指定します。デフォルトは`schema.metadata`です。
|
110
|
+
* -f, -m, --metadata-file ... リレーション情報ファイル、翻訳辞書ファイルを指定します。デフォルトは`指定なし`です。
|
111
|
+
* --rdoc, --rdoc-enabled ... `schema.rb`に記述しているrdocコメントからメタ情報を取得する場合に指定します。デフォルトは`指定なし`です。
|
112
|
+
* --parse-db-comment-as ... マイグレーション情報のcommentオプションをどのように解釈するかを指定します。`name`,`ignore`が指定できます。`name`を指定するとcommentオプションで指定された値を論理名として解釈します。`ignore`を指定するとcommentオプションの値を無視します。デフォルトは`ignore`です。
|
113
|
+
* -l, --log-output ... ログ出力先を指定します。`stdout`, `stderr`, `任意のファイル名`が指定できます。デフォルトは`stdout`です。
|
114
|
+
* -s --silent --no-log-output ... ログ出力をしたくない場合に指定します。
|
115
|
+
* -h, -host ... WebServerがListenするホスト名を指定します。デフォルトは`127.0.0.1`です。
|
116
|
+
* -p, --port ... WebServerがListenするポートを指定します。デフォルトは`10080`です。
|
108
117
|
|
109
118
|
### サブコマンド
|
110
119
|
|
111
|
-
|
120
|
+
* generate-relations ... Railsアプリケーションのモデル情報よりリレーション情報を抽出し、YAML形式で標準出力に出力します。`-d`オプションでRails.rootディレクトリを指定することができます(デフォルトはカレントディレクトリ)。
|
112
121
|
|
113
122
|
## 設定
|
114
123
|
|
@@ -116,6 +125,13 @@ TODO
|
|
116
125
|
設定ファイルは`schemard`コマンド実行ディレクトリに`.schemard.config`という名前で作成します。
|
117
126
|
以下のエントリを指定することができます。
|
118
127
|
|
119
|
-
*
|
128
|
+
* input_file
|
129
|
+
* output_file
|
130
|
+
* metadata_files
|
131
|
+
* rdoc_enabled
|
132
|
+
* parse_db_comment_as
|
133
|
+
* log_output
|
134
|
+
* webserver_host
|
135
|
+
* webserver_port
|
120
136
|
|
121
137
|
なお、設定ファイルとコマンドラインオプションの両方に指定がある場合、コマンドラインオプションが優先されます。
|
data/README.md
CHANGED
@@ -28,16 +28,18 @@ The figure below is the table schema which has generated from schema.rb of the R
|
|
28
28
|
|
29
29
|
<img src="https://raw.githubusercontent.com/wiki/xketanaka/schemard/images/init_layout.png" width="700px" >
|
30
30
|
|
31
|
-
You can adjust the position by checking "Edit table position" at the top left of the figure,
|
31
|
+
To layout tables in desired position, You can adjust the position by checking "Edit table position" at the top left of the figure,
|
32
32
|
And dragging the table.
|
33
33
|
|
34
34
|
<img src="https://raw.githubusercontent.com/wiki/xketanaka/schemard/images/edit_layout.png" width="700px" >
|
35
35
|
|
36
|
+
To finish layout for tables, you check to off "Edit table position".
|
37
|
+
|
36
38
|
### Add Relation
|
37
39
|
|
38
40
|
In the ERD generated by default, there is no relation information between tables.
|
39
|
-
To add a relation to the ERD, You need to create relation information
|
40
|
-
There are several ways to give a relation information.
|
41
|
+
To add a relation to the ERD, You need to create relation information separately from "schema.rb",
|
42
|
+
and load it. There are several ways to give a relation information.
|
41
43
|
|
42
44
|
This section explains how to add relation information based on model information of Rails application.
|
43
45
|
Just as before, we will explain the procedure with the source code of Ruby On Rails Tutorial.
|
@@ -66,27 +68,73 @@ tables:
|
|
66
68
|
- users
|
67
69
|
```
|
68
70
|
|
69
|
-
3. To load the extracted relationship information, execute with the following command option.
|
71
|
+
3. To load the extracted relationship information, execute with the following `-f` command option.
|
70
72
|
```
|
71
73
|
$ schemard -f db/relation.metadata
|
72
74
|
```
|
73
75
|
|
74
|
-
4.
|
76
|
+
4. The extracted relationship information have been added to the ERD, when accessing `http://localhost:10080` in the Web browser.
|
75
77
|
|
76
78
|
<img src="https://raw.githubusercontent.com/wiki/xketanaka/schemard/images/relation_added.png" width="700px" >
|
77
79
|
|
78
80
|
|
79
81
|
### Localization
|
80
82
|
|
83
|
+
In the ERD generated by default, physical names are displayed as the table name and column name.
|
84
|
+
There are several ways to display aliases other than physical names as table names and column names,
|
85
|
+
This section explains the procedure to use the translation file for ActiveRecord.
|
86
|
+
|
87
|
+
1. There is a translation file placed to `config/locale/ja.yml`, and it have contents below
|
88
|
+
```
|
89
|
+
ja:
|
90
|
+
activerecord:
|
91
|
+
models:
|
92
|
+
<model_name>: <モデル名>
|
93
|
+
|
94
|
+
ja:
|
95
|
+
activerecord:
|
96
|
+
attributes:
|
97
|
+
<model_name>:
|
98
|
+
<column_name>: <column_name>
|
99
|
+
```
|
100
|
+
|
101
|
+
2. Specify the translation file with the -f option and execute it as follows
|
102
|
+
```
|
103
|
+
$ schemard -f db/relation.metadata -f config/locale/ja.yml
|
104
|
+
```
|
105
|
+
|
81
106
|
## Options
|
82
107
|
|
83
108
|
The following command line options can be specified.
|
84
109
|
|
110
|
+
* -i, --input-file ... Specify the `schema.rb` file. The default is `db/schema.rb`.
|
111
|
+
* -o, --output-file ... Specify the file to output layout information. The default is `schema.metadata`.
|
112
|
+
* -f, -m, --metadata-file ... Specify the file of Relation information file, or translation file. The default is no specification.
|
113
|
+
* --rdoc, --rdoc-enabled ... It is specified when acquiring meta-information from rdoc-format comment described in `schema.rb`. The default is no specification.
|
114
|
+
* --parse-db-comment-as ... Specify how to interpret the comment option in the migration information. `name`,`ignore` can be specified. When `name` is specified, the value specified by the comment option is interpreted as a logical name. `ignore` ignores the value of the comment option. The default is `ignore`.
|
115
|
+
* -l, --log-output ... Specify the log output destination. `stdout`,`stderr`, `<file name>` can be specified. The default is `stdout`.
|
116
|
+
* -s --silent --no-log-output ... Specify this when you do not want log output.
|
117
|
+
* -h, -host ... Specify the host name that WebServer listens on. The default is `127.0.0.1`.
|
118
|
+
* -p, --port ... Specify the port that WebServer listens on. The default is `10080`.
|
119
|
+
|
85
120
|
### Sub Command
|
86
121
|
|
87
122
|
The following sub-commands can be specified.
|
88
123
|
|
124
|
+
* generate-relations ... Extract relation information from model information of Rails application and output it to standard output in YAML format. You can specify the Rails.root directory with the `-d` option (the default is the current directory).
|
125
|
+
|
89
126
|
## Configuration
|
90
127
|
|
91
128
|
Instead of specifying it with command line options, you can specify options in the configuration file.
|
92
129
|
Place the configuration file as `.schemard.config` in the` schemard` command execution directory. The following entries can be specified.
|
130
|
+
|
131
|
+
* input_file
|
132
|
+
* output_file
|
133
|
+
* metadata_files
|
134
|
+
* rdoc_enabled
|
135
|
+
* parse_db_comment_as
|
136
|
+
* log_output
|
137
|
+
* webserver_host
|
138
|
+
* webserver_port
|
139
|
+
|
140
|
+
If both the setting file and the command line option are specified, the command line option takes precedence.
|
@@ -15,18 +15,24 @@ module SchemaRD
|
|
15
15
|
puts "<#{rails_root}> is not Rails.root Directory, Abort!"
|
16
16
|
puts "Usage: schemard -d <Rails.root.dir>"
|
17
17
|
else
|
18
|
+
ENV["RAILS_ENV"] = "production"
|
18
19
|
Dir.chdir(rails_root) do
|
19
20
|
require require_path.to_s
|
20
21
|
end
|
21
22
|
end
|
22
23
|
end
|
23
24
|
def ready?
|
24
|
-
defined?(Rails)
|
25
|
+
unless defined?(Rails)
|
26
|
+
puts "Rails application not found."
|
27
|
+
return false
|
28
|
+
end
|
29
|
+
unless Rails.application.config.eager_load
|
30
|
+
puts "Rails.application.eager_load was set to false, abort!"
|
31
|
+
return false
|
32
|
+
end
|
33
|
+
true
|
25
34
|
end
|
26
35
|
def run
|
27
|
-
Dir.glob(Rails.root + "app/models/**/*")
|
28
|
-
.reject{|path| Dir.exist?(path) }.each{|filepath| require filepath }
|
29
|
-
|
30
36
|
hash = ObjectSpace.each_object(Class)
|
31
37
|
.select{|o| o.ancestors.include?(ActiveRecord::Base) && o != ActiveRecord::Base }
|
32
38
|
.select{|o| o.table_name }
|
@@ -57,17 +63,21 @@ module SchemaRD
|
|
57
63
|
has_many_rels = relation_selector.call(:has_many)
|
58
64
|
belongs_to_rels = relation_selector.call(:belongs_to)
|
59
65
|
|
66
|
+
relations_to_table_names = ->(relations){
|
67
|
+
relations.map{|r| begin r.klass.table_name; rescue => e; nil; end }.compact
|
68
|
+
}
|
69
|
+
|
60
70
|
if has_one_rels.present?
|
61
|
-
hash[model.table_name]["has_one"] = has_one_rels
|
71
|
+
hash[model.table_name]["has_one"] = relations_to_table_names.call(has_one_rels)
|
62
72
|
end
|
63
73
|
if has_many_rels.present?
|
64
|
-
hash[model.table_name]["has_many"] = has_many_rels
|
74
|
+
hash[model.table_name]["has_many"] = relations_to_table_names.call(has_many_rels)
|
65
75
|
end
|
66
76
|
if belongs_to_rels.present?
|
67
|
-
hash[model.table_name]["belongs_to"] = belongs_to_rels
|
77
|
+
hash[model.table_name]["belongs_to"] = relations_to_table_names.call(belongs_to_rels)
|
68
78
|
end
|
69
79
|
end
|
70
|
-
puts YAML.dump({ "tables" => hash })
|
80
|
+
puts YAML.dump({ "tables" => hash.reject{|key,val| val.empty? } })
|
71
81
|
end
|
72
82
|
end
|
73
83
|
end
|
data/lib/schemard.rb
CHANGED
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schemard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ken TANAKA
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0.9'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.9'
|
41
41
|
description: |2
|
@@ -48,7 +48,7 @@ executables:
|
|
48
48
|
extensions: []
|
49
49
|
extra_rdoc_files: []
|
50
50
|
files:
|
51
|
-
- .gitignore
|
51
|
+
- ".gitignore"
|
52
52
|
- Gemfile
|
53
53
|
- LICENSE.txt
|
54
54
|
- README.ja.md
|
@@ -84,17 +84,17 @@ require_paths:
|
|
84
84
|
- lib
|
85
85
|
required_ruby_version: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '2.0'
|
90
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
91
|
requirements:
|
92
|
-
- -
|
92
|
+
- - ">="
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: '0'
|
95
95
|
requirements: []
|
96
96
|
rubyforge_project:
|
97
|
-
rubygems_version: 2.
|
97
|
+
rubygems_version: 2.5.2
|
98
98
|
signing_key:
|
99
99
|
specification_version: 4
|
100
100
|
summary: SchemaRD is a ERD Viewer for schema.rb.
|