schema_comments 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +2 -3
- data/Gemfile +1 -1
- data/README.md +2 -2
- data/gemfiles/Gemfile.rails-4.0 +1 -1
- data/gemfiles/Gemfile.rails-4.1 +2 -2
- data/lib/schema_comments/base.rb +4 -8
- data/lib/schema_comments/connection_adapters.rb +19 -37
- data/lib/schema_comments/migration.rb +4 -8
- data/lib/schema_comments/migrator.rb +4 -8
- data/lib/schema_comments/schema.rb +4 -8
- data/lib/schema_comments/schema_comment.rb +19 -8
- data/lib/schema_comments/version.rb +1 -1
- data/lib/schema_comments.rb +3 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dfd122cb2fedd33909167773b879f943f97c74fb
|
4
|
+
data.tar.gz: 880e604fc10669a33c3408c936a052c1d54d86fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e03c5f4bd9b55bc4aa9e4395eb809da23999739ce10676ad67d0c9ad3d03c6c2dacf0244b6722572cd2128d1d6f572da85f7d47d21995651bed87530f4b1110b
|
7
|
+
data.tar.gz: 1210f6fa4a9eccfb61ebfcc7065d9e0265d0d6d67e4b4f7214d9030fe2102562e727d63360c2e4310a245fe53a3fe804b8ba20d2f249330526002cd175f3fb12
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -173,8 +173,8 @@ rake db:annotate で以下のようなコメントを、モデル、テスト、
|
|
173
173
|
annotate_modelsは、達人プログラマーのDave Thomasさんが公開しているプラグインです。
|
174
174
|
http://repo.pragprog.com/svn/Public/plugins/annotate_models/
|
175
175
|
|
176
|
-
本プラグインでは、それを更に拡張したDave Boltonさんのプラグイン
|
177
|
-
|
176
|
+
本プラグインでは、それを更に拡張したDave Boltonさんのプラグインannotate_models
|
177
|
+
( リポジトリは削除された様子・・・ )をベースに拡張を加えています。
|
178
178
|
|
179
179
|
## License
|
180
180
|
Copyright (c) 2008 Takeshi AKIMA, released under the Ruby License
|
data/gemfiles/Gemfile.rails-4.0
CHANGED
data/gemfiles/Gemfile.rails-4.1
CHANGED
@@ -3,9 +3,9 @@ source "http://rubygems.org"
|
|
3
3
|
gem "activesupport", "~> 4.1.0"
|
4
4
|
gem "activerecord" , "~> 4.1.0"
|
5
5
|
|
6
|
-
group :test do
|
6
|
+
group :development, :test do
|
7
7
|
gem "sqlite3", :platform => :ruby
|
8
|
-
gem "mysql2" , :platform => :ruby
|
8
|
+
gem "mysql2" , "~> 0.3.13", :platform => :ruby
|
9
9
|
gem "rails"
|
10
10
|
end
|
11
11
|
|
data/lib/schema_comments/base.rb
CHANGED
@@ -1,11 +1,7 @@
|
|
1
1
|
module SchemaComments
|
2
2
|
module Base
|
3
|
-
def self.
|
4
|
-
mod.
|
5
|
-
mod.instance_eval do
|
6
|
-
alias :columns_without_schema_comments :columns
|
7
|
-
alias :columns :columns_with_schema_comments
|
8
|
-
end
|
3
|
+
def self.prepended(mod)
|
4
|
+
mod.singleton_class.prepend ClassMethods
|
9
5
|
mod.ignore_pattern_to_export_i18n = /\[.*\]/
|
10
6
|
end
|
11
7
|
|
@@ -14,8 +10,8 @@ module SchemaComments
|
|
14
10
|
@table_comment ||= connection.table_comment(table_name)
|
15
11
|
end
|
16
12
|
|
17
|
-
def
|
18
|
-
result =
|
13
|
+
def columns
|
14
|
+
result = super
|
19
15
|
unless @column_comments_loaded
|
20
16
|
column_comment_hash = connection.column_comments(table_name)
|
21
17
|
result.each do |column|
|
@@ -11,18 +11,13 @@ module SchemaComments
|
|
11
11
|
end
|
12
12
|
|
13
13
|
module TableDefinition
|
14
|
-
def self.included(mod)
|
15
|
-
mod.module_eval do
|
16
|
-
alias_method_chain(:column, :schema_comments)
|
17
|
-
end
|
18
|
-
end
|
19
14
|
attr_accessor :comment
|
20
15
|
|
21
|
-
def
|
22
|
-
|
16
|
+
def column(name, type, options = {})
|
17
|
+
result = super(name, type, options)
|
23
18
|
column = self[name]
|
24
19
|
column.comment = options[:comment]
|
25
|
-
|
20
|
+
result
|
26
21
|
end
|
27
22
|
end
|
28
23
|
|
@@ -81,22 +76,9 @@ module SchemaComments
|
|
81
76
|
end
|
82
77
|
|
83
78
|
module ConcreteAdapter
|
84
|
-
def self.included(mod)
|
85
|
-
mod.module_eval do
|
86
|
-
alias_method_chain :columns , :schema_comments
|
87
|
-
alias_method_chain :create_table , :schema_comments
|
88
|
-
alias_method_chain :drop_table , :schema_comments
|
89
|
-
alias_method_chain :rename_table , :schema_comments
|
90
|
-
alias_method_chain :remove_column, :schema_comments
|
91
|
-
alias_method_chain :add_column , :schema_comments
|
92
|
-
alias_method_chain :change_column, :schema_comments
|
93
|
-
alias_method_chain :rename_column, :schema_comments
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
79
|
#TODO: columnsメソッドに第二引数移行がないので本来は消すべき?
|
98
|
-
def
|
99
|
-
result =
|
80
|
+
def columns(table_name, name = nil, &block)
|
81
|
+
result = super(table_name)
|
100
82
|
column_comment_hash = column_comments(table_name)
|
101
83
|
result.each do |column|
|
102
84
|
column.comment = column_comment_hash[column.name]
|
@@ -104,9 +86,9 @@ module SchemaComments
|
|
104
86
|
result
|
105
87
|
end
|
106
88
|
|
107
|
-
def
|
89
|
+
def create_table(table_name, options = {}, &block)
|
108
90
|
table_def = nil
|
109
|
-
result =
|
91
|
+
result = super(table_name, options) do |t|
|
110
92
|
table_def = t
|
111
93
|
yield(t)
|
112
94
|
end
|
@@ -117,19 +99,19 @@ module SchemaComments
|
|
117
99
|
result
|
118
100
|
end
|
119
101
|
|
120
|
-
def
|
121
|
-
result =
|
102
|
+
def drop_table(table_name, *args, &block)
|
103
|
+
result = super(table_name, *args)
|
122
104
|
delete_schema_comments(table_name) unless @ignore_drop_table
|
123
105
|
result
|
124
106
|
end
|
125
107
|
|
126
|
-
def
|
127
|
-
result =
|
108
|
+
def rename_table(table_name, new_name)
|
109
|
+
result = super(table_name, new_name)
|
128
110
|
update_schema_comments_table_name(table_name, new_name)
|
129
111
|
result
|
130
112
|
end
|
131
113
|
|
132
|
-
def
|
114
|
+
def remove_column(table_name, *column_names)
|
133
115
|
# sqlite3ではremove_columnがないので、以下のフローでスキーマ更新します。
|
134
116
|
# 1. CREATE TEMPORARY TABLE "altered_xxxxxx" (・・・)
|
135
117
|
# 2. PRAGMA index_list("xxxxxx")
|
@@ -140,7 +122,7 @@ module SchemaComments
|
|
140
122
|
#
|
141
123
|
# このdrop tableの際に、schema_commentsを変更しないようにフラグを立てています。
|
142
124
|
@ignore_drop_table = true
|
143
|
-
|
125
|
+
super(table_name, *column_names)
|
144
126
|
column_names.each do |column_name|
|
145
127
|
delete_schema_comments(table_name, column_name)
|
146
128
|
end
|
@@ -148,25 +130,25 @@ module SchemaComments
|
|
148
130
|
@ignore_drop_table = false
|
149
131
|
end
|
150
132
|
|
151
|
-
def
|
133
|
+
def add_column(table_name, column_name, type, options = {})
|
152
134
|
comment = options.delete(:comment)
|
153
|
-
result =
|
135
|
+
result = super(table_name, column_name, type, options)
|
154
136
|
column_comment(table_name, column_name, comment) if comment
|
155
137
|
result
|
156
138
|
end
|
157
139
|
|
158
|
-
def
|
140
|
+
def change_column(table_name, column_name, type, options = {})
|
159
141
|
comment = options.delete(:comment)
|
160
142
|
@ignore_drop_table = true
|
161
|
-
result =
|
143
|
+
result = super(table_name, column_name, type, options)
|
162
144
|
column_comment(table_name, column_name, comment) if comment
|
163
145
|
result
|
164
146
|
ensure
|
165
147
|
@ignore_drop_table = false
|
166
148
|
end
|
167
149
|
|
168
|
-
def
|
169
|
-
result =
|
150
|
+
def rename_column(table_name, column_name, new_column_name)
|
151
|
+
result = super(table_name, column_name, new_column_name)
|
170
152
|
comment = update_schema_comments_column_name(table_name, column_name, new_column_name)
|
171
153
|
result
|
172
154
|
end
|
@@ -1,17 +1,13 @@
|
|
1
1
|
module SchemaComments
|
2
2
|
module Migration
|
3
|
-
def self.
|
4
|
-
mod.
|
5
|
-
mod.instance_eval do
|
6
|
-
alias :migrate_without_schema_comments :migrate
|
7
|
-
alias :migrate :migrate_with_schema_comments
|
8
|
-
end
|
3
|
+
def self.prepended(mod)
|
4
|
+
mod.singleton_class.prepend(ClassMethods)
|
9
5
|
end
|
10
6
|
|
11
7
|
module ClassMethods
|
12
|
-
def
|
8
|
+
def migrate(*args, &block)
|
13
9
|
SchemaComments::SchemaComment.yaml_access do
|
14
|
-
|
10
|
+
super(*args, &block)
|
15
11
|
end
|
16
12
|
end
|
17
13
|
end
|
@@ -1,17 +1,13 @@
|
|
1
1
|
module SchemaComments
|
2
2
|
module Migrator
|
3
|
-
def self.
|
4
|
-
mod.
|
5
|
-
mod.instance_eval do
|
6
|
-
alias :migrate_without_schema_comments :migrate
|
7
|
-
alias :migrate :migrate_with_schema_comments
|
8
|
-
end
|
3
|
+
def self.prepend(mod)
|
4
|
+
mod.singleton_class.prepend(ClassMethods)
|
9
5
|
end
|
10
6
|
|
11
7
|
module ClassMethods
|
12
|
-
def
|
8
|
+
def migrate(*args, &block)
|
13
9
|
SchemaComments::SchemaComment.yaml_access do
|
14
|
-
|
10
|
+
super(*args, &block)
|
15
11
|
end
|
16
12
|
end
|
17
13
|
end
|
@@ -1,17 +1,13 @@
|
|
1
1
|
module SchemaComments
|
2
2
|
module Schema
|
3
|
-
def self.
|
4
|
-
mod.
|
5
|
-
mod.instance_eval do
|
6
|
-
alias :define_without_schema_comments :define
|
7
|
-
alias :define :define_with_schema_comments
|
8
|
-
end
|
3
|
+
def self.prepended(mod)
|
4
|
+
mod.singleton_class.prepend(ClassMethods)
|
9
5
|
end
|
10
6
|
|
11
7
|
module ClassMethods
|
12
|
-
def
|
8
|
+
def define(*args, &block)
|
13
9
|
SchemaComments::SchemaComment.yaml_access do
|
14
|
-
|
10
|
+
super(*args, &block)
|
15
11
|
end
|
16
12
|
end
|
17
13
|
end
|
@@ -82,15 +82,16 @@ module SchemaComments
|
|
82
82
|
db = SortedStore.new(SchemaComments.yaml_path)
|
83
83
|
result = nil
|
84
84
|
# t = Time.now.to_f
|
85
|
-
db
|
86
|
-
|
87
|
-
|
85
|
+
@yaml_transaction = db
|
86
|
+
begin
|
87
|
+
db.transaction do
|
88
88
|
db[TABLE_KEY] ||= {}
|
89
89
|
db[COLUMN_KEY] ||= {}
|
90
|
+
SortedStore.validate_yaml!(db)
|
90
91
|
result = yield(db) if block_given?
|
91
|
-
ensure
|
92
|
-
@yaml_transaction = nil
|
93
92
|
end
|
93
|
+
ensure
|
94
|
+
@yaml_transaction = nil
|
94
95
|
end
|
95
96
|
# puts("SchemaComment#yaml_access %fms from %s" % [Time.now.to_f - t, caller[0].gsub(/^.+:in /, '')])
|
96
97
|
result
|
@@ -110,7 +111,20 @@ module SchemaComments
|
|
110
111
|
root.to_yaml(@opt)
|
111
112
|
end
|
112
113
|
|
114
|
+
def self.validate_yaml!(root)
|
115
|
+
table_comments = (root['table_comments'] ||= {})
|
116
|
+
column_comments = (root['column_comments'] ||= {})
|
117
|
+
# raise YamlError, "Broken schame_comments.yml by invalid root: #{root.inspect}" unless root.is_a?(Hash)
|
118
|
+
raise YamlError, "Broken schame_comments.yml by invalid table_comments" unless table_comments.is_a?(Hash)
|
119
|
+
raise YamlError, "Broken schame_comments.yml by invalid_column_comments" unless column_comments.is_a?(Hash)
|
120
|
+
column_comments.each do |table_name, value|
|
121
|
+
next if value.nil?
|
122
|
+
raise YamlError, "Broken schame_comments.yml by invalid column_comments for #{table_name}" unless value.is_a?(Hash)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
113
126
|
def self.sort_yaml_content!(root)
|
127
|
+
self.validate_yaml!(root)
|
114
128
|
table_comments = (root['table_comments'] ||= {})
|
115
129
|
column_comments = (root['column_comments'] ||= {})
|
116
130
|
# 大元は
|
@@ -121,16 +135,13 @@ module SchemaComments
|
|
121
135
|
# その他
|
122
136
|
# ...
|
123
137
|
# の順番です。
|
124
|
-
raise YamlError, "Broken schame_comments.yml" unless root.is_a?(Hash)
|
125
138
|
root.extend(HashKeyOrderable)
|
126
139
|
root.key_order = %w(table_comments column_comments)
|
127
140
|
# table_comments はテーブル名のアルファベット順
|
128
141
|
table_names = ActiveRecord::Base.connection.tables.sort - ['schema_migrations']
|
129
|
-
raise YamlError, "Broken schame_comments.yml" unless table_comments.is_a?(Hash)
|
130
142
|
table_comments.extend(HashKeyOrderable)
|
131
143
|
table_comments.key_order = table_names
|
132
144
|
# column_comments もテーブル名のアルファベット順
|
133
|
-
raise YamlError, "Broken schame_comments.yml" unless column_comments.is_a?(Hash)
|
134
145
|
column_comments.extend(HashKeyOrderable)
|
135
146
|
column_comments.key_order = table_names
|
136
147
|
# column_comments の各値はテーブルのカラム順
|
data/lib/schema_comments.rb
CHANGED
@@ -28,13 +28,13 @@ module SchemaComments
|
|
28
28
|
ar_class = "ActiveRecord::#{base_name}".constantize
|
29
29
|
sc_class = "SchemaComments::#{base_name}".constantize
|
30
30
|
unless ar_class.ancestors.include?(sc_class)
|
31
|
-
ar_class.__send__(:
|
31
|
+
ar_class.__send__(:prepend, sc_class)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
unless ActiveRecord::ConnectionAdapters::AbstractAdapter.ancestors.include?(SchemaComments::ConnectionAdapters::Adapter)
|
36
36
|
ActiveRecord::ConnectionAdapters::AbstractAdapter.module_eval do
|
37
|
-
|
37
|
+
prepend SchemaComments::ConnectionAdapters::Adapter
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -44,7 +44,7 @@ module SchemaComments
|
|
44
44
|
require("active_record/connection_adapters/#{adapter.downcase}_adapter")
|
45
45
|
adapter_class = ('ActiveRecord::ConnectionAdapters::' << "#{adapter}Adapter").constantize
|
46
46
|
adapter_class.module_eval do
|
47
|
-
|
47
|
+
prepend SchemaComments::ConnectionAdapters::ConcreteAdapter
|
48
48
|
end
|
49
49
|
rescue Exception => e
|
50
50
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schema_comments
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- akm
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -141,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
141
|
version: '0'
|
142
142
|
requirements: []
|
143
143
|
rubyforge_project:
|
144
|
-
rubygems_version: 2.
|
144
|
+
rubygems_version: 2.5.1
|
145
145
|
signing_key:
|
146
146
|
specification_version: 4
|
147
147
|
summary: schema_comments generates extra methods dynamically for attribute which has
|