schema_plus 1.8.8 → 1.8.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bf8e4b864566ead9c19844204623de10e2ab44df
4
- data.tar.gz: 71de29b1196886aa34275654f2a17d7b350585c2
3
+ metadata.gz: 58bc995f73389eafe9656f43ae965eab34002187
4
+ data.tar.gz: fd1b1b12ff5357065ab3b7a256fac090e86cae75
5
5
  SHA512:
6
- metadata.gz: f65586a99e11078912f78c57778a2f4f133e7b6107b992eaf1753a9b7a59bd2fd0d48ede133f5aee0b48fd2e24ea7b4d1476467bfca482c22efc54ed1d10fc74
7
- data.tar.gz: 5571cc83bf774b15bccafc15550af99d4cf1ed3e80dada6d3200f757a460b496171cea0cd40b3f85d6a1445c3a0d4ad5d5c03d025ee0dcf6de9416ad304b1e8b
6
+ metadata.gz: 8705f479301f9506afc99e71eed8219d758461b19d301b07d22499d51af0dfda33eac4d324c99f8903802aaa61b99ccd6379ba98eaad19bbc6c737720dfb3675
7
+ data.tar.gz: bb3ae470aa2a9527f6ad61f7572ad484ed1ea23e526fe67fd525d17c72c2172a284ae2d4aeb1588107f1bfc5f95dc4f7c7574171e0025b2a77421602212d9750
@@ -30,6 +30,9 @@ after_script: bundle exec rake drop_databases
30
30
  script: bundle exec rake travis
31
31
  matrix:
32
32
  exclude:
33
+ - rvm: jruby
34
+ gemfile: gemfiles/rails-3.2/Gemfile.postgresql
35
+ env: POSTGRESQL_DB_USER=postgres MYSQL_DB_USER=travis
33
36
  - rvm: jruby
34
37
  gemfile: gemfiles/rails-3.2/Gemfile.sqlite3
35
38
  env: POSTGRESQL_DB_USER=postgres MYSQL_DB_USER=travis
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Change Log
4
4
 
5
+ ## 1.8.9
6
+
7
+ * Bug fix: Disable auto_create when sqlite3 implicitly copies a table (#213)
8
+
5
9
  ## 1.8.8
6
10
 
7
11
  * Bug fix: Postgres index creation was ignoring option `algorithm: :concurrently` (#209)
@@ -31,6 +31,7 @@ module SchemaPlus
31
31
  alias_method_chain :indexes, :schema_plus
32
32
  alias_method_chain :rename_table, :schema_plus
33
33
  alias_method_chain :tables, :schema_plus
34
+ alias_method_chain :copy_table, :schema_plus
34
35
  end
35
36
 
36
37
  if ::ActiveRecord::VERSION::MAJOR.to_i < 4
@@ -72,6 +73,17 @@ module SchemaPlus
72
73
  indexes
73
74
  end
74
75
 
76
+ def copy_table_with_schema_plus(*args, &block)
77
+ fk_override = { :auto_create => false, :auto_index => false }
78
+ save = Hash[fk_override.keys.collect{|key| [key, SchemaPlus.config.foreign_keys.send(key)]}]
79
+ begin
80
+ SchemaPlus.config.foreign_keys.update_attributes(fk_override)
81
+ copy_table_without_schema_plus(*args, &block)
82
+ ensure
83
+ SchemaPlus.config.foreign_keys.update_attributes(save)
84
+ end
85
+ end
86
+
75
87
  def rename_table_with_schema_plus(oldname, newname) #:nodoc:
76
88
  rename_table_without_schema_plus(oldname, newname)
77
89
  rename_indexes_and_foreign_keys(oldname, newname)
@@ -1,3 +1,3 @@
1
1
  module SchemaPlus
2
- VERSION = "1.8.8"
2
+ VERSION = "1.8.9"
3
3
  end
@@ -34,3 +34,6 @@ exclude:
34
34
  -
35
35
  ruby: jruby
36
36
  db: sqlite3
37
+ -
38
+ ruby: jruby
39
+ db: postgresql
@@ -685,78 +685,96 @@ describe ActiveRecord::Migration do
685
685
  end
686
686
 
687
687
 
688
- context "when column is changed", :sqlite3 => :skip do
688
+ context "when changing a column" do
689
689
 
690
690
  before(:each) do
691
691
  @model = Comment
692
692
  end
693
693
 
694
- it "should create foreign key" do
695
- change_column :user, :string, :foreign_key => { :references => [:users, :login] }
696
- expect(@model).to reference(:users, :login).on(:user)
697
- end
698
-
699
- context "and initially references to users table" do
694
+ context "with foreign keys", :sqlite3 => :skip do
700
695
 
701
- before(:each) do
702
- recreate_table @model do |t|
703
- t.integer :user_id
704
- end
696
+ it "should create foreign key" do
697
+ change_column :user, :string, :foreign_key => { :references => [:users, :login] }
698
+ expect(@model).to reference(:users, :login).on(:user)
705
699
  end
706
700
 
707
- it "should have foreign key" do
708
- expect(@model).to reference(:users)
709
- end
701
+ context "and initially references to users table" do
710
702
 
711
- it "should drop foreign key if it is no longer valid" do
712
- change_column :user_id, :integer, :foreign_key => { :references => :members }
713
- expect(@model).not_to reference(:users)
714
- end
703
+ before(:each) do
704
+ recreate_table @model do |t|
705
+ t.integer :user_id
706
+ end
707
+ end
715
708
 
716
- it "should drop foreign key if requested to do so" do
717
- change_column :user_id, :integer, :foreign_key => { :references => nil }
718
- expect(@model).not_to reference(:users)
719
- end
709
+ it "should have foreign key" do
710
+ expect(@model).to reference(:users)
711
+ end
720
712
 
721
- it "should remove auto-created index if foreign key is removed" do
722
- expect(@model).to have_index.on(:user_id) # sanity check that index was auto-created
723
- change_column :user_id, :integer, :foreign_key => { :references => nil }
724
- expect(@model).not_to have_index.on(:user_id)
725
- end
713
+ it "should drop foreign key if it is no longer valid" do
714
+ change_column :user_id, :integer, :foreign_key => { :references => :members }
715
+ expect(@model).not_to reference(:users)
716
+ end
726
717
 
727
- it "should reference pointed table afterwards if new one is created" do
728
- change_column :user_id, :integer, :foreign_key => { :references => :members }
729
- expect(@model).to reference(:members)
730
- end
718
+ it "should drop foreign key if requested to do so" do
719
+ change_column :user_id, :integer, :foreign_key => { :references => nil }
720
+ expect(@model).not_to reference(:users)
721
+ end
731
722
 
732
- it "should maintain foreign key if it's unaffected by change" do
733
- change_column :user_id, :integer, :default => 0
734
- expect(@model).to reference(:users)
735
- end
723
+ it "should remove auto-created index if foreign key is removed" do
724
+ expect(@model).to have_index.on(:user_id) # sanity check that index was auto-created
725
+ change_column :user_id, :integer, :foreign_key => { :references => nil }
726
+ expect(@model).not_to have_index.on(:user_id)
727
+ end
736
728
 
737
- it "should maintain foreign key if it's unaffected by change, even if auto_index is off" do
738
- with_fk_config(:auto_create => false) do
729
+ it "should reference pointed table afterwards if new one is created" do
730
+ change_column :user_id, :integer, :foreign_key => { :references => :members }
731
+ expect(@model).to reference(:members)
732
+ end
733
+
734
+ it "should maintain foreign key if it's unaffected by change" do
739
735
  change_column :user_id, :integer, :default => 0
740
736
  expect(@model).to reference(:users)
741
737
  end
738
+
739
+ it "should maintain foreign key if it's unaffected by change, even if auto_index is off" do
740
+ with_fk_config(:auto_create => false) do
741
+ change_column :user_id, :integer, :default => 0
742
+ expect(@model).to reference(:users)
743
+ end
744
+ end
745
+
742
746
  end
743
747
 
744
- end
748
+ context "if column defined without foreign key but with index" do
749
+ before(:each) do
750
+ recreate_table @model do |t|
751
+ t.integer :user_id, :foreign_key => false, :index => true
752
+ end
753
+ end
745
754
 
746
- context "if column defined without foreign key but with index" do
747
- before(:each) do
748
- recreate_table @model do |t|
749
- t.integer :user_id, :foreign_key => false, :index => true
755
+ it "should create the index" do
756
+ expect(@model).to have_index.on(:user_id)
750
757
  end
751
- end
752
758
 
753
- it "should create the index" do
754
- expect(@model).to have_index.on(:user_id)
759
+ it "adding foreign key should not fail due to attempt to auto-create existing index" do
760
+ expect { change_column :user_id, :integer, :foreign_key => true }.to_not raise_error
761
+ end
755
762
  end
763
+ end
764
+
765
+ context "without foreign keys" do
756
766
 
757
- it "adding foreign key should not fail due to attempt to auto-create existing index" do
758
- expect { change_column :user_id, :integer, :foreign_key => true }.to_not raise_error
767
+ it "doesn't auto-add foreign keys" do
768
+ recreate_table @model do |t|
769
+ t.integer :user_id, :foreign_key => false
770
+ t.string :other_column
771
+ end
772
+ with_fk_auto_create do
773
+ change_column :other_column, :text
774
+ end
775
+ expect(@model).to_not reference(:users)
759
776
  end
777
+
760
778
  end
761
779
 
762
780
  protected
@@ -770,6 +788,7 @@ describe ActiveRecord::Migration do
770
788
 
771
789
  end
772
790
 
791
+
773
792
  context "when column is removed", :sqlite3 => :skip do
774
793
  before(:each) do
775
794
  @model = Comment
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.8.8
4
+ version: 1.8.9
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: 2015-03-22 00:00:00.000000000 Z
12
+ date: 2015-04-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord