miguel 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/miguel/importer.rb +3 -0
- data/lib/miguel/schema.rb +17 -4
- data/lib/miguel/version.rb +2 -2
- data/test/data/schema.rb +8 -0
- data/test/data/schema.txt +7 -0
- data/test/data/schema_bare.txt +7 -0
- data/test/data/schema_change.txt +7 -0
- data/test/data/schema_down.txt +1 -0
- data/test/data/schema_full.txt +8 -0
- data/test/data/seq_1.txt +2 -2
- data/test/data/seq_2.txt +2 -2
- data/test/test_importer.rb +2 -2
- data/test/test_schema.rb +6 -0
- 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: 821d6ef0ddebb1aa237b6dabfa0b2272d05107534114c9596ba948bf6a96aa1c
|
4
|
+
data.tar.gz: de5c7d1f3ad59507f5f727b21d5323151a259d215eb32c32a3ba83ff473940c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d89c348653fa910bd3e2a22dc8c30de50b28b60ef14e947a0ae8cafee822f37f9c601551b9cd7cc4f7fc8a43e8b445539d52ae679515bd8ad96fcb481bdfec4c
|
7
|
+
data.tar.gz: e908e8e40752308de4d36453b4a721bfafc7f247a4c0e9dce4cd300fc6280b81d683d0deab8254bf19a4cf16a1c11cd974b0d87455d6aacf2fa60d49480a641c
|
data/README.md
CHANGED
@@ -123,6 +123,7 @@ set_defaults :Time, :timestamp, default: '2000-01-01 00:00:00'
|
|
123
123
|
set_defaults :Time?, :timestamp, default: nil
|
124
124
|
|
125
125
|
set_defaults :unique, :index, unique: true
|
126
|
+
set_defaults :fulltext, :index, type: :full_text
|
126
127
|
|
127
128
|
set_defaults :Key, :integer, unsigned: false
|
128
129
|
set_defaults :primary_key, type: :integer, unsigned: false
|
data/lib/miguel/importer.rb
CHANGED
@@ -160,8 +160,11 @@ module Miguel
|
|
160
160
|
foreign_key_indexes = table.foreign_keys.map{ |x| x.columns if x.columns.size == 1 }.compact
|
161
161
|
for name, opts in db.indexes( table.name )
|
162
162
|
opts = opts.dup
|
163
|
+
opts[ :name ] = name
|
163
164
|
columns = opts.delete( :columns )
|
164
165
|
next if ( ! opts[ :unique ] ) && foreign_key_indexes.include?( columns ) && name == columns.first
|
166
|
+
# Sequel currently doesn't provide info about fulltext indexes, so we have to rely on properly used names.
|
167
|
+
opts[ :type ] = :full_text if name =~ /_fulltext$/
|
165
168
|
opts.delete( :deferrable ) unless opts[ :deferrable ]
|
166
169
|
table.add_index( columns, opts )
|
167
170
|
end
|
data/lib/miguel/schema.rb
CHANGED
@@ -204,11 +204,15 @@ module Miguel
|
|
204
204
|
|
205
205
|
include Output
|
206
206
|
|
207
|
+
# The table this index belongs to.
|
208
|
+
attr_reader :table
|
209
|
+
|
207
210
|
# Index column(s) and options.
|
208
211
|
attr_reader :columns, :opts
|
209
212
|
|
210
213
|
# Create new index for given column(s).
|
211
|
-
def initialize( columns, opts = {} )
|
214
|
+
def initialize( table, columns, opts = {} )
|
215
|
+
@table = table
|
212
216
|
@columns = [ *columns ]
|
213
217
|
@opts = opts
|
214
218
|
end
|
@@ -218,11 +222,16 @@ module Miguel
|
|
218
222
|
|
219
223
|
# Get the index options, in a canonic way.
|
220
224
|
def canonic_opts
|
221
|
-
o = { :unique => false }
|
225
|
+
o = { :unique => false, :name => default_index_name }
|
222
226
|
o.merge!( opts )
|
223
227
|
o.delete_if{ |key, value| IGNORED_OPTS.include? key }
|
224
228
|
end
|
225
229
|
|
230
|
+
# Get default index name for this index.
|
231
|
+
def default_index_name
|
232
|
+
[ table.name, *columns, :index ].join( '_' ).to_sym
|
233
|
+
end
|
234
|
+
|
226
235
|
# Compare one index with another one.
|
227
236
|
def == other
|
228
237
|
other.is_a?( Index ) &&
|
@@ -367,7 +376,7 @@ module Miguel
|
|
367
376
|
|
368
377
|
# Add index definition.
|
369
378
|
def add_index( columns, *args )
|
370
|
-
@indexes << Index.new( columns, *args )
|
379
|
+
@indexes << Index.new( self, columns, *args )
|
371
380
|
end
|
372
381
|
|
373
382
|
# Add foreign key definition.
|
@@ -529,6 +538,7 @@ module Miguel
|
|
529
538
|
# :Time?, :timestamp, :default => nil
|
530
539
|
#
|
531
540
|
# :unique, :index, :unique => true
|
541
|
+
# :fulltext, :index, :type => :full_text
|
532
542
|
#
|
533
543
|
# :Key, :integer, :unsigned => false
|
534
544
|
# :primary_key, :type => :integer, :unsigned => false
|
@@ -560,9 +570,12 @@ module Miguel
|
|
560
570
|
opts[ :type ] ||= :integer unless args.first.is_a? Array or not opts[ :unsigned ]
|
561
571
|
end
|
562
572
|
|
563
|
-
# Save some typing for unique indexes.
|
573
|
+
# Save some typing for unique and fulltext indexes.
|
564
574
|
|
565
575
|
set_defaults :unique, :index, :unique => true
|
576
|
+
set_defaults :fulltext, :index, :type => :full_text do |opts,args,table|
|
577
|
+
opts[ :name ] ||= [ table, *args, :fulltext ].join( '_' ).to_sym
|
578
|
+
end
|
566
579
|
|
567
580
|
# Type shortcuts we use frequently.
|
568
581
|
|
data/lib/miguel/version.rb
CHANGED
data/test/data/schema.rb
CHANGED
@@ -96,8 +96,16 @@ Miguel::Schema.define( use_defaults: false ) do
|
|
96
96
|
unique [:a, :c]
|
97
97
|
index [:b, :c, :d]
|
98
98
|
index [:b, :a]
|
99
|
+
index [:c, :d], name: :named_cd_index
|
99
100
|
end
|
100
101
|
|
102
|
+
table :fulltext do
|
103
|
+
String :s
|
104
|
+
Text :t
|
105
|
+
fulltext :s
|
106
|
+
fulltext [:s, :t]
|
107
|
+
end unless opts[ :skip_fulltext ]
|
108
|
+
|
101
109
|
table :null do
|
102
110
|
String? :string
|
103
111
|
Text? :text
|
data/test/data/schema.txt
CHANGED
@@ -68,8 +68,15 @@ table :compound do
|
|
68
68
|
index [:a, :c], :null => false, :unique => true
|
69
69
|
index [:b, :c, :d], :null => false
|
70
70
|
index [:b, :a], :null => false
|
71
|
+
index [:c, :d], :null => false, :name => :named_cd_index
|
71
72
|
foreign_key [:b, :a], :compound, :null => false, :key => [:a, :b], :unsigned => false
|
72
73
|
end
|
74
|
+
table :fulltext do
|
75
|
+
String :s, :null => false, :text => false
|
76
|
+
String :t, :null => false, :text => true
|
77
|
+
index [:s], :null => false, :type => :full_text, :name => :fulltext_s_fulltext
|
78
|
+
index [:s, :t], :null => false, :type => :full_text, :name => :fulltext_s_t_fulltext
|
79
|
+
end
|
73
80
|
table :null do
|
74
81
|
String :string, :null => true, :text => false
|
75
82
|
String :text, :null => true, :text => true
|
data/test/data/schema_bare.txt
CHANGED
@@ -66,6 +66,13 @@ create_table :compound do
|
|
66
66
|
index [:a, :c], :null => false, :unique => true
|
67
67
|
index [:b, :c, :d], :null => false
|
68
68
|
index [:b, :a], :null => false
|
69
|
+
index [:c, :d], :null => false, :name => :named_cd_index
|
70
|
+
end
|
71
|
+
create_table :fulltext do
|
72
|
+
String :s, :null => false, :text => false
|
73
|
+
String :t, :null => false, :text => true
|
74
|
+
index [:s], :null => false, :type => :full_text, :name => :fulltext_s_fulltext
|
75
|
+
index [:s, :t], :null => false, :type => :full_text, :name => :fulltext_s_t_fulltext
|
69
76
|
end
|
70
77
|
create_table :null do
|
71
78
|
String :string, :null => true, :text => false
|
data/test/data/schema_change.txt
CHANGED
@@ -68,6 +68,13 @@ Sequel.migration do
|
|
68
68
|
index [:a, :c], :null => false, :unique => true
|
69
69
|
index [:b, :c, :d], :null => false
|
70
70
|
index [:b, :a], :null => false
|
71
|
+
index [:c, :d], :null => false, :name => :named_cd_index
|
72
|
+
end
|
73
|
+
create_table :fulltext do
|
74
|
+
String :s, :null => false, :text => false
|
75
|
+
String :t, :null => false, :text => true
|
76
|
+
index [:s], :null => false, :type => :full_text, :name => :fulltext_s_fulltext
|
77
|
+
index [:s, :t], :null => false, :type => :full_text, :name => :fulltext_s_t_fulltext
|
71
78
|
end
|
72
79
|
create_table :null do
|
73
80
|
String :string, :null => true, :text => false
|
data/test/data/schema_down.txt
CHANGED
data/test/data/schema_full.txt
CHANGED
@@ -68,6 +68,13 @@ Sequel.migration do
|
|
68
68
|
index [:a, :c], :null => false, :unique => true
|
69
69
|
index [:b, :c, :d], :null => false
|
70
70
|
index [:b, :a], :null => false
|
71
|
+
index [:c, :d], :null => false, :name => :named_cd_index
|
72
|
+
end
|
73
|
+
create_table :fulltext do
|
74
|
+
String :s, :null => false, :text => false
|
75
|
+
String :t, :null => false, :text => true
|
76
|
+
index [:s], :null => false, :type => :full_text, :name => :fulltext_s_fulltext
|
77
|
+
index [:s, :t], :null => false, :type => :full_text, :name => :fulltext_s_t_fulltext
|
71
78
|
end
|
72
79
|
create_table :null do
|
73
80
|
String :string, :null => true, :text => false
|
@@ -157,6 +164,7 @@ Sequel.migration do
|
|
157
164
|
drop_table :simple
|
158
165
|
drop_table :reuse
|
159
166
|
drop_table :compound
|
167
|
+
drop_table :fulltext
|
160
168
|
drop_table :null
|
161
169
|
drop_table :defaults
|
162
170
|
drop_table :simple_users
|
data/test/data/seq_1.txt
CHANGED
@@ -14,7 +14,7 @@ Sequel.migration do
|
|
14
14
|
add_column :create_time, :timestamp, :default => "2000-01-01 00:00:00", :null => false
|
15
15
|
add_column :update_time, :timestamp, :default => "2000-01-01 00:00:00", :null => false
|
16
16
|
add_column :fk, :integer, :default => 0, :null => false, :key => [:id], :unsigned => false
|
17
|
-
add_index [:u], :unique => true
|
17
|
+
add_index [:u], :unique => true, :name => :b_u_index
|
18
18
|
end
|
19
19
|
create_table :c do
|
20
20
|
primary_key :id, :null => false, :unsigned => false
|
@@ -46,7 +46,7 @@ Sequel.migration do
|
|
46
46
|
set_column_type :a, Integer, :null => false
|
47
47
|
end
|
48
48
|
alter_table :b do
|
49
|
-
drop_index [:u] # :unique => true
|
49
|
+
drop_index [:u] # :unique => true, :name => :b_u_index
|
50
50
|
drop_column :create_time # :timestamp, :null => false, :default => "2000-01-01 00:00:00"
|
51
51
|
drop_column :update_time # :timestamp, :null => false, :default => "2000-01-01 00:00:00"
|
52
52
|
drop_column :fk # :integer, :null => false, :key => [:id], :unsigned => false
|
data/test/data/seq_2.txt
CHANGED
@@ -4,7 +4,7 @@ Sequel.migration do
|
|
4
4
|
drop_foreign_key [:fk] # :a, :on_update => :no_action, :on_delete => :no_action, :key => [:id]
|
5
5
|
end
|
6
6
|
alter_table :b do
|
7
|
-
add_index [:create_time], :unique => false
|
7
|
+
add_index [:create_time], :unique => false, :name => :b_create_time_index
|
8
8
|
end
|
9
9
|
alter_table :c do
|
10
10
|
add_column :t, String, :default => "", :null => false, :text => true
|
@@ -36,7 +36,7 @@ Sequel.migration do
|
|
36
36
|
end
|
37
37
|
drop_table :a_b
|
38
38
|
alter_table :b do
|
39
|
-
drop_index [:create_time] # :unique => false
|
39
|
+
drop_index [:create_time] # :unique => false, :name => :b_create_time_index
|
40
40
|
end
|
41
41
|
alter_table :c do
|
42
42
|
drop_column :t # String, :null => false, :text => true
|
data/test/test_importer.rb
CHANGED
data/test/test_schema.rb
CHANGED
@@ -430,20 +430,26 @@ describe Miguel::Schema do
|
|
430
430
|
Integer :a, :null => false
|
431
431
|
Integer :b, :null => false
|
432
432
|
String :s, :null => false, :text => false
|
433
|
+
String :t, :null => false, :text => true
|
433
434
|
index [:a], :null => false
|
434
435
|
index [:b], :null => false, :unique => true
|
435
436
|
index [:a, :b], :null => false
|
436
437
|
index [:a, :b, :c], :null => false, :unique => true
|
438
|
+
index [:s], :null => false, :type => :full_text, :name => :index_s_fulltext
|
439
|
+
index [:s, :t], :null => false, :type => :full_text, :name => :index_s_t_fulltext
|
437
440
|
end
|
438
441
|
EOT
|
439
442
|
table :index do
|
440
443
|
Integer :a
|
441
444
|
Integer :b
|
442
445
|
String :s
|
446
|
+
Text :t
|
443
447
|
index :a
|
444
448
|
unique :b
|
445
449
|
index [:a, :b]
|
446
450
|
unique [:a, :b, :c]
|
451
|
+
fulltext :s
|
452
|
+
fulltext [:s, :t]
|
447
453
|
end
|
448
454
|
end
|
449
455
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: miguel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrik Rak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|