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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5432e4443335e0e9b60e9242f1b6523b833ae70434c7a0a13c5c01fd72b5a96c
|
4
|
+
data.tar.gz: 94c14df3be1af4d13103417ccec13a41461ecd9ad21922a44338de33b879cda9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc84382b23765a035f81b063c6e066f5ef6d56b4605696d3e4a15417d64ba7b42d8c0ddc157796d180b3adde9135934ceee2d156d5de1fecd22f751ee4b303a6
|
7
|
+
data.tar.gz: afaf8a450c895880c97accb55dbb36c96152b1f3ce7c4ede51e8da5c4aa0044a6862adc2ffcab4f82276285f8a3b19d3226342ac3011d9f6c84bc2a930ac909d
|
data/Gemfile.lock
CHANGED
@@ -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:
|
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.
|
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
|
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
|
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
|
60
|
+
def default_index_name(columns)
|
67
61
|
"on_#{Array(columns).join("_and_")}"
|
68
62
|
end
|
69
63
|
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
|
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
|
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.
|
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-
|
11
|
+
date: 2023-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|