schema_plus_foreign_keys 0.1.1 → 0.1.2
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2ffa8e1095bb42bec9a1caf9c6a90048964a771
|
4
|
+
data.tar.gz: d184941dfb77d130e6420bad3018466e984104c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcac94e7194fda6a55479f573be6250191f2f1d47ed5e7c6e29c6f4c3772348fe297b8b07349a2c7abaa3c58fb294c1a6e1e232c65dbfbbd84079c71e53173d2
|
7
|
+
data.tar.gz: ec5104854ab13660508d486d661216e0d56bbeda754c65108eeb3b0d37be8a0ebcd46af8f216b5e68e5949dd7243eb96fb5d0db827746aa231db5af48e2d7f73
|
data/README.md
CHANGED
@@ -149,6 +149,7 @@ SchemaPlus::ForeignKeys is tested on:
|
|
149
149
|
|
150
150
|
## History
|
151
151
|
|
152
|
+
* 0.1.2 - Handle very long names
|
152
153
|
* 0.1.1 - Cleanup; use (new) core Migration::RenameTable stack rather than monkey patching.
|
153
154
|
* 0.1.0 - Initial release, brought over from schema_plus 1.x via 2.0.0.pre*
|
154
155
|
|
data/lib/schema_plus/foreign_keys/active_record/connection_adapters/foreign_key_definition.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'openssl'
|
1
2
|
require 'active_record/connection_adapters/abstract/schema_definitions'
|
2
3
|
|
3
4
|
module SchemaPlus::ForeignKeys
|
@@ -113,7 +114,9 @@ module SchemaPlus::ForeignKeys
|
|
113
114
|
end
|
114
115
|
|
115
116
|
def self.default_name(from_table, column)
|
116
|
-
"fk_#{fixup_schema_name(from_table)}_#{Array.wrap(column).join('_and_')}"
|
117
|
+
name = "fk_#{fixup_schema_name(from_table)}_#{Array.wrap(column).join('_and_')}"
|
118
|
+
name = name.slice(0, 27) + "_" + OpenSSL::Digest::MD5.new.hexdigest(name) if name.length > 60
|
119
|
+
name
|
117
120
|
end
|
118
121
|
|
119
122
|
def self.fixup_schema_name(table_name)
|
data/spec/migration_spec.rb
CHANGED
@@ -106,6 +106,17 @@ describe ActiveRecord::Migration do
|
|
106
106
|
expect(@model).to reference(:users, :id).with_name("wugga")
|
107
107
|
end
|
108
108
|
|
109
|
+
it "handles very long names" do
|
110
|
+
table = ("ta"*15)
|
111
|
+
column = ("co"*15 + "_id")
|
112
|
+
expect {
|
113
|
+
ActiveRecord::Migration.create_table table do |t|
|
114
|
+
t.integer column, references: :members
|
115
|
+
end
|
116
|
+
}.not_to raise_error
|
117
|
+
expect(ActiveRecord::Base.connection.foreign_keys(table).first.column).to eq(column)
|
118
|
+
end
|
119
|
+
|
109
120
|
it "should allow multiple foreign keys to be made" do
|
110
121
|
recreate_table(@model) do |t|
|
111
122
|
t.integer :user_id, :references => :users
|