declare_schema 1.2.3.pre.ga.7 → 1.2.3.pre.ga.8

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
  SHA256:
3
- metadata.gz: 308421d49ba0007340aad10be1ca95b4798d1c3a98c3e7bb52e41d81f903530e
4
- data.tar.gz: 7e1c75911502f841c935308a8b1f8a8997702839eb348f07b45eee05cc3440b3
3
+ metadata.gz: ac52b40b3a13a99d43517d2755123ba3a836140fcf9862d10b35a586eaad9ef7
4
+ data.tar.gz: d84e7782e16652da230cb9e51ee4c951bba67c692ab58f12056f9e895738d203
5
5
  SHA512:
6
- metadata.gz: 2e4d907b428190cdb3cfa5b99c27e9a751a110144092e9498888b79a5050596bb849afb73feb38d6f4bba73617f4a3d00e0c8d4cde9634c124472f93a5003022
7
- data.tar.gz: 1774ac3658dccd0f32f280b04358cfa80707053d8d595b3527f467e97c8b91f66651de3737fea969abd01c2454bc028aca12ae98380e7a1d76d0ef4dc0a37eb5
6
+ metadata.gz: c03703d46e1ed3c149f51ad479e2baacc88bc174a1b5239419c9f906cf0a638b26f0299ac50845660734151e18ef1b0048479abf491b685dd81ba9d55649edf3
7
+ data.tar.gz: e20b98d2651485183f4df433eb482715d492175c8fb6407e7030ed08c90ae8c5845d633044a335c91578531f3e5c11df23348b81f95cf9d7871204e20a4f4178
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- declare_schema (1.2.3.pre.ga.7)
4
+ declare_schema (1.2.3.pre.ga.8)
5
5
  rails (>= 5.0)
6
6
 
7
7
  GEM
@@ -37,10 +37,6 @@ module DeclareSchema
37
37
  join_table
38
38
  end
39
39
 
40
- def index_name
41
- "index_#{table_name}_on_#{foreign_keys.first}_#{foreign_keys.last}"
42
- end
43
-
44
40
  def field_specs
45
41
  foreign_keys.each_with_index.each_with_object({}) do |(v, position), result|
46
42
  result[v] = ::DeclareSchema::Model::FieldSpec.new(self, v, :bigint, position: position, null: false)
@@ -57,7 +53,7 @@ module DeclareSchema
57
53
 
58
54
  def index_definitions_with_primary_key
59
55
  [
60
- IndexDefinition.new(self, foreign_keys, unique: true, name: index_name), # creates a primary composite key on both foreign keys
56
+ IndexDefinition.new(self, foreign_keys, unique: true, name: "PRIMARY KEY"), # creates a primary composite key on both foreign keys
61
57
  IndexDefinition.new(self, foreign_keys.last) # not unique by itself; combines with primary key to be unique
62
58
  ]
63
59
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeclareSchema
4
- VERSION = "1.2.3.pre.ga.7"
4
+ VERSION = "1.2.3.pre.ga.8"
5
5
  end
@@ -102,12 +102,37 @@ RSpec.describe DeclareSchema::Model::HabtmModelShim do
102
102
  expect(result.size).to eq(2), result.inspect
103
103
 
104
104
  expect(result.first).to be_a(::DeclareSchema::Model::IndexDefinition)
105
- expect(result.first.name).to eq('index_parent_1_parent_2_on_parent_1_id_parent_2_id')
105
+ expect(result.first.name).to eq('PRIMARY KEY')
106
106
  expect(result.first.fields).to eq(['parent_1_id', 'parent_2_id'])
107
107
  expect(result.first.unique).to be_truthy
108
108
  end
109
109
  end
110
110
 
111
+ context 'when table and foreign key names are long' do
112
+ let(:join_table) { "advertiser_campaigns_tracking_pixels" }
113
+ let(:foreign_keys) { ['advertiser_campaign', 'tracking_pixel'] }
114
+ let(:foreign_key_classes) { [Table1, Table2] }
115
+
116
+ before do
117
+ class Table1 < ActiveRecord::Base
118
+ self.table_name = 'advertiser_campaign'
119
+ end
120
+
121
+ class Table2 < ActiveRecord::Base
122
+ self.table_name = 'tracking_pixel'
123
+ end
124
+ end
125
+
126
+ it 'returns two index definitions and does not raise a IndexNameTooLongError' do
127
+ result = subject.index_definitions_with_primary_key
128
+ expect(result.size).to eq(2), result.inspect
129
+ expect(result.first).to be_a(::DeclareSchema::Model::IndexDefinition)
130
+ expect(result.first.name).to eq('PRIMARY KEY')
131
+ expect(result.first.fields).to eq(['advertiser_campaign', 'tracking_pixel'])
132
+ expect(result.first.unique).to be_truthy
133
+ end
134
+ end
135
+
111
136
  describe '#index_definitions' do
112
137
  it 'returns index_definitions_with_primary_key' do
113
138
  result = subject.index_definitions
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: declare_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3.pre.ga.7
4
+ version: 1.2.3.pre.ga.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Invoca Development adapted from hobo_fields by Tom Locke