pg_saurus 2.6.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,7 +7,7 @@ module PgSaurus::ConnectionAdapters::Table::CommentMethods
7
7
  # ====== Set comment on table
8
8
  # t.set_table_comment 'This table stores phone numbers that conform to the North American Numbering Plan.'
9
9
  def set_table_comment(comment)
10
- @base.set_table_comment(@table_name, comment)
10
+ @base.set_table_comment(@name, comment)
11
11
  end
12
12
 
13
13
  # Remove any comment from the table.
@@ -16,7 +16,7 @@ module PgSaurus::ConnectionAdapters::Table::CommentMethods
16
16
  # ====== Remove table comment
17
17
  # t.remove_table_comment
18
18
  def remove_table_comment
19
- @base.remove_table_comment(@table_name)
19
+ @base.remove_table_comment(@name)
20
20
  end
21
21
 
22
22
  # Set the comment for a given column.
@@ -25,7 +25,7 @@ module PgSaurus::ConnectionAdapters::Table::CommentMethods
25
25
  # ====== Set comment on the npa column
26
26
  # t.set_column_comment :npa, 'Numbering Plan Area Code - Allowed ranges: [2-9] for first digit, [0-9] for second and third digit.'
27
27
  def set_column_comment(column_name, comment)
28
- @base.set_column_comment(@table_name, column_name, comment)
28
+ @base.set_column_comment(@name, column_name, comment)
29
29
  end
30
30
 
31
31
  # Set comments on multiple columns. 'comments' is a hash of column_name => comment pairs.
@@ -35,7 +35,7 @@ module PgSaurus::ConnectionAdapters::Table::CommentMethods
35
35
  # t.set_column_comments :npa => 'Numbering Plan Area Code - Allowed ranges: [2-9] for first digit, [0-9] for second and third digit.',
36
36
  # :nxx => 'Central Office Number'
37
37
  def set_column_comments(comments)
38
- @base.set_column_comments(@table_name, comments)
38
+ @base.set_column_comments(@name, comments)
39
39
  end
40
40
 
41
41
  # Remove any comment for a given column.
@@ -44,7 +44,7 @@ module PgSaurus::ConnectionAdapters::Table::CommentMethods
44
44
  # ====== Remove comment from the npa column
45
45
  # t.remove_column_comment :npa
46
46
  def remove_column_comment(column_name)
47
- @base.remove_column_comment(@table_name, column_name)
47
+ @base.remove_column_comment(@name, column_name)
48
48
  end
49
49
 
50
50
  # Remove any comments from the given columns.
@@ -53,6 +53,6 @@ module PgSaurus::ConnectionAdapters::Table::CommentMethods
53
53
  # ====== Remove comment from the npa and nxx columns
54
54
  # t.remove_column_comment :npa, :nxx
55
55
  def remove_column_comments(*column_names)
56
- @base.remove_column_comments(@table_name, *column_names)
56
+ @base.remove_column_comments(@name, *column_names)
57
57
  end
58
58
  end
@@ -16,7 +16,7 @@ module PgSaurus::ConnectionAdapters::Table::TriggerMethods
16
16
  # initially_deferred: true
17
17
  # end
18
18
  def create_trigger(proc_name, event, options = {})
19
- @base.create_trigger(@table_name, proc_name, event, options)
19
+ @base.create_trigger(@name, proc_name, event, options)
20
20
  end
21
21
 
22
22
  # Removes a trigger.
@@ -27,7 +27,7 @@ module PgSaurus::ConnectionAdapters::Table::TriggerMethods
27
27
  # t.remove_trigger :pets_not_empty_trigger_proc
28
28
  # end
29
29
  def remove_trigger(proc_name, options = {})
30
- @base.remove_trigger(@table_name, proc_name, options)
30
+ @base.remove_trigger(@name, proc_name, options)
31
31
  end
32
32
 
33
33
  end
@@ -2,17 +2,11 @@
2
2
  # to support pg_saurus features.
3
3
  module PgSaurus::ConnectionAdapters::Table
4
4
  extend ActiveSupport::Autoload
5
- extend ActiveSupport::Concern
6
5
 
7
6
  autoload :CommentMethods
8
- autoload :ForeignerMethods
9
7
  autoload :TriggerMethods
10
8
 
11
9
  include CommentMethods
12
- include ForeignerMethods
13
10
  include TriggerMethods
14
11
 
15
- included do
16
- alias_method_chain :references, :foreign_keys
17
- end
18
12
  end
@@ -4,7 +4,6 @@ module PgSaurus::ConnectionAdapters # :nodoc:
4
4
  autoload :AbstractAdapter
5
5
  autoload :PostgreSQLAdapter, 'pg_saurus/connection_adapters/postgresql_adapter'
6
6
  autoload :Table
7
- autoload :ForeignKeyDefinition
8
7
  autoload :IndexDefinition, 'pg_saurus/connection_adapters/index_definition'
9
8
  autoload :FunctionDefinition, 'pg_saurus/connection_adapters/function_definition'
10
9
  autoload :TriggerDefinition, 'pg_saurus/connection_adapters/trigger_definition'
@@ -70,7 +70,7 @@ module PgSaurus::CreateIndexConcurrently
70
70
  #
71
71
  # @see ActiveRecord::ConnectionAdapters::SchemaStatements.add_index in pg_saurus gem
72
72
  def add_index(table_name, column_name, options = {}, &block)
73
- table_name = ::ActiveRecord::Migrator.proper_table_name(table_name)
73
+ table_name = proper_table_name(table_name)
74
74
  # GOTCHA:
75
75
  # checks if index should be created concurretnly then put it into
76
76
  # the queue to wait till queue processing will be called (should be
@@ -86,51 +86,6 @@ module PgSaurus::CreateIndexConcurrently
86
86
  nil
87
87
  end
88
88
 
89
- # Add a foreign key.
90
- #
91
- # == Options:
92
- # * :column
93
- # * :primary_key
94
- # * :dependent
95
- # * :exclude_index [Boolean]
96
- # * :concurrent_index [Boolean]
97
- #
98
- # @param [String, Symbol] from_table
99
- # @param [String, Symbol] to_table
100
- # @param [Hash] options
101
- # @option options [String, Symbol] :column
102
- # @option options [String, Symbol] :primary_key
103
- # @option options [Hash] :dependent
104
- # @option options [Boolean] :exclude_index
105
- # @option options [Boolean] :concurrent_index
106
- #
107
- # @raise [ArgumentError] in case of conflicted option were set
108
- #
109
- # @see ::PgSaurus::ConnectionAdapters::PostgreSQLAdapter::ForeignerMethods.add_foreign_key
110
- def add_foreign_key(from_table, to_table, options = {}, &block)
111
- from_table = ::ActiveRecord::Migrator.proper_table_name(from_table)
112
- concurrent_index = options[:concurrent_index]
113
-
114
- if concurrent_index then
115
- if options[:exclude_index]
116
- raise ArgumentError, 'Conflicted options(exclude_index, concurrent_index) was found, both are set to true.'
117
- end
118
-
119
- options[:column] ||= connection.id_column_name_from_table_name(to_table)
120
- options = options.merge(:concurrently => concurrent_index)
121
-
122
- index_options = { :concurrently => true }
123
- enque(from_table, options[:column], index_options)
124
- end
125
-
126
- # GOTCHA:
127
- # proceed foreign key creation, but giving :concurrent_index => true
128
- # prevent normal index creation in PgSaurus's `add_foreign_key`.
129
- # So, postponed creation could be done after transaction.
130
- # -- zekefast 2012-09-12
131
- connection.add_foreign_key(from_table, to_table, options, &block)
132
- end
133
-
134
89
  # Execute all postponed index creation.
135
90
  #
136
91
  # @return [::PgSaurus::CreateIndexConcurrently::Migration]
@@ -6,7 +6,6 @@ module PgSaurus::Migration::CommandRecorder
6
6
  autoload :ExtensionMethods
7
7
  autoload :SchemaMethods
8
8
  autoload :CommentMethods
9
- autoload :ForeignerMethods
10
9
  autoload :ViewMethods
11
10
  autoload :FunctionMethods
12
11
  autoload :TriggerMethods
@@ -14,7 +13,6 @@ module PgSaurus::Migration::CommandRecorder
14
13
  include ExtensionMethods
15
14
  include SchemaMethods
16
15
  include CommentMethods
17
- include ForeignerMethods
18
16
  include ViewMethods
19
17
  include FunctionMethods
20
18
  include TriggerMethods
@@ -0,0 +1,49 @@
1
+ # Provides methods to extend ActiveRecord::SchemaDumper to dump
2
+ # foreign keys.
3
+ module PgSaurus::SchemaDumper::ForeignKeyMethods
4
+
5
+ # See activerecord/lib/active_record/schema_dumper.rb
6
+ def foreign_keys_with_indexes(table, stream)
7
+ if (foreign_keys = @connection.foreign_keys(table)).any?
8
+ add_foreign_key_statements = foreign_keys.map do |foreign_key|
9
+
10
+ from_table = if foreign_key.from_schema && foreign_key.from_schema != 'public'
11
+ "#{foreign_key.from_schema}.#{remove_prefix_and_suffix(foreign_key.from_table)}"
12
+ else
13
+ remove_prefix_and_suffix(foreign_key.from_table)
14
+ end
15
+
16
+ parts = [
17
+ "add_foreign_key #{from_table.inspect}",
18
+ remove_prefix_and_suffix(foreign_key.to_table).inspect,
19
+ ]
20
+
21
+ if foreign_key.column != @connection.foreign_key_column_for(foreign_key.to_table)
22
+ parts << "column: #{foreign_key.column.inspect}"
23
+ end
24
+
25
+ if foreign_key.custom_primary_key?
26
+ parts << "primary_key: #{foreign_key.primary_key.inspect}"
27
+ end
28
+
29
+ if foreign_key.name !~ /^fk_rails_[0-9a-f]{10}$/
30
+ parts << "name: #{foreign_key.name.inspect}"
31
+ end
32
+
33
+ parts << "on_update: #{foreign_key.on_update.inspect}" if foreign_key.on_update
34
+ parts << "on_delete: #{foreign_key.on_delete.inspect}" if foreign_key.on_delete
35
+
36
+ # Always exclude the index
37
+ # If an index was created in a migration, it will get dumped to the schema
38
+ # separately from the foreign key. This will raise an exception if
39
+ # add_foreign_key is run without :exclude_index => true.
40
+ parts << ":exclude_index => true"
41
+
42
+ " #{parts.join(', ')}"
43
+ end
44
+
45
+ stream.puts add_foreign_key_statements.sort.join("\n")
46
+ end
47
+ end
48
+
49
+ end
@@ -8,7 +8,7 @@ module PgSaurus::SchemaDumper
8
8
  autoload :ExtensionMethods
9
9
  autoload :CommentMethods
10
10
  autoload :SchemaMethods
11
- autoload :ForeignerMethods
11
+ autoload :ForeignKeyMethods
12
12
  autoload :ViewMethods
13
13
  autoload :FunctionMethods
14
14
  autoload :TriggerMethods
@@ -16,7 +16,7 @@ module PgSaurus::SchemaDumper
16
16
  include ExtensionMethods
17
17
  include CommentMethods
18
18
  include SchemaMethods
19
- include ForeignerMethods
19
+ include ForeignKeyMethods
20
20
  include ViewMethods
21
21
  include FunctionMethods
22
22
  include TriggerMethods
@@ -26,9 +26,10 @@ module PgSaurus::SchemaDumper
26
26
  alias_method_chain :header, :extensions
27
27
 
28
28
  alias_method_chain :tables, :views
29
- alias_method_chain :tables, :foreign_keys
30
29
  alias_method_chain :tables, :functions
31
30
  alias_method_chain :tables, :triggers
32
31
  alias_method_chain :tables, :comments
32
+
33
+ alias_method_chain :foreign_keys, :indexes
33
34
  end
34
35
  end
@@ -1,4 +1,4 @@
1
1
  module PgSaurus
2
2
  # Version of pg_saurus gem.
3
- VERSION = "2.6.0"
3
+ VERSION = "3.0.0"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_saurus
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Potapov Sergey
@@ -13,102 +13,36 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2016-10-26 00:00:00.000000000 Z
16
+ date: 2016-05-05 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: pg
20
20
  requirement: !ruby/object:Gem::Requirement
21
21
  requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
24
- version: '0'
25
- type: :runtime
26
- prerelease: false
27
- version_requirements: !ruby/object:Gem::Requirement
28
- requirements:
29
- - - ">="
30
- - !ruby/object:Gem::Version
31
- version: '0'
32
- - !ruby/object:Gem::Dependency
33
- name: railties
34
- requirement: !ruby/object:Gem::Requirement
35
- requirements:
36
- - - "<"
37
- - !ruby/object:Gem::Version
38
- version: '4.2'
39
22
  - - "~>"
40
23
  - !ruby/object:Gem::Version
41
- version: '4.0'
24
+ version: 0.18.1
42
25
  type: :runtime
43
26
  prerelease: false
44
27
  version_requirements: !ruby/object:Gem::Requirement
45
28
  requirements:
46
- - - "<"
47
- - !ruby/object:Gem::Version
48
- version: '4.2'
49
29
  - - "~>"
50
30
  - !ruby/object:Gem::Version
51
- version: '4.0'
31
+ version: 0.18.1
52
32
  - !ruby/object:Gem::Dependency
53
- name: activemodel
33
+ name: rails
54
34
  requirement: !ruby/object:Gem::Requirement
55
35
  requirements:
56
- - - "<"
57
- - !ruby/object:Gem::Version
58
- version: '4.2'
59
36
  - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '4.0'
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "<"
67
37
  - !ruby/object:Gem::Version
68
38
  version: '4.2'
69
- - - "~>"
70
- - !ruby/object:Gem::Version
71
- version: '4.0'
72
- - !ruby/object:Gem::Dependency
73
- name: activerecord
74
- requirement: !ruby/object:Gem::Requirement
75
- requirements:
76
- - - "<"
77
- - !ruby/object:Gem::Version
78
- version: '4.2'
79
- - - "~>"
80
- - !ruby/object:Gem::Version
81
- version: '4.0'
82
39
  type: :runtime
83
40
  prerelease: false
84
41
  version_requirements: !ruby/object:Gem::Requirement
85
42
  requirements:
86
- - - "<"
87
- - !ruby/object:Gem::Version
88
- version: '4.2'
89
- - - "~>"
90
- - !ruby/object:Gem::Version
91
- version: '4.0'
92
- - !ruby/object:Gem::Dependency
93
- name: activesupport
94
- requirement: !ruby/object:Gem::Requirement
95
- requirements:
96
- - - "<"
97
- - !ruby/object:Gem::Version
98
- version: '4.2'
99
43
  - - "~>"
100
- - !ruby/object:Gem::Version
101
- version: '4.0'
102
- type: :runtime
103
- prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- requirements:
106
- - - "<"
107
44
  - !ruby/object:Gem::Version
108
45
  version: '4.2'
109
- - - "~>"
110
- - !ruby/object:Gem::Version
111
- version: '4.0'
112
46
  - !ruby/object:Gem::Dependency
113
47
  name: rspec-rails
114
48
  requirement: !ruby/object:Gem::Requirement
@@ -208,7 +142,7 @@ dependencies:
208
142
  - !ruby/object:Gem::Version
209
143
  version: '0'
210
144
  description: ActiveRecord extensions for PostgreSQL. Provides useful tools for schema,
211
- foreign_key, index, comment and extension manipulations in migrations.
145
+ foreign_key, index, function, trigger, comment and extension manipulations in migrations.
212
146
  email:
213
147
  - blake131313@gmail.com
214
148
  - arthur.shagall@gmail.com
@@ -233,7 +167,6 @@ files:
233
167
  - lib/pg_saurus/connection_adapters.rb
234
168
  - lib/pg_saurus/connection_adapters/abstract_adapter.rb
235
169
  - lib/pg_saurus/connection_adapters/abstract_adapter/comment_methods.rb
236
- - lib/pg_saurus/connection_adapters/abstract_adapter/foreigner_methods.rb
237
170
  - lib/pg_saurus/connection_adapters/abstract_adapter/function_methods.rb
238
171
  - lib/pg_saurus/connection_adapters/abstract_adapter/index_methods.rb
239
172
  - lib/pg_saurus/connection_adapters/abstract_adapter/schema_methods.rb
@@ -244,7 +177,7 @@ files:
244
177
  - lib/pg_saurus/connection_adapters/postgresql_adapter.rb
245
178
  - lib/pg_saurus/connection_adapters/postgresql_adapter/comment_methods.rb
246
179
  - lib/pg_saurus/connection_adapters/postgresql_adapter/extension_methods.rb
247
- - lib/pg_saurus/connection_adapters/postgresql_adapter/foreigner_methods.rb
180
+ - lib/pg_saurus/connection_adapters/postgresql_adapter/foreign_key_methods.rb
248
181
  - lib/pg_saurus/connection_adapters/postgresql_adapter/function_methods.rb
249
182
  - lib/pg_saurus/connection_adapters/postgresql_adapter/index_methods.rb
250
183
  - lib/pg_saurus/connection_adapters/postgresql_adapter/schema_methods.rb
@@ -253,7 +186,6 @@ files:
253
186
  - lib/pg_saurus/connection_adapters/postgresql_adapter/view_methods.rb
254
187
  - lib/pg_saurus/connection_adapters/table.rb
255
188
  - lib/pg_saurus/connection_adapters/table/comment_methods.rb
256
- - lib/pg_saurus/connection_adapters/table/foreigner_methods.rb
257
189
  - lib/pg_saurus/connection_adapters/table/trigger_methods.rb
258
190
  - lib/pg_saurus/connection_adapters/trigger_definition.rb
259
191
  - lib/pg_saurus/create_index_concurrently.rb
@@ -263,7 +195,6 @@ files:
263
195
  - lib/pg_saurus/migration/command_recorder.rb
264
196
  - lib/pg_saurus/migration/command_recorder/comment_methods.rb
265
197
  - lib/pg_saurus/migration/command_recorder/extension_methods.rb
266
- - lib/pg_saurus/migration/command_recorder/foreigner_methods.rb
267
198
  - lib/pg_saurus/migration/command_recorder/function_methods.rb
268
199
  - lib/pg_saurus/migration/command_recorder/schema_methods.rb
269
200
  - lib/pg_saurus/migration/command_recorder/trigger_methods.rb
@@ -272,7 +203,7 @@ files:
272
203
  - lib/pg_saurus/schema_dumper.rb
273
204
  - lib/pg_saurus/schema_dumper/comment_methods.rb
274
205
  - lib/pg_saurus/schema_dumper/extension_methods.rb
275
- - lib/pg_saurus/schema_dumper/foreigner_methods.rb
206
+ - lib/pg_saurus/schema_dumper/foreign_key_methods.rb
276
207
  - lib/pg_saurus/schema_dumper/function_methods.rb
277
208
  - lib/pg_saurus/schema_dumper/schema_methods.rb
278
209
  - lib/pg_saurus/schema_dumper/trigger_methods.rb
@@ -300,8 +231,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
300
231
  version: '0'
301
232
  requirements: []
302
233
  rubyforge_project:
303
- rubygems_version: 2.4.8
234
+ rubygems_version: 2.4.6
304
235
  signing_key:
305
236
  specification_version: 4
306
237
  summary: ActiveRecord extensions for PostgreSQL.
307
238
  test_files: []
239
+ has_rdoc:
@@ -1,67 +0,0 @@
1
- # Extends ActiveRecord::ConnectionAdapters::AbstractAdapter with
2
- # empty methods for foreign keys feature.
3
- module PgSaurus::ConnectionAdapters::AbstractAdapter::ForeignerMethods
4
- def supports_foreign_keys?
5
- false
6
- end
7
-
8
- # Adds a new foreign key to the +from_table+, referencing the primary key of +to_table+
9
- #
10
- # The foreign key will be named after the from and to tables unless you pass
11
- # <tt>:name</tt> as an option.
12
- #
13
- # ===== Examples
14
- # ====== Creating a foreign key
15
- # add_foreign_key(:comments, :posts)
16
- # generates
17
- # ALTER TABLE `comments` ADD CONSTRAINT
18
- # `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`)
19
- #
20
- # ====== Creating a named foreign key
21
- # add_foreign_key(:comments, :posts, :name => 'comments_belongs_to_posts')
22
- # generates
23
- # ALTER TABLE `comments` ADD CONSTRAINT
24
- # `comments_belongs_to_posts` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`)
25
- #
26
- # ====== Creating a cascading foreign_key on a custom column
27
- # add_foreign_key(:people, :people, :column => 'best_friend_id', :dependent => :nullify)
28
- # generates
29
- # ALTER TABLE `people` ADD CONSTRAINT
30
- # `people_best_friend_id_fk` FOREIGN KEY (`best_friend_id`) REFERENCES `people` (`id`)
31
- # ON DELETE SET NULL
32
- #
33
- # === Supported options
34
- # [:column]
35
- # Specify the column name on the from_table that references the to_table. By default this is guessed
36
- # to be the singular name of the to_table with "_id" suffixed. So a to_table of :posts will use "post_id"
37
- # as the default <tt>:column</tt>.
38
- # [:primary_key]
39
- # Specify the column name on the to_table that is referenced by this foreign key. By default this is
40
- # assumed to be "id".
41
- # [:name]
42
- # Specify the name of the foreign key constraint. This defaults to use from_table and foreign key column.
43
- # [:dependent]
44
- # If set to <tt>:delete</tt>, the associated records in from_table are deleted when records in to_table table are deleted.
45
- # If set to <tt>:nullify</tt>, the foreign key column is set to +NULL+.
46
- # [:options]
47
- # Any extra options you want appended to the foreign key definition.
48
- def add_foreign_key(from_table, to_table, options = {})
49
- end
50
-
51
- # Remove the given foreign key from the table.
52
- #
53
- # ===== Examples
54
- # ====== Remove the suppliers_company_id_fk in the suppliers table.
55
- # remove_foreign_key :suppliers, :companies
56
- # ====== Remove the foreign key named accounts_branch_id_fk in the accounts table.
57
- # remove_foreign_key :accounts, :column => :branch_id
58
- # ====== Remove the foreign key named party_foreign_key in the accounts table.
59
- # remove_foreign_key :accounts, :name => :party_foreign_key
60
- def remove_foreign_key(from_table, options)
61
- end
62
-
63
- # Return the foreign keys for the schema_dumper
64
- def foreign_keys(table_name)
65
- []
66
- end
67
- end