declare_schema 1.2.3.pre.ga.8 → 1.2.3.pre.ga.10

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: ac52b40b3a13a99d43517d2755123ba3a836140fcf9862d10b35a586eaad9ef7
4
- data.tar.gz: d84e7782e16652da230cb9e51ee4c951bba67c692ab58f12056f9e895738d203
3
+ metadata.gz: 5432e4443335e0e9b60e9242f1b6523b833ae70434c7a0a13c5c01fd72b5a96c
4
+ data.tar.gz: 94c14df3be1af4d13103417ccec13a41461ecd9ad21922a44338de33b879cda9
5
5
  SHA512:
6
- metadata.gz: c03703d46e1ed3c149f51ad479e2baacc88bc174a1b5239419c9f906cf0a638b26f0299ac50845660734151e18ef1b0048479abf491b685dd81ba9d55649edf3
7
- data.tar.gz: e20b98d2651485183f4df433eb482715d492175c8fb6407e7030ed08c90ae8c5845d633044a335c91578531f3e5c11df23348b81f95cf9d7871204e20a4f4178
6
+ metadata.gz: bc84382b23765a035f81b063c6e066f5ef6d56b4605696d3e4a15417d64ba7b42d8c0ddc157796d180b3adde9135934ceee2d156d5de1fecd22f751ee4b303a6
7
+ data.tar.gz: afaf8a450c895880c97accb55dbb36c96152b1f3ce7c4ede51e8da5c4aa0044a6862adc2ffcab4f82276285f8a3b19d3226342ac3011d9f6c84bc2a930ac909d
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.8)
4
+ declare_schema (1.2.3.pre.ga.10)
5
5
  rails (>= 5.0)
6
6
 
7
7
  GEM
@@ -53,7 +53,7 @@ module DeclareSchema
53
53
 
54
54
  def index_definitions_with_primary_key
55
55
  [
56
- IndexDefinition.new(self, foreign_keys, unique: true, name: "PRIMARY KEY"), # creates a primary composite key on both foreign keys
56
+ IndexDefinition.new(self, foreign_keys, unique: true, name: Model::IndexDefinition::PRIMARY_KEY_NAME), # creates a primary composite key on both foreign keys
57
57
  IndexDefinition.new(self, foreign_keys.last) # not unique by itself; combines with primary key to be unique
58
58
  ]
59
59
  end
@@ -19,7 +19,7 @@ module DeclareSchema
19
19
  @table = options.delete(:table_name) || model.table_name
20
20
  @fields = Array.wrap(fields).map(&:to_s)
21
21
  @explicit_name = options[:name] unless options.delete(:allow_equivalent)
22
- @name = options.delete(:name) || self.class.index_name(@fields)
22
+ @name = options.delete(:name) || self.class.default_index_name(@fields)
23
23
  @unique = options.delete(:unique) || name == PRIMARY_KEY_NAME || false
24
24
 
25
25
  if @name.length > MYSQL_INDEX_NAME_MAX_LENGTH
@@ -33,14 +33,11 @@ module DeclareSchema
33
33
 
34
34
  class << self
35
35
  # extract IndexSpecs from an existing table
36
- # always includes the PRIMARY KEY index for Model unless it is a HABTM Model.
37
36
  def for_model(model, old_table_name = nil)
38
37
  t = old_table_name || model.table_name
39
38
 
40
- habtm_model = model.is_a?(DeclareSchema::Model::HabtmModelShim)
41
-
42
39
  primary_key_columns = Array(model.connection.primary_key(t)).presence
43
- primary_key_columns || habtm_model or
40
+ primary_key_columns or
44
41
  raise "could not find primary key for table #{t} in #{model.connection.columns(t).inspect}"
45
42
 
46
43
  primary_key_found = false
@@ -50,20 +47,17 @@ module DeclareSchema
50
47
  i.columns == primary_key_columns && i.unique or
51
48
  raise "primary key on #{t} was not unique on #{primary_key_columns} (was unique=#{i.unique} on #{i.columns})"
52
49
  primary_key_found = true
53
- elsif i.columns == primary_key_columns && i.unique && !habtm_model
54
- # skip this primary key index since we'll create it below, with PRIMARY_KEY_NAME
55
- next
56
50
  end
57
51
  new(model, i.columns, name: i.name, unique: i.unique, where: i.where, table_name: old_table_name)
58
52
  end.compact
59
53
 
60
- if !primary_key_found && !habtm_model
54
+ if !primary_key_found
61
55
  index_definitions << new(model, primary_key_columns, name: PRIMARY_KEY_NAME, unique: true, where: nil, table_name: old_table_name)
62
56
  end
63
57
  index_definitions
64
58
  end
65
59
 
66
- def index_name(columns)
60
+ def default_index_name(columns)
67
61
  "on_#{Array(columns).join("_and_")}"
68
62
  end
69
63
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeclareSchema
4
- VERSION = "1.2.3.pre.ga.8"
4
+ VERSION = "1.2.3.pre.ga.10"
5
5
  end
@@ -102,7 +102,7 @@ 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('PRIMARY KEY')
105
+ expect(result.first.name).to eq('PRIMARY')
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
@@ -127,7 +127,7 @@ RSpec.describe DeclareSchema::Model::HabtmModelShim do
127
127
  result = subject.index_definitions_with_primary_key
128
128
  expect(result.size).to eq(2), result.inspect
129
129
  expect(result.first).to be_a(::DeclareSchema::Model::IndexDefinition)
130
- expect(result.first.name).to eq('PRIMARY KEY')
130
+ expect(result.first.name).to eq('PRIMARY')
131
131
  expect(result.first.fields).to eq(['advertiser_campaign', 'tracking_pixel'])
132
132
  expect(result.first.unique).to be_truthy
133
133
  end
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.8
4
+ version: 1.2.3.pre.ga.10
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-30 00:00:00.000000000 Z
11
+ date: 2023-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails