sequel-sequence 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +41 -8
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +7 -0
- data/CONTRIBUTING.md +110 -13
- data/README.md +28 -9
- data/Rakefile +9 -1
- data/lib/sequel/sequence/database/postgresql.rb +3 -2
- data/lib/sequel/sequence/database/server/mariadb.rb +71 -0
- data/lib/sequel/sequence/database/server/mysql.rb +178 -0
- data/lib/sequel/sequence/database/sqlite.rb +11 -4
- data/lib/sequel/sequence/database.rb +2 -2
- data/lib/sequel/sequence/database_ext_connection.rb +25 -0
- data/lib/sequel/sequence/version.rb +1 -1
- data/lib/sequel/sequence.rb +1 -9
- data/sequel-sequence.gemspec +3 -2
- data/test/mariadb_test_helper.rb +32 -0
- data/test/mysql_test_helper.rb +11 -9
- data/test/sequel/mariadb_sequence_test.rb +182 -0
- data/test/sequel/mysql_sequence_test.rb +214 -41
- data/test/sequel/sqlite_sequence_test.rb +77 -5
- data/test/sqlite_test_helper.rb +2 -1
- metadata +11 -6
- data/lib/sequel/sequence/database/mysql.rb +0 -10
- data/lib/sequel/sequence/database/mysql2.rb +0 -81
@@ -12,13 +12,28 @@ class MysqlSequenceTest < Minitest::Test
|
|
12
12
|
test 'adds sequence with default values' do
|
13
13
|
with_migration do
|
14
14
|
def up
|
15
|
-
# create_sequence :position, {start: 1, increment: 1} - default values
|
15
|
+
# create_sequence :position, {start: 1, increment: 1, numeric_label: 0} - default values
|
16
16
|
create_sequence :position
|
17
17
|
end
|
18
18
|
end.up
|
19
19
|
|
20
|
-
assert_equal 1, MysqlDB.nextval(:position)
|
21
20
|
assert_equal 2, MysqlDB.nextval(:position)
|
21
|
+
assert_equal 3, MysqlDB.nextval(:position)
|
22
|
+
end
|
23
|
+
|
24
|
+
test 'adds sequence with numeric_label' do
|
25
|
+
with_migration do
|
26
|
+
def up
|
27
|
+
# create_sequence :position, {start: 1, increment: 1, numeric_label: 0} - default values
|
28
|
+
create_sequence :position, numeric_label: 10
|
29
|
+
end
|
30
|
+
end.up
|
31
|
+
|
32
|
+
assert_equal 1, MysqlDB.currval(:position)
|
33
|
+
|
34
|
+
fiction_list = MysqlDB.fetch('SELECT fiction FROM position;').all
|
35
|
+
assert_equal 1, fiction_list.size
|
36
|
+
assert_equal 10, fiction_list.first[:fiction]
|
22
37
|
end
|
23
38
|
|
24
39
|
test 'adds sequence reader within model and its inherited class' do
|
@@ -28,15 +43,15 @@ class MysqlSequenceTest < Minitest::Test
|
|
28
43
|
end
|
29
44
|
end.up
|
30
45
|
|
31
|
-
class
|
46
|
+
class Stuff < Sequel::Model; end
|
32
47
|
|
33
|
-
assert_equal
|
34
|
-
assert_equal
|
48
|
+
assert_equal 2, Stuff.db.nextval('position')
|
49
|
+
assert_equal 3, Stuff.db.nextval('position')
|
35
50
|
|
36
|
-
class
|
51
|
+
class InheritedStuff < Stuff; end
|
37
52
|
|
38
|
-
assert_equal
|
39
|
-
assert_equal
|
53
|
+
assert_equal 4, InheritedStuff.db.nextval(:position)
|
54
|
+
assert_equal 5, InheritedStuff.db.nextval(:position)
|
40
55
|
end
|
41
56
|
|
42
57
|
test 'adds sequence starting at 100' do
|
@@ -46,30 +61,34 @@ class MysqlSequenceTest < Minitest::Test
|
|
46
61
|
end
|
47
62
|
end.up
|
48
63
|
|
49
|
-
assert_equal 100, MysqlDB.nextval(:position)
|
50
64
|
assert_equal 101, MysqlDB.nextval(:position)
|
65
|
+
assert_equal 102, MysqlDB.nextval(:position)
|
51
66
|
end
|
52
67
|
|
53
|
-
test 'adds sequence
|
68
|
+
test 'adds a sequence that we are trying to increase by a value greater than 1' do
|
69
|
+
@step = 4
|
54
70
|
with_migration do
|
55
71
|
def up
|
56
|
-
create_sequence :position, increment:
|
72
|
+
create_sequence :position, increment: 4
|
57
73
|
end
|
58
74
|
end.up
|
59
75
|
|
60
|
-
assert_equal
|
76
|
+
assert_equal 2, MysqlDB.nextval(:position)
|
61
77
|
assert_equal 3, MysqlDB.nextval(:position)
|
78
|
+
assert_operator (2 + @step), :>, MysqlDB.nextval(:position)
|
62
79
|
end
|
63
80
|
|
64
|
-
test 'adds sequence
|
81
|
+
test 'adds a sequence that we are trying to increase by a value greater than 1 (using :step alias)' do
|
82
|
+
@step = 4
|
65
83
|
with_migration do
|
66
84
|
def up
|
67
|
-
create_sequence :position, step:
|
85
|
+
create_sequence :position, step: 4
|
68
86
|
end
|
69
87
|
end.up
|
70
88
|
|
71
|
-
assert_equal
|
89
|
+
assert_equal 2, MysqlDB.nextval(:position)
|
72
90
|
assert_equal 3, MysqlDB.nextval(:position)
|
91
|
+
assert_operator (2 + @step), :>, MysqlDB.nextval(:position)
|
73
92
|
end
|
74
93
|
|
75
94
|
test "returns current/last sequence value, which doesn't increase by itself" do
|
@@ -80,33 +99,70 @@ class MysqlSequenceTest < Minitest::Test
|
|
80
99
|
end.up
|
81
100
|
|
82
101
|
MysqlDB.nextval(:position)
|
102
|
+
# changed value (=2) after default one (=1)
|
83
103
|
|
84
|
-
assert_equal
|
85
|
-
assert_equal
|
86
|
-
assert_equal
|
87
|
-
assert_equal
|
104
|
+
assert_equal 2, MysqlDB.currval(:position)
|
105
|
+
assert_equal 2, MysqlDB.lastval(:position)
|
106
|
+
assert_equal 2, MysqlDB.currval(:position)
|
107
|
+
assert_equal 2, MysqlDB.lastval(:position)
|
88
108
|
end
|
89
109
|
|
90
|
-
test 'sets sequence value' do
|
110
|
+
test 'sets a new sequence value greater than the current one' do
|
91
111
|
with_migration do
|
92
112
|
def up
|
93
113
|
create_sequence :position
|
94
114
|
end
|
95
115
|
end.up
|
96
116
|
|
97
|
-
MysqlDB.nextval(:position)
|
98
117
|
assert_equal MysqlDB.currval(:position), 1
|
99
118
|
|
119
|
+
MysqlDB.nextval(:position)
|
120
|
+
assert_equal MysqlDB.currval(:position), 2
|
121
|
+
|
100
122
|
MysqlDB.setval(:position, 101)
|
101
|
-
|
102
|
-
|
123
|
+
assert_equal 101, MysqlDB.lastval(:position)
|
124
|
+
|
125
|
+
assert_equal 102, MysqlDB.nextval(:position)
|
126
|
+
end
|
127
|
+
|
128
|
+
test 'sets a new sequence value less than the current one' do
|
129
|
+
with_migration do
|
130
|
+
def up
|
131
|
+
create_sequence :position, start: 100
|
132
|
+
end
|
133
|
+
end.up
|
134
|
+
|
135
|
+
assert_equal MysqlDB.currval(:position), 100
|
136
|
+
|
137
|
+
MysqlDB.nextval(:position)
|
138
|
+
assert_equal MysqlDB.currval(:position), 101
|
139
|
+
|
140
|
+
MysqlDB.setval(:position, 1)
|
141
|
+
assert_equal 101, MysqlDB.lastval(:position)
|
103
142
|
|
104
143
|
MysqlDB.nextval(:position)
|
105
|
-
# now the value is correct
|
106
144
|
assert_equal 102, MysqlDB.lastval(:position)
|
107
145
|
end
|
108
146
|
|
109
|
-
test '
|
147
|
+
test 'sets a new sequence value with a label' do
|
148
|
+
with_migration do
|
149
|
+
def up
|
150
|
+
create_sequence :position
|
151
|
+
end
|
152
|
+
end.up
|
153
|
+
|
154
|
+
MysqlDB.nextval(:position)
|
155
|
+
MysqlDB.nextval_with_label(:position, 1)
|
156
|
+
MysqlDB.nextval_with_label(:position, 1)
|
157
|
+
fiction_set_size = MysqlDB.fetch('SELECT * FROM position where fiction = 1;').all.size
|
158
|
+
assert_equal 2, fiction_set_size
|
159
|
+
|
160
|
+
# create_sequence + nextval
|
161
|
+
fiction_set_size = MysqlDB.fetch('SELECT * FROM position where fiction = 0;').all.size
|
162
|
+
assert_equal 2, fiction_set_size
|
163
|
+
end
|
164
|
+
|
165
|
+
test 'drops the sequence and the check_sequences' do
|
110
166
|
with_migration do
|
111
167
|
def up
|
112
168
|
create_sequence :position
|
@@ -114,7 +170,7 @@ class MysqlSequenceTest < Minitest::Test
|
|
114
170
|
end.up
|
115
171
|
|
116
172
|
sequence = MysqlDB.check_sequences.find_all do |seq|
|
117
|
-
seq[:
|
173
|
+
seq[:name] == 'position'
|
118
174
|
end
|
119
175
|
|
120
176
|
assert_equal 1, sequence.size
|
@@ -126,14 +182,40 @@ class MysqlSequenceTest < Minitest::Test
|
|
126
182
|
end.down
|
127
183
|
|
128
184
|
sequence = MysqlDB.check_sequences.find do |seq|
|
129
|
-
seq[:
|
185
|
+
seq[:name] == 'position'
|
186
|
+
end
|
187
|
+
|
188
|
+
assert_nil sequence
|
189
|
+
end
|
190
|
+
|
191
|
+
test 'drops the sequence with the parameter if_exists' do
|
192
|
+
with_migration do
|
193
|
+
def up
|
194
|
+
create_sequence :position
|
195
|
+
end
|
196
|
+
end.up
|
197
|
+
|
198
|
+
sequence = MysqlDB.check_sequences.find_all do |seq|
|
199
|
+
seq[:name] == 'position'
|
200
|
+
end
|
201
|
+
|
202
|
+
assert_equal 1, sequence.size
|
203
|
+
|
204
|
+
with_migration do
|
205
|
+
def down
|
206
|
+
drop_sequence :position, if_exists: true
|
207
|
+
end
|
208
|
+
end.down
|
209
|
+
|
210
|
+
sequence = MysqlDB.check_sequences.find do |seq|
|
211
|
+
seq[:name] == 'position'
|
130
212
|
end
|
131
213
|
|
132
214
|
assert_nil sequence
|
133
215
|
end
|
134
216
|
|
135
217
|
test 'orders sequences' do
|
136
|
-
list = MysqlDB.check_sequences.map { |s| s[:
|
218
|
+
list = MysqlDB.check_sequences.map { |s| s[:name] }
|
137
219
|
assert !list.include?('a')
|
138
220
|
assert !list.include?('b')
|
139
221
|
assert !list.include?('c')
|
@@ -141,42 +223,133 @@ class MysqlSequenceTest < Minitest::Test
|
|
141
223
|
with_migration do
|
142
224
|
def up
|
143
225
|
drop_table :things, if_exists: true
|
144
|
-
create_sequence :c
|
145
|
-
create_sequence :a
|
226
|
+
create_sequence :c, { start: 1 }
|
227
|
+
create_sequence :a, { start: 3 }
|
146
228
|
create_sequence :b
|
147
229
|
end
|
148
230
|
end.up
|
149
231
|
|
150
|
-
list = MysqlDB.check_sequences.map { |s| s[:
|
232
|
+
list = MysqlDB.check_sequences.map { |s| s[:name] }
|
151
233
|
assert list.include?('a')
|
152
234
|
assert list.include?('b')
|
153
235
|
assert list.include?('c')
|
154
236
|
end
|
155
237
|
|
238
|
+
test 'checks custom sequence generated from code' do
|
239
|
+
assert_equal MysqlDB.custom_sequence?(:c), false
|
240
|
+
|
241
|
+
with_migration do
|
242
|
+
def up
|
243
|
+
create_sequence :c
|
244
|
+
end
|
245
|
+
end.up
|
246
|
+
|
247
|
+
assert_equal MysqlDB.custom_sequence?(:c), true
|
248
|
+
end
|
249
|
+
|
250
|
+
test 'recreates the same sequence with the same start value' do
|
251
|
+
with_migration do
|
252
|
+
def up
|
253
|
+
create_sequence :position_id, if_exists: false, start: 1
|
254
|
+
end
|
255
|
+
end.up
|
256
|
+
|
257
|
+
assert_equal 1, MysqlDB.currval(:position_id)
|
258
|
+
|
259
|
+
fiction_set_size = MysqlDB.fetch('SELECT * FROM position_id where fiction = 0;').all.size
|
260
|
+
assert_equal 1, fiction_set_size
|
261
|
+
|
262
|
+
with_migration do
|
263
|
+
def up
|
264
|
+
create_sequence :position_id, if_exists: false, start: 1
|
265
|
+
end
|
266
|
+
end.up
|
267
|
+
|
268
|
+
assert_equal 1, MysqlDB.currval(:position_id)
|
269
|
+
|
270
|
+
fiction_set_size = MysqlDB.fetch('SELECT * FROM position_id where fiction = 0;').all.size
|
271
|
+
assert_equal 1, fiction_set_size
|
272
|
+
end
|
273
|
+
|
274
|
+
test 'recreates the same sequence with a smaller start value' do
|
275
|
+
with_migration do
|
276
|
+
def up
|
277
|
+
create_sequence :position_id, if_exists: false, start: 100
|
278
|
+
end
|
279
|
+
end.up
|
280
|
+
|
281
|
+
assert_equal 100, MysqlDB.currval(:position_id)
|
282
|
+
|
283
|
+
fiction_set_size = MysqlDB.fetch('SELECT * FROM position_id where fiction = 0;').all.size
|
284
|
+
assert_equal 1, fiction_set_size
|
285
|
+
|
286
|
+
with_migration do
|
287
|
+
def up
|
288
|
+
create_sequence :position_id, if_exists: false, start: 1
|
289
|
+
end
|
290
|
+
end.up
|
291
|
+
|
292
|
+
assert_equal 100, MysqlDB.currval(:position_id)
|
293
|
+
|
294
|
+
fiction_set_size = MysqlDB.fetch('SELECT * FROM position_id where fiction = 0;').all.size
|
295
|
+
assert_equal 1, fiction_set_size
|
296
|
+
end
|
297
|
+
|
298
|
+
test 'recreates the same sequence with a greater start value' do
|
299
|
+
with_migration do
|
300
|
+
def up
|
301
|
+
create_sequence :position_id, if_exists: false, start: 1
|
302
|
+
end
|
303
|
+
end.up
|
304
|
+
|
305
|
+
assert_equal 1, MysqlDB.currval(:position_id)
|
306
|
+
|
307
|
+
fiction_set_size = MysqlDB.fetch('SELECT * FROM position_id where fiction = 0;').all.size
|
308
|
+
assert_equal 1, fiction_set_size
|
309
|
+
|
310
|
+
with_migration do
|
311
|
+
def up
|
312
|
+
create_sequence :position_id, if_exists: false, start: 100
|
313
|
+
end
|
314
|
+
end.up
|
315
|
+
|
316
|
+
assert_equal 100, MysqlDB.currval(:position_id)
|
317
|
+
|
318
|
+
fiction_set_size = MysqlDB.fetch('SELECT * FROM position_id where fiction = 0;').all.size
|
319
|
+
assert_equal 2, fiction_set_size
|
320
|
+
end
|
321
|
+
|
156
322
|
test 'creates table that references sequence' do
|
157
323
|
with_migration do
|
158
324
|
def up
|
159
|
-
drop_table :builders, if_exists: true
|
160
325
|
create_sequence :position_id, if_exists: false, start: 1
|
161
|
-
create_table :
|
326
|
+
create_table :creators do
|
162
327
|
primary_key :id
|
163
328
|
String :name, text: true
|
164
|
-
Bignum :position
|
329
|
+
Bignum :position
|
165
330
|
end
|
166
|
-
set_column_default_nextval :
|
331
|
+
set_column_default_nextval :creators, :position, :position_id
|
167
332
|
end
|
168
333
|
end.up
|
169
334
|
|
170
|
-
class
|
335
|
+
class Creator < Sequel::Model; end
|
171
336
|
|
172
|
-
|
173
|
-
pos1 = MysqlDB.
|
174
|
-
assert_equal pos1,
|
337
|
+
creator1 = Creator.create(name: 'Creator 1')
|
338
|
+
pos1 = MysqlDB.lastval(:position_id)
|
339
|
+
assert_equal pos1, creator1.reload.position
|
175
340
|
|
176
|
-
|
341
|
+
creator2 = Creator.create(name: 'Creator 2')
|
177
342
|
pos2 = MysqlDB.currval(:position_id)
|
178
|
-
assert_equal pos2,
|
343
|
+
assert_equal pos2, creator2.reload.position
|
179
344
|
|
180
345
|
assert_equal pos2 - pos1, 1
|
346
|
+
|
347
|
+
MysqlDB.nextval(:position_id)
|
348
|
+
|
349
|
+
creator4 = Creator.create(name: 'Creator 4')
|
350
|
+
pos4 = MysqlDB.currval(:position_id)
|
351
|
+
assert_equal pos4, creator4.reload.position
|
352
|
+
|
353
|
+
assert_equal pos4 - pos2, 2
|
181
354
|
end
|
182
355
|
end
|
@@ -12,7 +12,7 @@ class SqliteSequenceTest < Minitest::Test
|
|
12
12
|
test 'adds sequence with default values' do
|
13
13
|
with_migration do
|
14
14
|
def up
|
15
|
-
# create_sequence :position, {start: 1, increment: 1} - default values
|
15
|
+
# create_sequence :position, {start: 1, increment: 1, numeric_label: 0} - default values
|
16
16
|
create_sequence :position
|
17
17
|
end
|
18
18
|
end.up
|
@@ -126,8 +126,7 @@ class SqliteSequenceTest < Minitest::Test
|
|
126
126
|
SQLiteDB.setval(:position, 1)
|
127
127
|
assert_equal 101, SQLiteDB.lastval(:position)
|
128
128
|
|
129
|
-
SQLiteDB.nextval(:position)
|
130
|
-
assert_equal 102, SQLiteDB.lastval(:position)
|
129
|
+
assert_equal 102, SQLiteDB.nextval(:position)
|
131
130
|
end
|
132
131
|
|
133
132
|
test 'sets a new sequence value with a label' do
|
@@ -143,8 +142,9 @@ class SqliteSequenceTest < Minitest::Test
|
|
143
142
|
fiction_set_size = SQLiteDB.fetch('SELECT * FROM position where fiction = 1;').all.size
|
144
143
|
assert_equal 2, fiction_set_size
|
145
144
|
|
145
|
+
# create_sequence + nextval
|
146
146
|
fiction_set_size = SQLiteDB.fetch('SELECT * FROM position where fiction = 0;').all.size
|
147
|
-
assert_equal
|
147
|
+
assert_equal 2, fiction_set_size
|
148
148
|
end
|
149
149
|
|
150
150
|
test 'drops the sequence and the check_sequences' do
|
@@ -173,7 +173,7 @@ class SqliteSequenceTest < Minitest::Test
|
|
173
173
|
assert_nil sequence
|
174
174
|
end
|
175
175
|
|
176
|
-
test '
|
176
|
+
test 'drops the sequence with the parameter if_exists' do
|
177
177
|
with_migration do
|
178
178
|
def up
|
179
179
|
create_sequence :position
|
@@ -220,6 +220,78 @@ class SqliteSequenceTest < Minitest::Test
|
|
220
220
|
assert list.include?('c')
|
221
221
|
end
|
222
222
|
|
223
|
+
test 'recreates the same sequence with the same start value' do
|
224
|
+
with_migration do
|
225
|
+
def up
|
226
|
+
create_sequence :position_id, if_exists: false, start: 1
|
227
|
+
end
|
228
|
+
end.up
|
229
|
+
|
230
|
+
assert_equal 1, SQLiteDB.currval(:position_id)
|
231
|
+
|
232
|
+
fiction_set_size = SQLiteDB.fetch('SELECT * FROM position_id where fiction = 0;').all.size
|
233
|
+
assert_equal 1, fiction_set_size
|
234
|
+
|
235
|
+
with_migration do
|
236
|
+
def up
|
237
|
+
create_sequence :position_id, if_exists: false, start: 1
|
238
|
+
end
|
239
|
+
end.up
|
240
|
+
|
241
|
+
assert_equal 1, SQLiteDB.currval(:position_id)
|
242
|
+
|
243
|
+
fiction_set_size = SQLiteDB.fetch('SELECT * FROM position_id where fiction = 0;').all.size
|
244
|
+
assert_equal 1, fiction_set_size
|
245
|
+
end
|
246
|
+
|
247
|
+
test 'recreates the same sequence with a smaller start value' do
|
248
|
+
with_migration do
|
249
|
+
def up
|
250
|
+
create_sequence :position_id, if_exists: false, start: 100
|
251
|
+
end
|
252
|
+
end.up
|
253
|
+
|
254
|
+
assert_equal 100, SQLiteDB.currval(:position_id)
|
255
|
+
|
256
|
+
fiction_set_size = SQLiteDB.fetch('SELECT * FROM position_id where fiction = 0;').all.size
|
257
|
+
assert_equal 1, fiction_set_size
|
258
|
+
|
259
|
+
with_migration do
|
260
|
+
def up
|
261
|
+
create_sequence :position_id, if_exists: false, start: 1
|
262
|
+
end
|
263
|
+
end.up
|
264
|
+
|
265
|
+
assert_equal 100, SQLiteDB.currval(:position_id)
|
266
|
+
|
267
|
+
fiction_set_size = SQLiteDB.fetch('SELECT * FROM position_id where fiction = 0;').all.size
|
268
|
+
assert_equal 1, fiction_set_size
|
269
|
+
end
|
270
|
+
|
271
|
+
test 'recreates the same sequence with a greater start value' do
|
272
|
+
with_migration do
|
273
|
+
def up
|
274
|
+
create_sequence :position_id, if_exists: false, start: 1
|
275
|
+
end
|
276
|
+
end.up
|
277
|
+
|
278
|
+
assert_equal 1, SQLiteDB.currval(:position_id)
|
279
|
+
|
280
|
+
fiction_set_size = SQLiteDB.fetch('SELECT * FROM position_id where fiction = 0;').all.size
|
281
|
+
assert_equal 1, fiction_set_size
|
282
|
+
|
283
|
+
with_migration do
|
284
|
+
def up
|
285
|
+
create_sequence :position_id, if_exists: false, start: 100
|
286
|
+
end
|
287
|
+
end.up
|
288
|
+
|
289
|
+
assert_equal 100, SQLiteDB.currval(:position_id)
|
290
|
+
|
291
|
+
fiction_set_size = SQLiteDB.fetch('SELECT * FROM position_id where fiction = 0;').all.size
|
292
|
+
assert_equal 2, fiction_set_size
|
293
|
+
end
|
294
|
+
|
223
295
|
test 'creates table that references sequence' do
|
224
296
|
with_migration do
|
225
297
|
def up
|
data/test/sqlite_test_helper.rb
CHANGED
@@ -10,7 +10,8 @@ SQLiteDB = Sequel.connect(
|
|
10
10
|
|
11
11
|
module SqliteTestHelper
|
12
12
|
def recreate_table
|
13
|
-
SQLiteDB.drop_sequence
|
13
|
+
SQLiteDB.drop_sequence :position
|
14
|
+
SQLiteDB.drop_sequence :position_id, if_exists: true
|
14
15
|
SQLiteDB.run 'DROP TABLE IF EXISTS objects'
|
15
16
|
SQLiteDB.drop_sequence 'a'
|
16
17
|
SQLiteDB.drop_sequence 'b'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel-sequence
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nikolai Bocharov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-09-
|
11
|
+
date: 2023-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|
@@ -158,7 +158,8 @@ dependencies:
|
|
158
158
|
version: 1.6.0
|
159
159
|
description: |2
|
160
160
|
This gem provides a single interface for SEQUENCE functionality
|
161
|
-
in Postgresql and
|
161
|
+
in Postgresql and MariaDB DBMS within the Sequel ORM.
|
162
|
+
It also models the Sequences to meet the needs of SQLite and MySQL users.
|
162
163
|
email:
|
163
164
|
- it.architect@yahoo.com
|
164
165
|
executables: []
|
@@ -185,14 +186,17 @@ files:
|
|
185
186
|
- lib/sequel/error.rb
|
186
187
|
- lib/sequel/sequence.rb
|
187
188
|
- lib/sequel/sequence/database.rb
|
188
|
-
- lib/sequel/sequence/database/mysql.rb
|
189
|
-
- lib/sequel/sequence/database/mysql2.rb
|
190
189
|
- lib/sequel/sequence/database/postgresql.rb
|
190
|
+
- lib/sequel/sequence/database/server/mariadb.rb
|
191
|
+
- lib/sequel/sequence/database/server/mysql.rb
|
191
192
|
- lib/sequel/sequence/database/sqlite.rb
|
193
|
+
- lib/sequel/sequence/database_ext_connection.rb
|
192
194
|
- lib/sequel/sequence/version.rb
|
193
195
|
- sequel-sequence.gemspec
|
196
|
+
- test/mariadb_test_helper.rb
|
194
197
|
- test/mysql_test_helper.rb
|
195
198
|
- test/postgresql_test_helper.rb
|
199
|
+
- test/sequel/mariadb_sequence_test.rb
|
196
200
|
- test/sequel/mysql_sequence_test.rb
|
197
201
|
- test/sequel/postgresql_sequence_test.rb
|
198
202
|
- test/sequel/sqlite_sequence_test.rb
|
@@ -223,5 +227,6 @@ requirements: []
|
|
223
227
|
rubygems_version: 3.4.19
|
224
228
|
signing_key:
|
225
229
|
specification_version: 4
|
226
|
-
summary:
|
230
|
+
summary: Adds SEQUENCE support to Sequel for migrations to PostgreSQL, MariaDB, MySQL
|
231
|
+
and SQLite.
|
227
232
|
test_files: []
|
@@ -1,81 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# https://sequel.jeremyevans.net/rdoc/files/doc/sql_rdoc.html
|
4
|
-
# https://github.com/jeremyevans/sequel/blob/master/lib/sequel/database/connecting.rb
|
5
|
-
module Sequel
|
6
|
-
module Sequence
|
7
|
-
module Database
|
8
|
-
module Mysql2
|
9
|
-
def quote_column_name(name)
|
10
|
-
"`#{name.gsub('`', '``')}`"
|
11
|
-
end
|
12
|
-
|
13
|
-
def quote_sequence_name(name)
|
14
|
-
"`#{name.gsub(/[`"']/, '')}`"
|
15
|
-
end
|
16
|
-
|
17
|
-
def check_sequences
|
18
|
-
fetch("SHOW FULL TABLES WHERE Table_type = 'SEQUENCE';").all.to_a
|
19
|
-
end
|
20
|
-
|
21
|
-
def create_sequence(name, options = {})
|
22
|
-
increment = options[:increment] || options[:step]
|
23
|
-
if_exists = build_exists_condition(options[:if_exists])
|
24
|
-
name = quote_name(name.to_s)
|
25
|
-
|
26
|
-
sql = ["CREATE SEQUENCE #{if_exists} #{name}"]
|
27
|
-
sql << "INCREMENT BY #{increment}" if increment
|
28
|
-
sql << "START WITH #{options[:start]}" if options[:start]
|
29
|
-
sql << ';'
|
30
|
-
|
31
|
-
run(sql.join("\n"))
|
32
|
-
end
|
33
|
-
|
34
|
-
def drop_sequence(name)
|
35
|
-
name = quote_name(name.to_s)
|
36
|
-
sql = "DROP SEQUENCE IF EXISTS #{name}"
|
37
|
-
run(sql)
|
38
|
-
end
|
39
|
-
|
40
|
-
def nextval(name)
|
41
|
-
name = quote(name.to_s)
|
42
|
-
out = nil
|
43
|
-
fetch("SELECT nextval(#{name});") do |row|
|
44
|
-
out = row["nextval(#{name})".to_sym]
|
45
|
-
end
|
46
|
-
out
|
47
|
-
end
|
48
|
-
|
49
|
-
# for db.database_type = :mysql2
|
50
|
-
def lastval(name)
|
51
|
-
name = quote(name.to_s)
|
52
|
-
out = nil
|
53
|
-
fetch("SELECT lastval(#{name});") do |row|
|
54
|
-
out = row["lastval(#{name})".to_sym]
|
55
|
-
end
|
56
|
-
out
|
57
|
-
end
|
58
|
-
|
59
|
-
# for db.database_type = :postgres
|
60
|
-
alias currval lastval
|
61
|
-
|
62
|
-
def setval(name, value)
|
63
|
-
name = quote(name.to_s)
|
64
|
-
out = nil
|
65
|
-
fetch("SELECT setval(#{name}, #{value});") do |row|
|
66
|
-
out = row["setval(#{name}, #{value})".to_sym]
|
67
|
-
end
|
68
|
-
out
|
69
|
-
end
|
70
|
-
|
71
|
-
def set_column_default_nextval(table, column, sequence)
|
72
|
-
table = table.to_s
|
73
|
-
column = column.to_s
|
74
|
-
sequence = quote(sequence.to_s)
|
75
|
-
run "ALTER TABLE IF EXISTS #{table} " \
|
76
|
-
"ALTER COLUMN #{column} SET DEFAULT nextval(#{sequence});"
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|