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: 18b2164c375e6447f51ff241d12deaa5748736e4
4
- data.tar.gz: 0c46ee8eb9792365ae22ecc13ecf305afde81a39
3
+ metadata.gz: b2ffa8e1095bb42bec9a1caf9c6a90048964a771
4
+ data.tar.gz: d184941dfb77d130e6420bad3018466e984104c5
5
5
  SHA512:
6
- metadata.gz: b930008367e71b0c7b53771be9974d61e37c5ed8ba2c3a6ec049a41185299656c8126c1f097155b0776d9210c7bf295ea8a5a7e4014df52bbc9a954e87a8de64
7
- data.tar.gz: bc1f9db77881d39cc24f418458711b486cabed9a7c3b1d479d1af9eb3ac8fe4ab1129cac8c0efe66938b437a0626e6e1b25ae63cb75637b6bdada084a89d6f7c
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
 
@@ -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)
@@ -1,5 +1,5 @@
1
1
  module SchemaPlus
2
2
  module ForeignKeys
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schema_plus_foreign_keys
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ronen barzel