schema_plus 1.8.1 → 1.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +6 -0
- data/lib/schema_plus/active_record/column_options_handler.rb +13 -11
- data/lib/schema_plus/active_record/connection_adapters/schema_statements.rb +2 -2
- data/lib/schema_plus/active_record/migration/command_recorder.rb +1 -1
- data/lib/schema_plus/version.rb +1 -1
- data/spec/column_spec.rb +3 -3
- data/spec/migration_spec.rb +10 -0
- data/spec/named_schemas_spec.rb +1 -1
- data/spec/schema_dumper_spec.rb +1 -1
- data/spec/views_spec.rb +1 -1
- 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: c0fa513513788b541ef9a1f0f9bc50ca6f3360e5
|
4
|
+
data.tar.gz: 26caef3cbcf5b870bd4484e903d57d33ff999b15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd84595cfdb830f928a4f06bb6dc13960ca144121b5f4dd88d29415a540807f36e0b7d5abe1f5f34d34e2421b482755ec42a0111a4a5ed67f072836fb6f4f881
|
7
|
+
data.tar.gz: 1d7350d3629ae83ace5180dd907c6dbf76fe6b33ffc31d3196888530bfe3fb5e89a4cb1545df110ab67457a552c58ccd1365f579dc1fe8865fcda96ff80480cb
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
## Change Log
|
4
4
|
|
5
|
+
## 1.8.2
|
6
|
+
|
7
|
+
* Bug fix when using t.references in change_table (#194). Thanks to [@boone](https://github.com/boone)
|
8
|
+
|
5
9
|
## 1.8.1
|
6
10
|
|
7
11
|
* Bug fix for AR 4.2, spurious add_foreign_key statements at the top of schema dump. Thanks to [@tovodeverett](https://github.com/tovodeverett) for doing better testing than me!
|
data/README.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
|
+
> ## This is the README for schema_plus 1.8.x
|
2
|
+
> which supports Rails 3.2, 4.0, 4.1, and 4.2. Ongoing development towards schema_plus 2.0 takes place in the [master branch](https://github.com/SchemaPlus/schema_plus/tree/master), supporting only Rails >= 4.2
|
3
|
+
|
4
|
+
---
|
5
|
+
|
1
6
|
# SchemaPlus
|
2
7
|
|
8
|
+
|
3
9
|
SchemaPlus is an ActiveRecord extension that provides enhanced capabilities
|
4
10
|
for schema definition and querying, including: enhanced and more DRY index
|
5
11
|
capabilities, support and automation for foreign key constraints, and support
|
@@ -2,17 +2,19 @@ module SchemaPlus::ActiveRecord
|
|
2
2
|
module ColumnOptionsHandler
|
3
3
|
def schema_plus_normalize_column_options(options)
|
4
4
|
# replace some shortcuts with full versions
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
5
|
+
[:index, :_index].each do |key|
|
6
|
+
case options[key]
|
7
|
+
when true then options[key] = {}
|
8
|
+
when :unique then options[key] = { :unique => true }
|
9
|
+
when Hash
|
10
|
+
if options[key][:length].is_a? Hash
|
11
|
+
normalize = if "#{::ActiveRecord::VERSION::MAJOR}.#{::ActiveRecord::VERSION::MINOR}".to_r >= "4.2".to_r
|
12
|
+
:stringify_keys!
|
13
|
+
else
|
14
|
+
:symbolize_keys!
|
15
|
+
end
|
16
|
+
options[key][:length].send normalize
|
17
|
+
end
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
@@ -54,8 +54,8 @@ module SchemaPlus::ActiveRecord::ConnectionAdapters
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def add_index_options_with_schema_plus(table_name, column_name, options = {})
|
57
|
-
|
58
|
-
add_index_options_without_schema_plus(table_name, Array(column_name).concat(Array(
|
57
|
+
with_columns = options.delete(:with) { |_| [] }
|
58
|
+
add_index_options_without_schema_plus(table_name, Array(column_name).concat(Array(with_columns).map(&:to_s)), options)
|
59
59
|
end
|
60
60
|
|
61
61
|
def self.add_index_exception_handler(connection, table, columns, options, e) #:nodoc:
|
@@ -40,7 +40,7 @@ module SchemaPlus
|
|
40
40
|
index_options = options.delete(:index)
|
41
41
|
add_column(table_name, "#{ref_name}_id", :integer, options)
|
42
42
|
add_column(table_name, "#{ref_name}_type", :string, polymorphic.is_a?(Hash) ? polymorphic : options) if polymorphic
|
43
|
-
add_index(table_name, polymorphic ? %w[id type].map{ |t| "#{ref_name}_#{t}" } : "#{ref_name}_id", index_options.is_a?(Hash) ? index_options :
|
43
|
+
add_index(table_name, polymorphic ? %w[id type].map{ |t| "#{ref_name}_#{t}" } : "#{ref_name}_id", index_options.is_a?(Hash) ? index_options : {}) if index_options
|
44
44
|
end
|
45
45
|
|
46
46
|
self
|
data/lib/schema_plus/version.rb
CHANGED
data/spec/column_spec.rb
CHANGED
@@ -32,7 +32,7 @@ describe "Column" do
|
|
32
32
|
|
33
33
|
context "if not unique" do
|
34
34
|
|
35
|
-
before
|
35
|
+
before(:each) do
|
36
36
|
create_table(User, :login => { :index => true})
|
37
37
|
@login = User.columns.find{|column| column.name == "login"}
|
38
38
|
end
|
@@ -48,7 +48,7 @@ describe "Column" do
|
|
48
48
|
end
|
49
49
|
|
50
50
|
context "if unique single column" do
|
51
|
-
before
|
51
|
+
before(:each) do
|
52
52
|
create_table(User, :login => { :index => :unique})
|
53
53
|
@login = User.columns.find{|column| column.name == "login"}
|
54
54
|
end
|
@@ -64,7 +64,7 @@ describe "Column" do
|
|
64
64
|
|
65
65
|
context "if unique multicolumn" do
|
66
66
|
|
67
|
-
before
|
67
|
+
before(:each) do
|
68
68
|
create_table(User, :first => {}, :middle => {}, :last => { :index => {:with => [:first, :middle], :unique => true}})
|
69
69
|
@first = User.columns.find{|column| column.name == "first"}
|
70
70
|
@middle = User.columns.find{|column| column.name == "middle"}
|
data/spec/migration_spec.rb
CHANGED
@@ -482,6 +482,16 @@ describe ActiveRecord::Migration do
|
|
482
482
|
expect(@model).to reference(:users, :id).on(:user_id)
|
483
483
|
end
|
484
484
|
|
485
|
+
it "should accept index shorthand when using :references"+suffix, :sqlite3 => :skip do
|
486
|
+
with_fk_config(:auto_index => false) do
|
487
|
+
change_table(@model, :bulk => bulk) do |t|
|
488
|
+
t.references :user, :index => true
|
489
|
+
end
|
490
|
+
end
|
491
|
+
expect(@model).to have_index.on(:user_id)
|
492
|
+
end
|
493
|
+
|
494
|
+
|
485
495
|
it "should create a foreign key constraint using :belongs_to"+suffix, :sqlite3 => :skip do
|
486
496
|
change_table(@model, :bulk => bulk) do |t|
|
487
497
|
t.belongs_to :user
|
data/spec/named_schemas_spec.rb
CHANGED
data/spec/schema_dumper_spec.rb
CHANGED
@@ -259,7 +259,7 @@ describe "Schema dump" do
|
|
259
259
|
end
|
260
260
|
|
261
261
|
context "with cyclic foreign key constraints", :sqlite3 => :skip do
|
262
|
-
before
|
262
|
+
before(:all) do
|
263
263
|
ActiveRecord::Base.connection.add_foreign_key(Comment.table_name, :commenter_id, User.table_name, :id)
|
264
264
|
ActiveRecord::Base.connection.add_foreign_key(Comment.table_name, :post_id, Post.table_name, :id)
|
265
265
|
ActiveRecord::Base.connection.add_foreign_key(Post.table_name, :first_comment_id, Comment.table_name, :id)
|
data/spec/views_spec.rb
CHANGED
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.2
|
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:
|
12
|
+
date: 2015-01-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|