declare_schema 1.2.3.pre.ga.9 → 1.2.3.pre.ga.11
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: 86fb8e0f1179f4a912b7c841221b20725037a067ba2832f5e6fead997760e131
|
4
|
+
data.tar.gz: 4317f36bbb51f2ff265ba8746d45287e00b0d2b2846b53aee1635d7a658cb4e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 654a545b37437f371acc2a1c8faafcdb6a0282f2edc93357dd5ab73df0f1a55b8f529741ee6a0f68517fc41e90990b5bc15bc4d72c4703158e0e38288b2de868
|
7
|
+
data.tar.gz: 5eeb08441fa3be8f1963b810c07332db31791cde928575d86d827d4cce39801e53903a4cd941c0b9de9e81cd6adfa53cf79b07fd6d09afa2c4b420473907c2d5
|
data/Gemfile.lock
CHANGED
@@ -12,7 +12,7 @@ module DeclareSchema
|
|
12
12
|
|
13
13
|
def initialize(model, foreign_key, **options)
|
14
14
|
@model = model
|
15
|
-
@foreign_key = foreign_key.to_s.presence or raise ArgumentError "Foreign key
|
15
|
+
@foreign_key = foreign_key.to_s.presence or raise ArgumentError "Foreign key must not be empty: #{foreign_key.inspect}"
|
16
16
|
@options = options
|
17
17
|
|
18
18
|
@child_table_name = model.table_name # unless a table rename, which would happen when a class is renamed??
|
@@ -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,15 +33,12 @@ module DeclareSchema
|
|
33
33
|
|
34
34
|
class << self
|
35
35
|
# extract IndexSpecs from an existing table
|
36
|
-
#
|
36
|
+
# includes the PRIMARY KEY index
|
37
37
|
def for_model(model, old_table_name = nil)
|
38
38
|
t = old_table_name || model.table_name
|
39
39
|
|
40
|
-
habtm_model = model.is_a?(DeclareSchema::Model::HabtmModelShim)
|
41
|
-
|
42
40
|
primary_key_columns = Array(model.connection.primary_key(t)).presence
|
43
|
-
primary_key_columns
|
44
|
-
raise "could not find primary key for table #{t} in #{model.connection.columns(t).inspect}"
|
41
|
+
primary_key_columns or raise "could not find primary key for table #{t} in #{model.connection.columns(t).inspect}"
|
45
42
|
|
46
43
|
primary_key_found = false
|
47
44
|
index_definitions = model.connection.indexes(t).map do |i|
|
@@ -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
|
@@ -510,7 +510,6 @@ module Generators
|
|
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
512
|
fk_to_add = fks_to_add.find do |fk_to_add|
|
513
|
-
fk_to_add.foreign_key.nil? and raise "Foreign key is not allowed to be nil for #{fk_to_add.inspect}"
|
514
513
|
fk_to_add.child_table_name == fk_to_drop.child_table_name &&
|
515
514
|
fk_to_add.parent_table_name == fk_to_drop.parent_table_name &&
|
516
515
|
fk_to_add.foreign_key == to_rename[fk_to_drop.foreign_key]
|
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.11
|
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-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|