schema_plus 1.4.0 → 1.5.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0d5b988ea47657ad4e1be912509f3d17c4c4e329
4
- data.tar.gz: e4fcc4ac3d1ca3003e4a9c7fc1c0a48e687dd197
3
+ metadata.gz: 14f770e20ed8fc7090ddc3fd58e95976e6a6ae13
4
+ data.tar.gz: 999f0ad6bd7a1346dda3ebc152ec2a0f7a430488
5
5
  SHA512:
6
- metadata.gz: 4ea4f3e69dd6fd4705146b05123e7ec245414ef77de85382a5ada63bebfce065088d4447ea9f411b82444d33c94d7a9ce6ad96a76061816a7a851023a9672e8f
7
- data.tar.gz: 9251ec18b5b5f416627162c4adecff472c22c82ac23076461d7b8d045f40744f246827da14580c17d5957efb45218a7b235d71ffbcc1092e1b7486a4547cc3f2
6
+ metadata.gz: 33fdfaee05d32853f87112adc5d156970f4d5bddec6c2f8379a283ad16cf6e9eb3e5adfb84dbf60af476e340f51c15ab6f53d2336877226e670602bbf141d35e
7
+ data.tar.gz: 3ff056bfd48ea22a5004f3f6760d4bec52127bde7040b65082f2de86fcf00b1353be1a1f46a6b1d37dc04ab87ef0cb6f8146578d985cb126d118b77a670dc124
data/README.md CHANGED
@@ -17,15 +17,14 @@ For added rails DRYness see also the gems
17
17
 
18
18
  SchemaPlus supports all combinations of:
19
19
 
20
- * Rails 3.2, 4.0, and 4.1 (currently 4.1.0beta3)
20
+ * Rails/ActiveRecord 3.2, 4.0, and 4.1 (currently 4.1.0beta3)
21
21
  * PostgreSQL, MySQL (using mysql2 gem; mysql gem only supported with Rails
22
22
  3.2), or SQLite3 (using sqlite3 >= 3.7.7 which has foreign key support)
23
23
  * MRI Ruby 1.9.3, 2.0.0, or 2.1.0
24
24
 
25
25
  And also supports:
26
26
 
27
- * jruby with Rails 3.2 and PostgreSQL or MySQL
28
-
27
+ * jruby with Rails/ActiveRecord 3.2 and PostgreSQL or MySQL
29
28
 
30
29
 
31
30
  ## Installation
@@ -77,7 +76,7 @@ You can also create multi-column indexes, for example:
77
76
 
78
77
  t.string :country_code
79
78
  t.string :area_code
80
- t.string :local_number index: { with: [:country_code, :area_code], unique: true }
79
+ t.string :local_number, index: { with: [:country_code, :area_code], unique: true }
81
80
 
82
81
  And you can specify index orders:
83
82
 
@@ -224,6 +223,8 @@ the above views you can define
224
223
  class UncommentedPost < ActiveRecord::Base
225
224
  end
226
225
 
226
+ Note: In Postgres, all internal views (the ones with `pg_` prefix) will be skipped.
227
+
227
228
  ### Column Defaults: Expressions
228
229
 
229
230
  SchemaPlus allows defaults to be set using expressions or constant values:
@@ -297,6 +298,19 @@ of foreign key constraints, you can re-enable it:
297
298
 
298
299
  * *nothing currently waiting to be released*
299
300
 
301
+
302
+ ### 1.5.1
303
+
304
+ * Now respects ActiveRecord::SchemaDumper.ignore_tables for views (issue #153)
305
+
306
+ ### 1.5.0
307
+ * Can now be used with activerecord standalone, doesn't need all of rails.
308
+ * `views` ignores postgres internal views, thanks to [@everplays](https://github.com/everplays) (issue #147)
309
+
310
+ ### 1.4.1
311
+
312
+ * Bug fixes `migration.add_references` with `polymophic: true` (issue #145 and others)
313
+
300
314
  ### 1.4.0
301
315
 
302
316
  * Supports jruby & mysql, thanks to [@rzenha](https://github.com/razenha)
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ gemspec :path => File.expand_path('..', __FILE__)
3
+
4
+ gem "byebug" if RUBY_VERSION > "2"
@@ -1,4 +1,3 @@
1
- source 'https://rubygems.org'
1
+ eval File.read File.expand_path('../../Gemfile.base', __FILE__)
2
2
 
3
- gemspec :path => File.expand_path('../../..', __FILE__)
4
3
  gem "rails", "~> 3.2.0"
@@ -1,4 +1,3 @@
1
- source 'https://rubygems.org'
1
+ eval File.read File.expand_path('../../Gemfile.base', __FILE__)
2
2
 
3
- gemspec :path => File.expand_path('../../..', __FILE__)
4
3
  gem "rails", "~> 4.0.0"
@@ -1,4 +1,3 @@
1
- source 'https://rubygems.org'
1
+ eval File.read File.expand_path('../../Gemfile.base', __FILE__)
2
2
 
3
- gemspec :path => File.expand_path('../../..', __FILE__)
4
3
  gem "rails", "~> 4.1.0.beta1"
@@ -1,4 +1,3 @@
1
- source 'https://rubygems.org'
1
+ eval File.read File.expand_path('../../Gemfile.base', __FILE__)
2
2
 
3
- gemspec :path => File.expand_path('../../..', __FILE__)
4
3
  gem "rails", "~> 4.0.0"
@@ -83,6 +83,7 @@ module SchemaPlus
83
83
  # are specified simultaneously.
84
84
  #
85
85
  def add_index(table_name, column_name, options = {})
86
+ options = {} if options.nil? # some callers explicitly pass options=nil
86
87
  column_name, options = [], column_name if column_name.is_a?(Hash)
87
88
  column_names = Array(column_name).compact
88
89
  if column_names.empty?
@@ -264,6 +265,7 @@ module SchemaPlus
264
265
  SELECT viewname
265
266
  FROM pg_views
266
267
  WHERE schemaname = ANY (current_schemas(false))
268
+ AND viewname NOT LIKE 'pg\_%'
267
269
  SQL
268
270
  sql += " AND schemaname != 'postgis'" if adapter_name == 'PostGIS'
269
271
  query(sql, name).map { |row| row[0] }
@@ -4,10 +4,16 @@ module SchemaPlus::ActiveRecord::ConnectionAdapters
4
4
  def self.included(base) #:nodoc:
5
5
  base.class_eval do
6
6
  alias_method_chain :create_table, :schema_plus
7
+ alias_method_chain :add_reference, :schema_plus unless ::ActiveRecord::VERSION::MAJOR.to_i < 4
7
8
  include AddIndex
8
9
  end
9
10
  end
10
11
 
12
+ def add_reference_with_schema_plus(table_name, ref_name, options = {}) #:nodoc:
13
+ options[:references] = nil if options[:polymorphic]
14
+ add_reference_without_schema_plus(table_name, ref_name, options)
15
+ end
16
+
11
17
  ##
12
18
  # :method: create_table
13
19
  #
@@ -76,7 +82,7 @@ module SchemaPlus::ActiveRecord::ConnectionAdapters
76
82
  # an error.)
77
83
  #
78
84
  def add_index_with_schema_plus(table, columns, options={})
79
- options.delete(:if_exists)
85
+ options.delete(:if_exists) if options # some callers explcitly pass options=nil
80
86
  add_index_without_schema_plus(table, columns, options)
81
87
  rescue => e
82
88
  SchemaStatements.add_index_exception_handler(self, table, columns, options, e)
@@ -27,8 +27,9 @@ module SchemaPlus
27
27
  # should track it down separately and submit a patch/fix to rails
28
28
  #
29
29
  def add_reference_with_schema_plus(table_name, ref_name, options = {}) #:nodoc:
30
+ options[:references] = nil if options[:polymorphic]
30
31
  # which is the worse hack...?
31
- if RUBY_VERSION >= "2.0.0"
32
+ if RUBY_VERSION >= "2.0.0" and self.delegate.respond_to? :add_reference_sql
32
33
  # .. rebinding a method from a different module? (can't do this in ruby 1.9.3)
33
34
  ::ActiveRecord::ConnectionAdapters::SchemaStatements.instance_method(:add_reference).bind(self).call(table_name, ref_name, options)
34
35
  else
@@ -52,6 +52,7 @@ module SchemaPlus
52
52
  tables_without_schema_plus(nil)
53
53
 
54
54
  @connection.views.each do |view_name|
55
+ next if Array.wrap(::ActiveRecord::SchemaDumper.ignore_tables).any? {|pattern| view_name.match pattern}
55
56
  definition = @connection.view_definition(view_name)
56
57
  @table_dumps[view_name] = " create_view #{view_name.inspect}, #{definition.inspect}, :force => true\n"
57
58
  end
@@ -1,3 +1,3 @@
1
1
  module SchemaPlus
2
- VERSION = "1.4.0"
2
+ VERSION = "1.5.1"
3
3
  end
data/schema_plus.gemspec CHANGED
@@ -12,6 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.homepage = "https://github.com/lomba/schema_plus"
13
13
  s.summary = "Enhances ActiveRecord schema mechanism, including more DRY index creation and support for foreign key constraints and views."
14
14
  s.description = "SchemaPlus is an ActiveRecord extension that provides enhanced capabilities for schema definition and querying, including: enhanced and more DRY index capabilities, support and automation for foreign key constraints, and support for views."
15
+ s.license = 'MIT'
15
16
 
16
17
  s.rubyforge_project = "schema_plus"
17
18
 
@@ -20,7 +21,7 @@ Gem::Specification.new do |s|
20
21
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
22
  s.require_paths = ["lib"]
22
23
 
23
- s.add_dependency("rails", ">= 3.2")
24
+ s.add_dependency("activerecord", ">= 3.2")
24
25
  s.add_dependency("valuable")
25
26
 
26
27
  s.add_development_dependency("rake")
@@ -14,4 +14,4 @@ ActiveRecord::Base.configurations = {
14
14
 
15
15
  }
16
16
 
17
- ActiveRecord::Base.establish_connection 'schema_plus'
17
+ ActiveRecord::Base.establish_connection :schema_plus
@@ -14,4 +14,4 @@ ActiveRecord::Base.configurations = {
14
14
 
15
15
  }
16
16
 
17
- ActiveRecord::Base.establish_connection 'schema_plus'
17
+ ActiveRecord::Base.establish_connection :schema_plus
@@ -13,4 +13,4 @@ ActiveRecord::Base.configurations = {
13
13
 
14
14
  }
15
15
 
16
- ActiveRecord::Base.establish_connection 'schema_plus'
16
+ ActiveRecord::Base.establish_connection :schema_plus
@@ -11,5 +11,5 @@ ActiveRecord::Base.configurations = {
11
11
 
12
12
  }
13
13
 
14
- ActiveRecord::Base.establish_connection 'schema_plus'
14
+ ActiveRecord::Base.establish_connection :schema_plus
15
15
  ActiveRecord::Base.connection.execute "PRAGMA synchronous = OFF"
@@ -599,6 +599,44 @@ describe ActiveRecord::Migration do
599
599
 
600
600
  end
601
601
 
602
+ context "when add reference" do
603
+
604
+ before(:each) do
605
+ @model = Comment
606
+ end
607
+
608
+ it "should create foreign key" do
609
+ add_reference(:post) do
610
+ @model.should reference(:posts, :id).on(:post_id)
611
+ end
612
+ end
613
+
614
+ it "should not create a foreign_key if polymorphic" do
615
+ add_reference(:post, :polymorphic => true) do
616
+ @model.should_not reference(:posts, :id).on(:post_id)
617
+ end
618
+ end
619
+
620
+ it "should create a two-column index if polymophic and index requested" do
621
+ add_reference(:post, :polymorphic => true, :index => true) do
622
+ @model.should have_index.on([:post_id, :post_type])
623
+ end
624
+ end
625
+
626
+
627
+ protected
628
+ def add_reference(column_name, *args)
629
+ table = @model.table_name
630
+ ActiveRecord::Migration.suppress_messages do
631
+ ActiveRecord::Migration.add_reference(table, column_name, *args)
632
+ @model.reset_column_information
633
+ yield if block_given?
634
+ ActiveRecord::Migration.remove_column(table, "#{column_name}_id")
635
+ end
636
+ end
637
+
638
+ end unless ::ActiveRecord::VERSION::MAJOR.to_i < 4
639
+
602
640
  context "when column is changed" do
603
641
 
604
642
  before(:each) do
data/spec/views_spec.rb CHANGED
@@ -17,13 +17,6 @@ describe ActiveRecord do
17
17
 
18
18
  let(:connection) { ActiveRecord::Base.connection }
19
19
 
20
- let (:dump) {
21
- StringIO.open { |stream|
22
- ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
23
- stream.string
24
- }
25
- }
26
-
27
20
  context "views" do
28
21
 
29
22
  around (:each) do |example|
@@ -38,6 +31,7 @@ describe ActiveRecord do
38
31
  end
39
32
 
40
33
  it "should instrospect" do
34
+ # for postgresql, ignore views named pg_*
41
35
  connection.views.sort.should == %W[a_ones ab_ones]
42
36
  connection.view_definition('a_ones').should match(%r{^SELECT .*b.*,.*s.* FROM .*items.* WHERE .*a.* = 1}i)
43
37
  connection.view_definition('ab_ones').should match(%r{^SELECT .*s.* FROM .*a_ones.* WHERE .*b.* = 1}i)
@@ -58,6 +52,14 @@ describe ActiveRecord do
58
52
  dump.should match(%r{create_table "items".*create_view "a_ones".*create_view "ab_ones"}m)
59
53
  end
60
54
 
55
+ it "should not be included in schema if listed in ignore_tables" do
56
+ dump(ignore_tables: /b_/) do |dump|
57
+ dump.should match(%r{create_view "a_ones", "SELECT .*b.*,.*s.* FROM .*items.* WHERE .*a.* = 1.*, :force => true}i)
58
+ dump.should_not match(%r{"ab_ones"})
59
+ end
60
+ end
61
+
62
+
61
63
  it "dump should not reference current database" do
62
64
  # why check this? mysql default to providing the view definition
63
65
  # with tables explicitly scoped to the current database, which
@@ -142,6 +144,7 @@ describe ActiveRecord do
142
144
 
143
145
  create_view :a_ones, Item.select('b, s').where(:a => 1)
144
146
  create_view :ab_ones, "select s from a_ones where b = 1"
147
+ create_view :pg_dummy_internal, "select 1" if SchemaPlusHelpers.postgresql?
145
148
  end
146
149
  end
147
150
  connection.execute "insert into items (a, b, s) values (1, 1, 'one_one')"
@@ -157,13 +160,16 @@ describe ActiveRecord do
157
160
  drop_view "ab_ones"
158
161
  drop_view "a_ones"
159
162
  drop_table "items"
163
+ drop_view :pg_dummy_internal if SchemaPlusHelpers.postgresql?
160
164
  end
161
165
  end
162
166
  end
163
167
 
164
- def dump
168
+ def dump(opts={})
165
169
  StringIO.open { |stream|
170
+ ActiveRecord::SchemaDumper.ignore_tables = Array.wrap(opts[:ignore_tables])
166
171
  ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
172
+ yield stream.string if block_given?
167
173
  stream.string
168
174
  }
169
175
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schema_plus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ronen Barzel
@@ -9,10 +9,10 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-08 00:00:00.000000000 Z
12
+ date: 2014-04-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: rails
15
+ name: activerecord
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
18
  - - '>='
@@ -126,6 +126,7 @@ files:
126
126
  - MIT-LICENSE
127
127
  - README.md
128
128
  - Rakefile
129
+ - gemfiles/Gemfile.base
129
130
  - gemfiles/rails-3.2/Gemfile.base
130
131
  - gemfiles/rails-3.2/Gemfile.mysql
131
132
  - gemfiles/rails-3.2/Gemfile.mysql2
@@ -190,7 +191,8 @@ files:
190
191
  - spec/support/matchers/reference.rb
191
192
  - spec/views_spec.rb
192
193
  homepage: https://github.com/lomba/schema_plus
193
- licenses: []
194
+ licenses:
195
+ - MIT
194
196
  metadata: {}
195
197
  post_install_message:
196
198
  rdoc_options: []