declare_schema 1.4.0.colin.1 → 1.4.0.colin.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/declare_schema/model.rb +6 -6
- data/lib/declare_schema/schema_change/index_add.rb +3 -3
- data/lib/declare_schema/version.rb +1 -1
- data/lib/generators/declare_schema/migration/migrator.rb +2 -2
- data/spec/lib/declare_schema/schema_change/index_add_spec.rb +11 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d774a80915bfd6f22349e18be176e237c901d595a871144a08d73478946147b
|
4
|
+
data.tar.gz: 0cc5d18ba43357d595dff24ff3a2bf3f9443b9d3f8ed9ec909d53708b2820984
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96b51490860259a27e1b1fcbe02bab2722ca069ec9ee314879ccf563fc4f420c44485de9ec57035165a057953a9ba4705c5575c38f6a4592088d47c8704dafc1
|
7
|
+
data.tar.gz: ddb153c4999b17c8c74885b4bfa9ef7488992c760797808af40840cdb579f8e162d66b0cf043b1543905ef1282252c5dd371d40881cd403bdba2429b6590f81a
|
data/Gemfile.lock
CHANGED
data/lib/declare_schema/model.rb
CHANGED
@@ -51,9 +51,9 @@ module DeclareSchema
|
|
51
51
|
module ClassMethods
|
52
52
|
def index(fields, **options)
|
53
53
|
# make index idempotent
|
54
|
-
|
55
|
-
unless index_definitions.any? { |index_spec| index_spec.
|
56
|
-
index_definitions <<
|
54
|
+
index = ::DeclareSchema::Model::IndexDefinition.new(self, fields, **options)
|
55
|
+
unless index_definitions.any? { |index_spec| index_spec.equivalent?(index) }
|
56
|
+
index_definitions << index
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
@@ -122,7 +122,7 @@ module DeclareSchema
|
|
122
122
|
index_options = {}
|
123
123
|
case index_value
|
124
124
|
when String
|
125
|
-
Kernel.warn("belongs_to index: 'name' is deprecated; use index: { name: 'name' } instead")
|
125
|
+
Kernel.warn("belongs_to index: 'name' is deprecated; use index: { name: 'name' } instead (in #{name})")
|
126
126
|
index_options[:name] = index_value
|
127
127
|
# when false -- impossible since we checked that above
|
128
128
|
when true
|
@@ -134,7 +134,7 @@ module DeclareSchema
|
|
134
134
|
end
|
135
135
|
|
136
136
|
if options.has_key?(:unique)
|
137
|
-
Kernel.warn("belongs_to unique: true|false is deprecated; use index: { unique: true|false } instead")
|
137
|
+
Kernel.warn("belongs_to unique: true|false is deprecated; use index: { unique: true|false } instead (in #{name})")
|
138
138
|
index_options[:unique] = options.delete(:unique)
|
139
139
|
end
|
140
140
|
|
@@ -305,7 +305,7 @@ module DeclareSchema
|
|
305
305
|
if (to_name = options.delete(:index))
|
306
306
|
index_opts =
|
307
307
|
{
|
308
|
-
unique: args.include?(:unique) || options.delete(:unique)
|
308
|
+
unique: args.include?(:unique) || !!options.delete(:unique)
|
309
309
|
}
|
310
310
|
# support index: true declaration
|
311
311
|
index_opts[:name] = to_name unless to_name == true
|
@@ -5,13 +5,13 @@ require_relative 'base'
|
|
5
5
|
module DeclareSchema
|
6
6
|
module SchemaChange
|
7
7
|
class IndexAdd < Base
|
8
|
-
def initialize(table_name, column_names, name:, unique:, where: nil,
|
8
|
+
def initialize(table_name, column_names, name:, unique:, where: nil, length: nil)
|
9
9
|
@table_name = table_name
|
10
10
|
@column_names = column_names
|
11
11
|
@name = name
|
12
12
|
@unique = unique
|
13
13
|
@where = where.presence
|
14
|
-
@
|
14
|
+
@length = length
|
15
15
|
end
|
16
16
|
|
17
17
|
def up_command
|
@@ -20,7 +20,7 @@ module DeclareSchema
|
|
20
20
|
}
|
21
21
|
options[:unique] = true if @unique
|
22
22
|
options[:where] = @where if @where
|
23
|
-
options[:
|
23
|
+
options[:length] = @length if @length
|
24
24
|
|
25
25
|
"add_index #{[@table_name.to_sym.inspect,
|
26
26
|
@column_names.map(&:to_sym).inspect,
|
@@ -457,11 +457,11 @@ module Generators
|
|
457
457
|
renamed_indexes_to_drop, renamed_indexes_to_add = index_changes_due_to_column_renames(indexes_to_drop, indexes_to_add, to_rename)
|
458
458
|
|
459
459
|
drop_indexes = (indexes_to_drop - renamed_indexes_to_drop).map do |i|
|
460
|
-
::DeclareSchema::SchemaChange::IndexRemove.new(new_table_name, i.columns,
|
460
|
+
::DeclareSchema::SchemaChange::IndexRemove.new(new_table_name, i.columns, **i.options)
|
461
461
|
end
|
462
462
|
|
463
463
|
add_indexes = (indexes_to_add - renamed_indexes_to_add).map do |i|
|
464
|
-
::DeclareSchema::SchemaChange::IndexAdd.new(new_table_name, i.columns,
|
464
|
+
::DeclareSchema::SchemaChange::IndexAdd.new(new_table_name, i.columns, **i.options)
|
465
465
|
end
|
466
466
|
|
467
467
|
# the order is important here - adding a :unique, for instance needs to remove then add
|
@@ -46,30 +46,30 @@ RSpec.describe DeclareSchema::SchemaChange::IndexAdd do
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
context 'with
|
50
|
-
let(:
|
51
|
-
subject { described_class.new(table_name, column_names, name: name, unique: unique,
|
49
|
+
context 'with length: nil' do
|
50
|
+
let(:length) { nil }
|
51
|
+
subject { described_class.new(table_name, column_names, name: name, unique: unique, length: length) }
|
52
52
|
|
53
53
|
it 'responds with command' do
|
54
54
|
expect(subject.up).to eq("add_index :#{table_name}, #{column_names.map(&:to_sym).inspect}, name: #{name.to_sym.inspect}\n")
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
context 'with
|
59
|
-
let(:
|
60
|
-
subject { described_class.new(table_name, column_names, name: name, unique: unique,
|
58
|
+
context 'with length: 2' do
|
59
|
+
let(:length) { 2 }
|
60
|
+
subject { described_class.new(table_name, column_names, name: name, unique: unique, length: length) }
|
61
61
|
|
62
62
|
it 'responds with command' do
|
63
|
-
expect(subject.up).to eq("add_index :#{table_name}, #{column_names.map(&:to_sym).inspect}, name: #{name.to_sym.inspect},
|
63
|
+
expect(subject.up).to eq("add_index :#{table_name}, #{column_names.map(&:to_sym).inspect}, name: #{name.to_sym.inspect}, length: #{length}\n")
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
context 'with
|
68
|
-
let(:
|
69
|
-
subject { described_class.new(table_name, column_names, name: name, unique: unique,
|
67
|
+
context 'with length: hash' do
|
68
|
+
let(:length) { { last_name: 10, first_name: 1 } }
|
69
|
+
subject { described_class.new(table_name, column_names, name: name, unique: unique, length: length) }
|
70
70
|
|
71
71
|
it 'responds with command' do
|
72
|
-
expect(subject.up).to eq("add_index :#{table_name}, #{column_names.map(&:to_sym).inspect}, name: #{name.to_sym.inspect},
|
72
|
+
expect(subject.up).to eq("add_index :#{table_name}, #{column_names.map(&:to_sym).inspect}, name: #{name.to_sym.inspect}, length: { last_name: 10, first_name: 1 }\n")
|
73
73
|
end
|
74
74
|
end
|
75
75
|
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.4.0.colin.
|
4
|
+
version: 1.4.0.colin.3
|
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: 2024-01-
|
11
|
+
date: 2024-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|