pg_power 1.5.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +11 -0
- data/lib/pg_power/connection_adapters/postgresql_adapter.rb +2 -0
- data/lib/pg_power/connection_adapters/postgresql_adapter/view_methods.rb +17 -0
- data/lib/pg_power/migration/command_recorder.rb +2 -0
- data/lib/pg_power/migration/command_recorder/view_methods.rb +24 -0
- data/lib/pg_power/schema_dumper.rb +3 -0
- data/lib/pg_power/schema_dumper/view_methods.rb +27 -0
- data/lib/pg_power/tools.rb +27 -1
- data/lib/pg_power/version.rb +1 -1
- metadata +118 -132
data/README.markdown
CHANGED
@@ -235,6 +235,17 @@ Unload extension module:
|
|
235
235
|
drop_extension "fuzzystrmatch"
|
236
236
|
```
|
237
237
|
|
238
|
+
## Views
|
239
|
+
|
240
|
+
Version 1.6.0 introduces experimental support for creating views. This API should only be used with the understanding
|
241
|
+
that it is preliminary 'alpha' at best.
|
242
|
+
|
243
|
+
### Example
|
244
|
+
|
245
|
+
```ruby
|
246
|
+
create_view "demography.citizens_view", "select * from demography.citizens"
|
247
|
+
```
|
248
|
+
|
238
249
|
## Tools
|
239
250
|
|
240
251
|
PgPower::Tools provides number of useful methods:
|
@@ -11,6 +11,7 @@ module PgPower::ConnectionAdapters::PostgreSQLAdapter
|
|
11
11
|
autoload :ForeignerMethods, 'pg_power/connection_adapters/postgresql_adapter/foreigner_methods'
|
12
12
|
autoload :IndexMethods, 'pg_power/connection_adapters/postgresql_adapter/index_methods'
|
13
13
|
autoload :TranslateException, 'pg_power/connection_adapters/postgresql_adapter/translate_exception'
|
14
|
+
autoload :ViewMethods, 'pg_power/connection_adapters/postgresql_adapter/view_methods'
|
14
15
|
|
15
16
|
include ExtensionMethods
|
16
17
|
include SchemaMethods
|
@@ -18,4 +19,5 @@ module PgPower::ConnectionAdapters::PostgreSQLAdapter
|
|
18
19
|
include ForeignerMethods
|
19
20
|
include IndexMethods
|
20
21
|
include TranslateException
|
22
|
+
include ViewMethods
|
21
23
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Provides methods to extend {ActiveRecord::ConnectionAdapters::PostgreSQLAdapter}
|
2
|
+
# to support views feature.
|
3
|
+
module PgPower::ConnectionAdapters::PostgreSQLAdapter::ViewMethods
|
4
|
+
# Creates new view in DB.
|
5
|
+
# @param [String, Symbol] view_name
|
6
|
+
# @param [String] view_definition
|
7
|
+
def create_view(view_name, view_definition)
|
8
|
+
::PgPower::Tools.create_view(view_name, view_definition)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Drops view in DB.
|
12
|
+
# @param [String, Symbol] view_name
|
13
|
+
def drop_view(view_name)
|
14
|
+
::PgPower::Tools.drop_view(view_name)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -7,9 +7,11 @@ module PgPower::Migration::CommandRecorder
|
|
7
7
|
autoload :SchemaMethods
|
8
8
|
autoload :CommentMethods
|
9
9
|
autoload :ForeignerMethods
|
10
|
+
autoload :ViewMethods
|
10
11
|
|
11
12
|
include ExtensionMethods
|
12
13
|
include SchemaMethods
|
13
14
|
include CommentMethods
|
14
15
|
include ForeignerMethods
|
16
|
+
include ViewMethods
|
15
17
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Provides methods to extend {ActiveRecord::Migration::CommandRecorder} to
|
2
|
+
# support view feature.
|
3
|
+
module PgPower::Migration::CommandRecorder::ViewMethods
|
4
|
+
|
5
|
+
# Creates PostgreSQL view
|
6
|
+
# @param [String, Symbol] view_name
|
7
|
+
# @param [String] view_definition
|
8
|
+
def create_view(*args)
|
9
|
+
record(:create_view, args)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Drops view in DB.
|
13
|
+
# @param [String, Symbol] view_name
|
14
|
+
def drop_view(*args)
|
15
|
+
record(:drop_view, args)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Inverts creation of a view in DB.
|
19
|
+
# @param [String, Symbol] view_name
|
20
|
+
def invert_create_view(args)
|
21
|
+
[:drop_view, [args.first]]
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -9,17 +9,20 @@ module PgPower::SchemaDumper
|
|
9
9
|
autoload :CommentMethods
|
10
10
|
autoload :SchemaMethods
|
11
11
|
autoload :ForeignerMethods
|
12
|
+
autoload :ViewMethods
|
12
13
|
|
13
14
|
include ExtensionMethods
|
14
15
|
include CommentMethods
|
15
16
|
include SchemaMethods
|
16
17
|
include ForeignerMethods
|
18
|
+
include ViewMethods
|
17
19
|
|
18
20
|
included do
|
19
21
|
alias_method_chain :header, :schemas
|
20
22
|
alias_method_chain :header, :extensions
|
21
23
|
|
22
24
|
alias_method_chain :tables, :schemas
|
25
|
+
alias_method_chain :tables, :views
|
23
26
|
alias_method_chain :tables, :comments
|
24
27
|
alias_method_chain :tables, :foreign_keys
|
25
28
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Extends ActiveRecord::SchemaDumper class to dump views
|
2
|
+
module PgPower::SchemaDumper::ViewMethods
|
3
|
+
# Dump create view statements
|
4
|
+
def tables_with_views(stream)
|
5
|
+
tables_without_views(stream)
|
6
|
+
views(stream)
|
7
|
+
stream
|
8
|
+
end
|
9
|
+
|
10
|
+
# Generates code to create views.
|
11
|
+
def views(stream)
|
12
|
+
# Don't create "system" views.
|
13
|
+
view_names = PgPower::Tools.views
|
14
|
+
view_names.each do |options|
|
15
|
+
write_view_definition(stream, options["table_schema"], options["table_name"], options["view_definition"])
|
16
|
+
end
|
17
|
+
stream << "\n"
|
18
|
+
end
|
19
|
+
private :views
|
20
|
+
|
21
|
+
# Generates code to create view.
|
22
|
+
def write_view_definition(stream, table_schema, table_name, view_definition)
|
23
|
+
stream << " create_view \"#{table_schema}.#{table_name}\", \"#{view_definition}\"\n"
|
24
|
+
end
|
25
|
+
private :write_view_definition
|
26
|
+
|
27
|
+
end
|
data/lib/pg_power/tools.rb
CHANGED
@@ -6,6 +6,9 @@ module PgPower
|
|
6
6
|
# PgPower::Tools.drop_schema "services" # => remove the schema
|
7
7
|
# PgPower::Tools.schemas # => ["public", "information_schema", "nets"]
|
8
8
|
# PgPower::Tools.move_table_to_schema :computers, :nets
|
9
|
+
# PgPower::Tools.create_view view_name, view_definition # => creates new DB view
|
10
|
+
# PgPower::Tools.drop_view view_name # => removes the view
|
11
|
+
# PgPower::Tools.views # => ["x_view", "y_view", "z_view"]
|
9
12
|
module Tools
|
10
13
|
extend self
|
11
14
|
|
@@ -36,7 +39,30 @@ module PgPower
|
|
36
39
|
connection.execute sql
|
37
40
|
end
|
38
41
|
|
39
|
-
|
42
|
+
# Creates PostgreSQL view
|
43
|
+
# @param [String, Symbol] view_name
|
44
|
+
# @param [String] view_definition
|
45
|
+
def create_view(view_name, view_definition)
|
46
|
+
sql = "CREATE VIEW #{view_name} AS #{view_definition}"
|
47
|
+
connection.execute sql
|
48
|
+
end
|
49
|
+
|
50
|
+
# Drops PostgreSQL view
|
51
|
+
# @param [String, Symbol] view_name
|
52
|
+
def drop_view(view_name)
|
53
|
+
sql = "DROP VIEW #{view_name}"
|
54
|
+
connection.execute sql
|
55
|
+
end
|
56
|
+
|
57
|
+
# Returns an array of existing, non system views.
|
58
|
+
def views
|
59
|
+
sql = <<-SQL
|
60
|
+
SELECT table_schema, table_name, view_definition
|
61
|
+
FROM INFORMATION_SCHEMA.views
|
62
|
+
WHERE table_schema NOT IN ('pg_catalog','information_schema')
|
63
|
+
SQL
|
64
|
+
connection.execute sql
|
65
|
+
end
|
40
66
|
|
41
67
|
# Return database connections
|
42
68
|
def connection
|
data/lib/pg_power/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,10 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg_power
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.6.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 5
|
9
|
-
- 0
|
10
|
-
version: 1.5.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Potapov Sergey
|
14
9
|
- Arthur Shagall
|
15
10
|
- Artem Ignatyev
|
@@ -17,132 +12,129 @@ authors:
|
|
17
12
|
autorequire:
|
18
13
|
bindir: bin
|
19
14
|
cert_chain: []
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
- !ruby/object:Gem::Dependency
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ">="
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
hash: 3
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
version: "0"
|
33
|
-
version_requirements: *id001
|
15
|
+
date: 2013-06-25 00:00:00.000000000 Z
|
16
|
+
dependencies:
|
17
|
+
- !ruby/object:Gem::Dependency
|
34
18
|
name: pg
|
35
|
-
|
19
|
+
requirement: !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ! '>='
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '0'
|
36
25
|
type: :runtime
|
37
|
-
|
38
|
-
|
26
|
+
prerelease: false
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
28
|
none: false
|
40
|
-
requirements:
|
41
|
-
- -
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
|
45
|
-
- 0
|
46
|
-
version: "0"
|
47
|
-
version_requirements: *id002
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
48
34
|
name: rspec-rails
|
49
|
-
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
50
41
|
type: :runtime
|
51
|
-
|
52
|
-
|
42
|
+
prerelease: false
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
44
|
none: false
|
54
|
-
requirements:
|
55
|
-
- -
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
|
58
|
-
|
59
|
-
- 3
|
60
|
-
- 1
|
61
|
-
version: "3.1"
|
62
|
-
version_requirements: *id003
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
- !ruby/object:Gem::Dependency
|
63
50
|
name: rails
|
64
|
-
|
65
|
-
type: :runtime
|
66
|
-
- !ruby/object:Gem::Dependency
|
67
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
51
|
+
requirement: !ruby/object:Gem::Requirement
|
68
52
|
none: false
|
69
|
-
requirements:
|
70
|
-
- -
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
|
73
|
-
|
74
|
-
- 0
|
75
|
-
version: "0"
|
76
|
-
version_requirements: *id004
|
77
|
-
name: rcov
|
53
|
+
requirements:
|
54
|
+
- - ~>
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '3.1'
|
57
|
+
type: :runtime
|
78
58
|
prerelease: false
|
79
|
-
|
80
|
-
- !ruby/object:Gem::Dependency
|
81
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
60
|
none: false
|
83
|
-
requirements:
|
84
|
-
- -
|
85
|
-
- !ruby/object:Gem::Version
|
86
|
-
|
87
|
-
|
88
|
-
- 0
|
89
|
-
version: "0"
|
90
|
-
version_requirements: *id005
|
61
|
+
requirements:
|
62
|
+
- - ~>
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '3.1'
|
65
|
+
- !ruby/object:Gem::Dependency
|
91
66
|
name: yard
|
92
|
-
|
67
|
+
requirement: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
93
73
|
type: :development
|
94
|
-
|
95
|
-
|
74
|
+
prerelease: false
|
75
|
+
version_requirements: !ruby/object:Gem::Requirement
|
96
76
|
none: false
|
97
|
-
requirements:
|
98
|
-
- -
|
99
|
-
- !ruby/object:Gem::Version
|
100
|
-
|
101
|
-
|
102
|
-
- 0
|
103
|
-
version: "0"
|
104
|
-
version_requirements: *id006
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
- !ruby/object:Gem::Dependency
|
105
82
|
name: metrical
|
106
|
-
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
107
89
|
type: :development
|
108
|
-
|
109
|
-
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
110
92
|
none: false
|
111
|
-
requirements:
|
112
|
-
- -
|
113
|
-
- !ruby/object:Gem::Version
|
114
|
-
|
115
|
-
|
116
|
-
- 0
|
117
|
-
version: "0"
|
118
|
-
version_requirements: *id007
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
119
98
|
name: jeweler
|
120
|
-
|
121
|
-
type: :development
|
122
|
-
- !ruby/object:Gem::Dependency
|
123
|
-
requirement: &id008 !ruby/object:Gem::Requirement
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
124
100
|
none: false
|
125
|
-
requirements:
|
126
|
-
- -
|
127
|
-
- !ruby/object:Gem::Version
|
128
|
-
|
129
|
-
|
130
|
-
- 0
|
131
|
-
version: "0"
|
132
|
-
version_requirements: *id008
|
133
|
-
name: ruby-debug
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
type: :development
|
134
106
|
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'
|
135
121
|
type: :development
|
136
|
-
|
137
|
-
|
122
|
+
prerelease: false
|
123
|
+
version_requirements: !ruby/object:Gem::Requirement
|
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:
|
138
132
|
- rubygems@tmxcredit.com
|
139
133
|
executables: []
|
140
|
-
|
141
134
|
extensions: []
|
142
|
-
|
143
|
-
extra_rdoc_files:
|
135
|
+
extra_rdoc_files:
|
144
136
|
- README.markdown
|
145
|
-
files:
|
137
|
+
files:
|
146
138
|
- README.markdown
|
147
139
|
- lib/core_ext/active_record/connection_adapters/abstract/schema_statements.rb
|
148
140
|
- lib/core_ext/active_record/connection_adapters/postgresql_adapter.rb
|
@@ -164,6 +156,7 @@ files:
|
|
164
156
|
- lib/pg_power/connection_adapters/postgresql_adapter/index_methods.rb
|
165
157
|
- lib/pg_power/connection_adapters/postgresql_adapter/schema_methods.rb
|
166
158
|
- lib/pg_power/connection_adapters/postgresql_adapter/translate_exception.rb
|
159
|
+
- lib/pg_power/connection_adapters/postgresql_adapter/view_methods.rb
|
167
160
|
- lib/pg_power/connection_adapters/table.rb
|
168
161
|
- lib/pg_power/connection_adapters/table/comment_methods.rb
|
169
162
|
- lib/pg_power/connection_adapters/table/foreigner_methods.rb
|
@@ -176,46 +169,39 @@ files:
|
|
176
169
|
- lib/pg_power/migration/command_recorder/extension_methods.rb
|
177
170
|
- lib/pg_power/migration/command_recorder/foreigner_methods.rb
|
178
171
|
- lib/pg_power/migration/command_recorder/schema_methods.rb
|
172
|
+
- lib/pg_power/migration/command_recorder/view_methods.rb
|
179
173
|
- lib/pg_power/schema_dumper.rb
|
180
174
|
- lib/pg_power/schema_dumper/comment_methods.rb
|
181
175
|
- lib/pg_power/schema_dumper/extension_methods.rb
|
182
176
|
- lib/pg_power/schema_dumper/foreigner_methods.rb
|
183
177
|
- lib/pg_power/schema_dumper/schema_methods.rb
|
178
|
+
- lib/pg_power/schema_dumper/view_methods.rb
|
184
179
|
- lib/pg_power/tools.rb
|
185
180
|
- lib/pg_power/version.rb
|
186
181
|
- lib/tasks/pg_power_tasks.rake
|
187
182
|
homepage: https://github.com/TMXCredit/pg_power
|
188
183
|
licenses: []
|
189
|
-
|
190
184
|
post_install_message:
|
191
185
|
rdoc_options: []
|
192
|
-
|
193
|
-
require_paths:
|
186
|
+
require_paths:
|
194
187
|
- lib
|
195
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
188
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
196
189
|
none: false
|
197
|
-
requirements:
|
198
|
-
- -
|
199
|
-
- !ruby/object:Gem::Version
|
200
|
-
|
201
|
-
|
202
|
-
- 0
|
203
|
-
version: "0"
|
204
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
190
|
+
requirements:
|
191
|
+
- - ! '>='
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
version: '0'
|
194
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
205
195
|
none: false
|
206
|
-
requirements:
|
207
|
-
- -
|
208
|
-
- !ruby/object:Gem::Version
|
209
|
-
|
210
|
-
segments:
|
211
|
-
- 0
|
212
|
-
version: "0"
|
196
|
+
requirements:
|
197
|
+
- - ! '>='
|
198
|
+
- !ruby/object:Gem::Version
|
199
|
+
version: '0'
|
213
200
|
requirements: []
|
214
|
-
|
215
201
|
rubyforge_project:
|
216
202
|
rubygems_version: 1.8.24
|
217
203
|
signing_key:
|
218
204
|
specification_version: 3
|
219
205
|
summary: ActiveRecord extensions for PostgreSQL.
|
220
206
|
test_files: []
|
221
|
-
|
207
|
+
has_rdoc:
|