declare_schema 1.2.3.pre.ga.6 → 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: '0681126cdd17705ec35f41ab9e4dc608fbc961b50614124ace54e17c49675eca'
4
- data.tar.gz: efa69b2eb51fa5e2a9ec5b22ed04ecdf91679abecfb674646ea7e461974a097e
3
+ metadata.gz: ac52b40b3a13a99d43517d2755123ba3a836140fcf9862d10b35a586eaad9ef7
4
+ data.tar.gz: d84e7782e16652da230cb9e51ee4c951bba67c692ab58f12056f9e895738d203
5
5
  SHA512:
6
- metadata.gz: 69d913a279f29f6368ceb224791213d9bc711e27c8a4a598f7feeb720bf753c5b6e5d65e7537655979b9bc6da5ee663c69f8c9dc2a8e2156b5b1e1c7608cc03b
7
- data.tar.gz: 5f4b21eb05fc804a883f5bef692bf3473e25b8a61e066cf094e363b46be27fede8fc520efebc04a49ccd4e3c56fa7bddfcb5713204c828dba146904423781535
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.6)
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.6"
4
+ VERSION = "1.2.3.pre.ga.8"
5
5
  end
@@ -446,7 +446,7 @@ module Generators
446
446
  if !ActiveRecord::Base.connection.class.name.match?(/SQLite3Adapter/)
447
447
  change_primary_key =
448
448
  if (existing_primary_key || defined_primary_key) &&
449
- existing_primary_key_columns != defined_primary_key&.columns
449
+ existing_primary_key_columns != defined_primary_key&.columns
450
450
  ::DeclareSchema::SchemaChange::PrimaryKeyChange.new(new_table_name, existing_primary_key_columns, defined_primary_key&.columns)
451
451
  end
452
452
  end
@@ -509,12 +509,14 @@ module Generators
509
509
 
510
510
  def foreign_key_changes_due_to_column_renames(fks_to_drop, fks_to_add, to_rename)
511
511
  fks_to_drop.each_with_object([[], []]) do |fk_to_drop, (renamed_fks_to_drop, renamed_fks_to_add)|
512
- if (fk_to_add = fks_to_add.find do |fk_to_add|
512
+ fk_to_add = fks_to_add.find do |fk_to_add|
513
513
  fk_to_add.foreign_key.nil? and raise "Foreign key is not allowed to be nil for #{fk_to_add.inspect}"
514
514
  fk_to_add.child_table_name == fk_to_drop.child_table_name &&
515
- fk_to_add.parent_table_name == fk_to_drop.parent_table_name &&
516
- fk_to_add.foreign_key == to_rename[fk_to_drop.foreign_key]
517
- end)
515
+ fk_to_add.parent_table_name == fk_to_drop.parent_table_name &&
516
+ fk_to_add.foreign_key == to_rename[fk_to_drop.foreign_key]
517
+ end
518
+
519
+ if fk_to_add
518
520
  renamed_fks_to_drop << fk_to_drop
519
521
  renamed_fks_to_add << fk_to_add
520
522
  end
@@ -49,11 +49,10 @@ RSpec.describe DeclareSchema::Model::ForeignKeyDefinition do
49
49
  end
50
50
 
51
51
  context 'when all options passed' do
52
- let(:foreign_key) { nil }
53
52
  let(:options) { { parent_table: :networks, foreign_key: :the_network_id, constraint_name: :constraint_1, dependent: :delete } }
54
53
 
55
54
  it 'normalizes symbols to strings' do
56
- expect(subject.foreign_key).to be_nil
55
+ expect(subject.foreign_key).to eq('network_id')
57
56
  expect(subject.foreign_key_name).to eq('the_network_id')
58
57
  expect(subject.parent_table_name).to eq('networks')
59
58
  expect(subject.constraint_name).to eq('constraint_1')
@@ -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,14 +1,14 @@
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.6
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
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-29 00:00:00.000000000 Z
11
+ date: 2023-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails