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 +4 -4
- data/.travis.yml +3 -0
- data/CHANGELOG.md +4 -0
- data/lib/schema_plus/active_record/connection_adapters/sqlite3_adapter.rb +12 -0
- data/lib/schema_plus/version.rb +1 -1
- data/schema_dev.yml +3 -0
- data/spec/migration_spec.rb +66 -47
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58bc995f73389eafe9656f43ae965eab34002187
|
4
|
+
data.tar.gz: fd1b1b12ff5357065ab3b7a256fac090e86cae75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8705f479301f9506afc99e71eed8219d758461b19d301b07d22499d51af0dfda33eac4d324c99f8903802aaa61b99ccd6379ba98eaad19bbc6c737720dfb3675
|
7
|
+
data.tar.gz: bb3ae470aa2a9527f6ad61f7572ad484ed1ea23e526fe67fd525d17c72c2172a284ae2d4aeb1588107f1bfc5f95dc4f7c7574171e0025b2a77421602212d9750
|
data/.travis.yml
CHANGED
@@ -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
|
data/CHANGELOG.md
CHANGED
@@ -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)
|
data/lib/schema_plus/version.rb
CHANGED
data/schema_dev.yml
CHANGED
data/spec/migration_spec.rb
CHANGED
@@ -685,78 +685,96 @@ describe ActiveRecord::Migration do
|
|
685
685
|
end
|
686
686
|
|
687
687
|
|
688
|
-
context "when
|
688
|
+
context "when changing a column" do
|
689
689
|
|
690
690
|
before(:each) do
|
691
691
|
@model = Comment
|
692
692
|
end
|
693
693
|
|
694
|
-
|
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
|
-
|
702
|
-
|
703
|
-
|
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
|
-
|
708
|
-
expect(@model).to reference(:users)
|
709
|
-
end
|
701
|
+
context "and initially references to users table" do
|
710
702
|
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
703
|
+
before(:each) do
|
704
|
+
recreate_table @model do |t|
|
705
|
+
t.integer :user_id
|
706
|
+
end
|
707
|
+
end
|
715
708
|
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
end
|
709
|
+
it "should have foreign key" do
|
710
|
+
expect(@model).to reference(:users)
|
711
|
+
end
|
720
712
|
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
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
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
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
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
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
|
-
|
738
|
-
|
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
|
-
|
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
|
-
|
747
|
-
|
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
|
-
|
754
|
-
|
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 "
|
758
|
-
|
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.
|
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-
|
12
|
+
date: 2015-04-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|