pg_power 1.4.0 → 1.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.
@@ -33,6 +33,15 @@ module PgPower::ConnectionAdapters::AbstractAdapter::CommentMethods
33
33
 
34
34
  end
35
35
 
36
+ # Sets the comment on the given index
37
+ #
38
+ # ===== Example
39
+ # ====== Setting comment on the index_pets_on_breed_id index
40
+ # set_index_comment 'index_pets_on_breed_id', 'Index on breed_id'
41
+ def set_index_comment(index_name, comment)
42
+
43
+ end
44
+
36
45
  # Removes any comment from the given table.
37
46
  #
38
47
  # ===== Example
@@ -59,4 +68,13 @@ module PgPower::ConnectionAdapters::AbstractAdapter::CommentMethods
59
68
  def remove_column_comments(table_name, *column_names)
60
69
 
61
70
  end
71
+
72
+ # Removes the comment from the given index
73
+ #
74
+ # ===== Example
75
+ # ====== Removing comment from the index_pets_on_breed_id index
76
+ # remove_index_comment :index_pets_on_breed_id
77
+ def remove_index_comment(index_name)
78
+
79
+ end
62
80
  end
@@ -31,6 +31,14 @@ module PgPower::ConnectionAdapters::PostgreSQLAdapter::CommentMethods
31
31
  end
32
32
  end
33
33
 
34
+ # Sets the given comment on the given index
35
+ # @param [String, Symbol] index_name The name of the index
36
+ # @param [String, Symbol] comment The comment to set on the index
37
+ def set_index_comment(index_name, comment)
38
+ sql = "COMMENT ON INDEX #{quote_string(index_name)} IS $$#{comment}$$;"
39
+ execute sql
40
+ end
41
+
34
42
  # Executes SQL to remove comment on passed table.
35
43
  # @param [String, Symbol] table_name
36
44
  def remove_table_comment(table_name)
@@ -53,6 +61,13 @@ module PgPower::ConnectionAdapters::PostgreSQLAdapter::CommentMethods
53
61
  end
54
62
  end
55
63
 
64
+ # Removes any comment from the given index
65
+ # @param [String, Symbol] index_name The name of the index
66
+ def remove_index_comment(index_name)
67
+ sql = "COMMENT ON INDEX #{quote_string(index_name)} IS NULL;"
68
+ execute sql
69
+ end
70
+
56
71
  # Fetches all comments related to passed table.
57
72
  # I returns table comment and column comments as well.
58
73
  # ===Example
@@ -61,7 +76,7 @@ module PgPower::ConnectionAdapters::PostgreSQLAdapter::CommentMethods
61
76
  # ["email", "Comment on email column"]]
62
77
  def comments(table_name)
63
78
  relation_name, schema_name = table_name.split(".", 2).reverse
64
- schema_name ||= "public"
79
+ schema_name ||= :public
65
80
 
66
81
  com = select_all <<-SQL
67
82
  SELECT a.attname AS column_name, d.description AS comment
@@ -76,4 +91,24 @@ module PgPower::ConnectionAdapters::PostgreSQLAdapter::CommentMethods
76
91
  [ row['column_name'], row['comment'] ]
77
92
  end
78
93
  end
94
+
95
+ # Fetches index comments
96
+ # returns an Array of Arrays, each element representing a single index with comment as
97
+ # [ 'schema_name', 'index_name', 'comment' ]
98
+ def index_comments
99
+ query = <<-SQL
100
+ SELECT c.relname AS index_name, d.description AS comment, pg_namespace.nspname AS schema_name
101
+ FROM pg_description d
102
+ JOIN pg_class c ON c.oid = d.objoid
103
+ JOIN pg_namespace ON c.relnamespace = pg_namespace.oid
104
+ WHERE c.relkind = 'i'
105
+ ORDER BY schema_name, index_name
106
+ SQL
107
+
108
+ com = select_all(query)
109
+
110
+ com.map do |row|
111
+ [ row['schema_name'], row['index_name'], row['comment'] ]
112
+ end
113
+ end
79
114
  end
@@ -8,7 +8,7 @@ module PgPower::Migration::CommandRecorder::CommentMethods
8
8
 
9
9
  # :nodoc:
10
10
  def remove_table_comment(*args)
11
- record(:remove_table_comments, args)
11
+ record(:remove_table_comment, args)
12
12
  end
13
13
 
14
14
  # :nodoc:
@@ -31,6 +31,16 @@ module PgPower::Migration::CommandRecorder::CommentMethods
31
31
  record(:remove_column_comments, args)
32
32
  end
33
33
 
34
+ # :nodoc:
35
+ def set_index_comment(*args)
36
+ record(:set_index_comment, args)
37
+ end
38
+
39
+ # :nodoc:
40
+ def remove_index_comment(*args)
41
+ record(:remove_index_comment, args)
42
+ end
43
+
34
44
  # :nodoc:
35
45
  def invert_set_table_comment(args)
36
46
  table_name = args.first
@@ -49,4 +59,10 @@ module PgPower::Migration::CommandRecorder::CommentMethods
49
59
  i_args = [args[0]] + args[1].collect{|name, value| name }
50
60
  [:remove_column_comments, i_args]
51
61
  end
62
+
63
+ # :nodoc:
64
+ def invert_set_index_comment(args)
65
+ index_name = args.first
66
+ [:remove_index_comment, [index_name]]
67
+ end
52
68
  end
@@ -8,9 +8,21 @@ module PgPower::SchemaDumper::CommentMethods
8
8
  table_names = @connection.tables.sort
9
9
  table_names += get_non_public_schema_table_names.sort
10
10
 
11
+ # Dump table and column comments
11
12
  table_names.each do |table_name|
12
13
  dump_comments(table_name, stream)
13
14
  end
15
+
16
+ # Now dump index comments
17
+ unless (index_comments = @connection.index_comments).empty?
18
+ index_comments.each do |row|
19
+ schema_name = row[0]
20
+ index_name = schema_name == 'public' ? "'#{row[1]}'" : "'#{schema_name}.#{row[1]}'"
21
+ comment = format_comment(row[2])
22
+ stream.puts " set_index_comment #{index_name}, '#{comment}'"
23
+ end
24
+ stream.puts
25
+ end
14
26
  end
15
27
 
16
28
  # Finds all comments related to passed table and writes appropriated
@@ -19,7 +31,7 @@ module PgPower::SchemaDumper::CommentMethods
19
31
  unless (comments = @connection.comments(table_name)).empty?
20
32
  comment_statements = comments.map do |row|
21
33
  column_name = row[0]
22
- comment = row[1].gsub(/'/, "\\\\'")
34
+ comment = format_comment(row[1])
23
35
  if column_name
24
36
  " set_column_comment '#{table_name}', '#{column_name}', '#{comment}'"
25
37
  else
@@ -33,4 +45,10 @@ module PgPower::SchemaDumper::CommentMethods
33
45
  end
34
46
  end
35
47
  private :dump_comments
48
+
49
+ # Escape out single quotes from comments
50
+ def format_comment(comment)
51
+ comment.gsub(/'/, "\\\\'")
52
+ end
53
+ private :format_comment
36
54
  end
@@ -1,4 +1,4 @@
1
1
  module PgPower
2
2
  # Version of pg_power gem.
3
- VERSION = "1.4.0"
3
+ VERSION = "1.5.0"
4
4
  end
metadata CHANGED
@@ -1,10 +1,15 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: pg_power
3
- version: !ruby/object:Gem::Version
4
- version: 1.4.0
3
+ version: !ruby/object:Gem::Version
4
+ hash: 3
5
5
  prerelease:
6
+ segments:
7
+ - 1
8
+ - 5
9
+ - 0
10
+ version: 1.5.0
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Potapov Sergey
9
14
  - Arthur Shagall
10
15
  - Artem Ignatyev
@@ -12,129 +17,132 @@ authors:
12
17
  autorequire:
13
18
  bindir: bin
14
19
  cert_chain: []
15
- date: 2013-05-01 00:00:00.000000000 Z
16
- dependencies:
17
- - !ruby/object:Gem::Dependency
18
- name: pg
19
- requirement: !ruby/object:Gem::Requirement
20
+
21
+ date: 2013-05-14 00:00:00 Z
22
+ dependencies:
23
+ - !ruby/object:Gem::Dependency
24
+ requirement: &id001 !ruby/object:Gem::Requirement
20
25
  none: false
21
- requirements:
22
- - - ! '>='
23
- - !ruby/object:Gem::Version
24
- version: '0'
25
- type: :runtime
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ version_requirements: *id001
34
+ name: pg
26
35
  prerelease: false
27
- version_requirements: !ruby/object:Gem::Requirement
36
+ type: :runtime
37
+ - !ruby/object:Gem::Dependency
38
+ requirement: &id002 !ruby/object:Gem::Requirement
28
39
  none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: '0'
33
- - !ruby/object:Gem::Dependency
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ version_requirements: *id002
34
48
  name: rspec-rails
35
- requirement: !ruby/object:Gem::Requirement
36
- none: false
37
- requirements:
38
- - - ! '>='
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- type: :runtime
42
49
  prerelease: false
43
- version_requirements: !ruby/object:Gem::Requirement
44
- none: false
45
- requirements:
46
- - - ! '>='
47
- - !ruby/object:Gem::Version
48
- version: '0'
49
- - !ruby/object:Gem::Dependency
50
- name: rails
51
- requirement: !ruby/object:Gem::Requirement
50
+ type: :runtime
51
+ - !ruby/object:Gem::Dependency
52
+ requirement: &id003 !ruby/object:Gem::Requirement
52
53
  none: false
53
- requirements:
54
+ requirements:
54
55
  - - ~>
55
- - !ruby/object:Gem::Version
56
- version: '3.1'
56
+ - !ruby/object:Gem::Version
57
+ hash: 5
58
+ segments:
59
+ - 3
60
+ - 1
61
+ version: "3.1"
62
+ version_requirements: *id003
63
+ name: rails
64
+ prerelease: false
57
65
  type: :runtime
66
+ - !ruby/object:Gem::Dependency
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ version_requirements: *id004
77
+ name: rcov
58
78
  prerelease: false
59
- version_requirements: !ruby/object:Gem::Requirement
79
+ type: :development
80
+ - !ruby/object:Gem::Dependency
81
+ requirement: &id005 !ruby/object:Gem::Requirement
60
82
  none: false
61
- requirements:
62
- - - ~>
63
- - !ruby/object:Gem::Version
64
- version: '3.1'
65
- - !ruby/object:Gem::Dependency
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ version_requirements: *id005
66
91
  name: yard
67
- requirement: !ruby/object:Gem::Requirement
68
- none: false
69
- requirements:
70
- - - ! '>='
71
- - !ruby/object:Gem::Version
72
- version: '0'
73
- type: :development
74
92
  prerelease: false
75
- version_requirements: !ruby/object:Gem::Requirement
93
+ type: :development
94
+ - !ruby/object:Gem::Dependency
95
+ requirement: &id006 !ruby/object:Gem::Requirement
76
96
  none: false
77
- requirements:
78
- - - ! '>='
79
- - !ruby/object:Gem::Version
80
- version: '0'
81
- - !ruby/object:Gem::Dependency
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ version_requirements: *id006
82
105
  name: metrical
83
- requirement: !ruby/object:Gem::Requirement
84
- none: false
85
- requirements:
86
- - - ! '>='
87
- - !ruby/object:Gem::Version
88
- version: '0'
89
- type: :development
90
106
  prerelease: false
91
- version_requirements: !ruby/object:Gem::Requirement
107
+ type: :development
108
+ - !ruby/object:Gem::Dependency
109
+ requirement: &id007 !ruby/object:Gem::Requirement
92
110
  none: false
93
- requirements:
94
- - - ! '>='
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ version_requirements: *id007
98
119
  name: jeweler
99
- requirement: !ruby/object:Gem::Requirement
100
- none: false
101
- requirements:
102
- - - ! '>='
103
- - !ruby/object:Gem::Version
104
- version: '0'
105
- type: :development
106
120
  prerelease: false
107
- version_requirements: !ruby/object:Gem::Requirement
108
- none: false
109
- requirements:
110
- - - ! '>='
111
- - !ruby/object:Gem::Version
112
- version: '0'
113
- - !ruby/object:Gem::Dependency
114
- name: ruby-debug19
115
- requirement: !ruby/object:Gem::Requirement
116
- none: false
117
- requirements:
118
- - - ! '>='
119
- - !ruby/object:Gem::Version
120
- version: '0'
121
121
  type: :development
122
- prerelease: false
123
- version_requirements: !ruby/object:Gem::Requirement
122
+ - !ruby/object:Gem::Dependency
123
+ requirement: &id008 !ruby/object:Gem::Requirement
124
124
  none: false
125
- requirements:
126
- - - ! '>='
127
- - !ruby/object:Gem::Version
128
- version: '0'
129
- description: ActiveRecord extensions for PostgreSQL. Provides useful tools for schema,
130
- foreign_key, index, comment and extensios manipulations in migrations.
131
- email:
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ hash: 3
129
+ segments:
130
+ - 0
131
+ version: "0"
132
+ version_requirements: *id008
133
+ name: ruby-debug
134
+ prerelease: false
135
+ type: :development
136
+ description: ActiveRecord extensions for PostgreSQL. Provides useful tools for schema, foreign_key, index, comment and extensios manipulations in migrations.
137
+ email:
132
138
  - rubygems@tmxcredit.com
133
139
  executables: []
140
+
134
141
  extensions: []
135
- extra_rdoc_files:
142
+
143
+ extra_rdoc_files:
136
144
  - README.markdown
137
- files:
145
+ files:
138
146
  - README.markdown
139
147
  - lib/core_ext/active_record/connection_adapters/abstract/schema_statements.rb
140
148
  - lib/core_ext/active_record/connection_adapters/postgresql_adapter.rb
@@ -178,29 +186,36 @@ files:
178
186
  - lib/tasks/pg_power_tasks.rake
179
187
  homepage: https://github.com/TMXCredit/pg_power
180
188
  licenses: []
189
+
181
190
  post_install_message:
182
191
  rdoc_options: []
183
- require_paths:
192
+
193
+ require_paths:
184
194
  - lib
185
- required_ruby_version: !ruby/object:Gem::Requirement
195
+ required_ruby_version: !ruby/object:Gem::Requirement
186
196
  none: false
187
- requirements:
188
- - - ! '>='
189
- - !ruby/object:Gem::Version
190
- version: '0'
191
- segments:
197
+ requirements:
198
+ - - ">="
199
+ - !ruby/object:Gem::Version
200
+ hash: 3
201
+ segments:
192
202
  - 0
193
- hash: 509296341304110115
194
- required_rubygems_version: !ruby/object:Gem::Requirement
203
+ version: "0"
204
+ required_rubygems_version: !ruby/object:Gem::Requirement
195
205
  none: false
196
- requirements:
197
- - - ! '>='
198
- - !ruby/object:Gem::Version
199
- version: '0'
206
+ requirements:
207
+ - - ">="
208
+ - !ruby/object:Gem::Version
209
+ hash: 3
210
+ segments:
211
+ - 0
212
+ version: "0"
200
213
  requirements: []
214
+
201
215
  rubyforge_project:
202
216
  rubygems_version: 1.8.24
203
217
  signing_key:
204
218
  specification_version: 3
205
219
  summary: ActiveRecord extensions for PostgreSQL.
206
220
  test_files: []
221
+