schema_plus 1.4.0 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/gemfiles/Gemfile.base +4 -0
- data/gemfiles/rails-3.2/Gemfile.base +1 -2
- data/gemfiles/rails-4.0/Gemfile.base +1 -2
- data/gemfiles/rails-4.1/Gemfile.base +1 -2
- data/gemfiles/rails-edge/Gemfile.base +1 -2
- data/lib/schema_plus/active_record/connection_adapters/postgresql_adapter.rb +1 -0
- data/lib/schema_plus/active_record/connection_adapters/schema_statements.rb +7 -1
- data/lib/schema_plus/active_record/migration/command_recorder.rb +2 -1
- data/lib/schema_plus/version.rb +1 -1
- data/spec/connections/mysql/connection.rb +1 -1
- data/spec/connections/mysql2/connection.rb +1 -1
- data/spec/connections/postgresql/connection.rb +1 -1
- data/spec/connections/sqlite3/connection.rb +1 -1
- data/spec/migration_spec.rb +38 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8356e7e431dc435c954901447ddeee24dfff4b7a
|
4
|
+
data.tar.gz: 4a9789ee8e6cdf5845cd6181558b267a8d368064
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13e4f154b793d5c47054eacbffa293b27e2369ddc77cababec864521c67764f7867ef7be006476cbf3dc621f6ea3c2ccffd8cccd1e5254c1116653b2942bc498
|
7
|
+
data.tar.gz: acc74c44573cf7b6044cff3f3e25655d771109ec2e397a14dab887622aebea27b3b0bd8ae9ea47f4205e3b480f44a5db22b28df33e1d60fcfbc216dcddb75966
|
data/README.md
CHANGED
@@ -297,6 +297,10 @@ of foreign key constraints, you can re-enable it:
|
|
297
297
|
|
298
298
|
* *nothing currently waiting to be released*
|
299
299
|
|
300
|
+
### 1.4.1
|
301
|
+
|
302
|
+
* Bug fixes `migration.add_references` with `polymophic: true` (issue #145 and others)
|
303
|
+
|
300
304
|
### 1.4.0
|
301
305
|
|
302
306
|
* Supports jruby & mysql, thanks to [@rzenha](https://github.com/razenha)
|
@@ -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?
|
@@ -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
|
data/lib/schema_plus/version.rb
CHANGED
data/spec/migration_spec.rb
CHANGED
@@ -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
|
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.
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ronen Barzel
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-03-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -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
|