sequel-sequence 0.4.0 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ci.gemfile +25 -0
- data/.github/workflows/ci.yml +4 -2
- data/CHANGELOG.md +18 -0
- data/CONTRIBUTING.md +16 -5
- data/README.md +19 -4
- data/Rakefile +26 -1
- data/lib/sequel/error.rb +6 -6
- data/lib/sequel/sequence/database/postgresql.rb +17 -7
- data/lib/sequel/sequence/database/server/mariadb.rb +89 -56
- data/lib/sequel/sequence/database/server/mysql.rb +179 -172
- data/lib/sequel/sequence/database/sqlite.rb +16 -24
- data/lib/sequel/sequence/database.rb +10 -10
- data/lib/sequel/sequence/database_ext_connection.rb +7 -3
- data/lib/sequel/sequence/version.rb +1 -1
- data/lib/sequel/sequence.rb +46 -14
- data/sequel-sequence.gemspec +13 -13
- data/test/mariadb_test_helper.rb +2 -0
- data/test/mock_test_helper.rb +5 -0
- data/test/mysql_test_helper.rb +5 -0
- data/test/postgresql_test_helper.rb +3 -1
- data/test/sequel/mariadb_sequence_test.rb +67 -16
- data/test/sequel/mock_sequence_test.rb +100 -0
- data/test/sequel/mysql_sequence_test.rb +58 -16
- data/test/sequel/postgresql_sequence_test.rb +58 -6
- data/test/sequel/sqlite_sequence_test.rb +51 -11
- data/test/sqlite_test_helper.rb +8 -1
- data/test/test_helper.rb +1 -0
- metadata +8 -47
@@ -1,178 +1,185 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
3
|
+
module Sequel
|
4
|
+
module Sequence
|
5
|
+
module Database
|
6
|
+
module Server
|
7
|
+
module Mysql
|
8
|
+
def check_sequences
|
9
|
+
fetch('SELECT * FROM mysql_sequence;').all.to_a
|
10
|
+
end
|
11
|
+
|
12
|
+
def custom_sequence?(sequence_name)
|
13
|
+
table_matcher do
|
14
|
+
out = nil
|
15
|
+
fetch(select_from_mysql_sequence_where(stringify(sequence_name))) do |row|
|
16
|
+
out = row[:name]
|
17
|
+
end
|
18
|
+
!out.nil?
|
19
|
+
end || false
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_sequence(name, options = {})
|
23
|
+
check_options(options)
|
24
|
+
if_exists = build_exists_condition(options[:if_exists])
|
25
|
+
start_option = options[:start] || 1
|
26
|
+
num_label = options[:numeric_label] || 0
|
27
|
+
return if (current = lastval(name)) && (current >= start_option)
|
28
|
+
|
29
|
+
run create_sequence_table(stringify(name), if_exists)
|
30
|
+
run insert_into_sequence_table_init_values(stringify(name), start_option, num_label)
|
31
|
+
run create_mysql_sequence
|
32
|
+
table_matcher { run delete_from_mysql_sequence(stringify(name)) }
|
33
|
+
run insert_into_mysql_sequence(stringify(name), start_option)
|
34
|
+
end
|
35
|
+
|
36
|
+
def drop_sequence(name, options = {})
|
37
|
+
if_exists = build_exists_condition(options[:if_exists])
|
38
|
+
run drop_sequence_table(stringify(name), if_exists)
|
39
|
+
table_matcher { run delete_from_mysql_sequence(stringify(name)) }
|
40
|
+
end
|
41
|
+
|
42
|
+
def nextval(name)
|
43
|
+
run insert_into_sequence_table(stringify(name), 0)
|
44
|
+
table_matcher { run delete_from_mysql_sequence(stringify(name)) }
|
45
|
+
run insert_last_insert_id_into_mysql_sequence(stringify(name))
|
46
|
+
take_seq(stringify(name))
|
47
|
+
end
|
48
|
+
|
49
|
+
def nextval_with_label(name, num_label = 0)
|
50
|
+
run insert_into_sequence_table(stringify(name), num_label)
|
51
|
+
table_matcher { run delete_from_mysql_sequence(stringify(name)) }
|
52
|
+
run insert_last_insert_id_into_mysql_sequence(stringify(name))
|
53
|
+
take_seq(stringify(name))
|
54
|
+
end
|
55
|
+
|
56
|
+
def lastval(name)
|
57
|
+
take_seq(stringify(name))
|
58
|
+
end
|
59
|
+
|
60
|
+
alias currval lastval
|
61
|
+
|
62
|
+
def setval(name, value)
|
63
|
+
current = lastval(name)
|
64
|
+
if current.nil?
|
65
|
+
create_sequence(stringify(name), { start: value })
|
66
|
+
elsif value < current
|
67
|
+
log_info Sequel::Database::DANGER_OPT_ID
|
68
|
+
value = current
|
69
|
+
elsif value > current
|
70
|
+
run insert_into_sequence_table_init_values(stringify(name), value, 0)
|
71
|
+
table_matcher { run delete_from_mysql_sequence(stringify(name)) }
|
72
|
+
run insert_into_mysql_sequence(stringify(name), value)
|
73
|
+
end
|
74
|
+
value
|
75
|
+
end
|
76
|
+
|
77
|
+
def set_column_default_nextval(table, column, sequence)
|
78
|
+
run create_sequenced_column(stringify(table),
|
79
|
+
stringify(column),
|
80
|
+
stringify(sequence))
|
81
|
+
run update_sequenced_column(stringify(table),
|
82
|
+
stringify(column),
|
83
|
+
stringify(sequence))
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def stringify(name)
|
89
|
+
@name ||= {}
|
90
|
+
@name.fetch(name, nil) || (@name[name] = name.to_s)
|
91
|
+
end
|
92
|
+
|
93
|
+
def select_from_mysql_sequence_where(name)
|
94
|
+
"SELECT * FROM mysql_sequence where name = '#{name}';"
|
95
|
+
end
|
96
|
+
|
97
|
+
def create_sequence_table(name, if_exists = nil)
|
98
|
+
%(
|
99
|
+
CREATE TABLE #{if_exists || Sequel::Database::IF_NOT_EXISTS} #{name}
|
100
|
+
(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
101
|
+
fiction INT);
|
102
|
+
).strip
|
103
|
+
end
|
104
|
+
|
105
|
+
def insert_into_sequence_table_init_values(name, start_id, num_label)
|
106
|
+
"INSERT INTO #{name} (id, fiction) VALUES (#{start_id}, #{num_label});"
|
107
|
+
end
|
108
|
+
|
109
|
+
def create_mysql_sequence
|
110
|
+
%(
|
111
|
+
CREATE TABLE #{Sequel::Database::IF_NOT_EXISTS} mysql_sequence
|
112
|
+
(name VARCHAR(40), seq INT);
|
113
|
+
).strip
|
114
|
+
end
|
115
|
+
|
116
|
+
def select_max_seq(name)
|
117
|
+
"SELECT MAX(seq) AS id FROM mysql_sequence WHERE name = '#{name}';"
|
118
|
+
end
|
119
|
+
|
120
|
+
def take_seq(name)
|
121
|
+
table_matcher do
|
122
|
+
out = nil
|
123
|
+
fetch(select_max_seq(name)) do |row|
|
124
|
+
out = row[:id]
|
125
|
+
end
|
126
|
+
out
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def delete_from_mysql_sequence(name)
|
131
|
+
"DELETE QUICK IGNORE FROM mysql_sequence WHERE name = '#{name}';"
|
132
|
+
end
|
133
|
+
|
134
|
+
def insert_into_mysql_sequence(name, value)
|
135
|
+
"INSERT INTO mysql_sequence (name, seq) VALUES ('#{name}', #{value});"
|
136
|
+
end
|
137
|
+
|
138
|
+
def drop_sequence_table(name, if_exists = nil)
|
139
|
+
"DROP TABLE #{if_exists || Sequel::Database::IF_EXISTS} #{name};"
|
140
|
+
end
|
141
|
+
|
142
|
+
def insert_into_sequence_table(name, num_label)
|
143
|
+
"INSERT INTO #{name} (fiction) VALUES (#{num_label});"
|
144
|
+
end
|
145
|
+
|
146
|
+
def insert_last_insert_id_into_mysql_sequence(name)
|
147
|
+
"INSERT INTO mysql_sequence (name, seq) VALUES ('#{name}', LAST_INSERT_ID());"
|
148
|
+
end
|
149
|
+
|
150
|
+
def create_sequenced_column(table, _column, sequence)
|
151
|
+
%(
|
152
|
+
CREATE TRIGGER IF NOT EXISTS #{table}_#{sequence} BEFORE INSERT
|
153
|
+
ON #{table}
|
154
|
+
FOR EACH ROW BEGIN
|
155
|
+
DELETE QUICK IGNORE FROM mysql_sequence WHERE name = '#{sequence}';
|
156
|
+
INSERT INTO #{sequence} SET fiction = 0;
|
157
|
+
INSERT INTO mysql_sequence SET name = '#{sequence}', seq = LAST_INSERT_ID();
|
158
|
+
|
159
|
+
END;
|
160
|
+
).strip
|
161
|
+
end
|
162
|
+
|
163
|
+
def update_sequenced_column(table, column, sequence)
|
164
|
+
%(
|
165
|
+
CREATE TRIGGER IF NOT EXISTS #{table}_#{column} BEFORE INSERT
|
166
|
+
ON #{table}
|
167
|
+
FOR EACH ROW FOLLOWS #{table}_#{sequence}
|
168
|
+
SET NEW.#{column} = ( SELECT MAX(seq) FROM mysql_sequence WHERE name = '#{sequence}' );
|
169
|
+
).strip
|
170
|
+
end
|
171
|
+
|
172
|
+
def table_matcher(&block)
|
173
|
+
block.call
|
174
|
+
rescue Sequel::DatabaseError => e
|
175
|
+
return if e.message =~ /\AMysql2::Error: Table(.)*doesn't exist\z/
|
176
|
+
|
177
|
+
# :nocov:
|
178
|
+
raise e
|
179
|
+
# :nocov:
|
180
|
+
end
|
181
|
+
end
|
124
182
|
end
|
125
|
-
out
|
126
183
|
end
|
127
184
|
end
|
128
|
-
|
129
|
-
def delete_from_mysql_sequence(name)
|
130
|
-
"DELETE QUICK IGNORE FROM mysql_sequence WHERE name = '#{name}';"
|
131
|
-
end
|
132
|
-
|
133
|
-
def insert_into_mysql_sequence(name, value)
|
134
|
-
"INSERT INTO mysql_sequence (name, seq) VALUES ('#{name}', #{value});"
|
135
|
-
end
|
136
|
-
|
137
|
-
def drop_sequence_table(name, if_exists = nil)
|
138
|
-
"DROP TABLE #{if_exists || Sequel::Database::IF_EXISTS} #{name};"
|
139
|
-
end
|
140
|
-
|
141
|
-
def insert_into_sequence_table(name, num_label)
|
142
|
-
"INSERT INTO #{name} (fiction) VALUES (#{num_label});"
|
143
|
-
end
|
144
|
-
|
145
|
-
def insert_last_insert_id_into_mysql_sequence(name)
|
146
|
-
"INSERT INTO mysql_sequence (name, seq) VALUES ('#{name}', LAST_INSERT_ID());"
|
147
|
-
end
|
148
|
-
|
149
|
-
def create_sequenced_column(table, _column, sequence)
|
150
|
-
%(
|
151
|
-
CREATE TRIGGER IF NOT EXISTS #{table}_#{sequence} BEFORE INSERT
|
152
|
-
ON #{table}
|
153
|
-
FOR EACH ROW BEGIN
|
154
|
-
DELETE QUICK IGNORE FROM mysql_sequence WHERE name = '#{sequence}';
|
155
|
-
INSERT INTO #{sequence} SET fiction = 0;
|
156
|
-
INSERT INTO mysql_sequence SET name = '#{sequence}', seq = LAST_INSERT_ID();
|
157
|
-
|
158
|
-
END;
|
159
|
-
).strip
|
160
|
-
end
|
161
|
-
|
162
|
-
def update_sequenced_column(table, column, sequence)
|
163
|
-
%(
|
164
|
-
CREATE TRIGGER IF NOT EXISTS #{table}_#{column} BEFORE INSERT
|
165
|
-
ON #{table}
|
166
|
-
FOR EACH ROW FOLLOWS #{table}_#{sequence}
|
167
|
-
SET NEW.#{column} = ( SELECT MAX(seq) FROM mysql_sequence WHERE name = '#{sequence}' );
|
168
|
-
).strip
|
169
|
-
end
|
170
|
-
|
171
|
-
def table_matcher(&block)
|
172
|
-
block.call
|
173
|
-
rescue Sequel::DatabaseError => e
|
174
|
-
return if e.message =~ /\AMysql2::Error: Table(.)*doesn't exist\z/
|
175
|
-
|
176
|
-
raise e
|
177
|
-
end
|
178
185
|
end
|
@@ -6,6 +6,11 @@ module Sequel
|
|
6
6
|
module Sequence
|
7
7
|
module Database
|
8
8
|
module SQLite
|
9
|
+
def custom_sequence?(sequence_name)
|
10
|
+
sql = "SELECT * FROM `sqlite_sequence` WHERE name = '#{stringify(sequence_name)}';"
|
11
|
+
fetch(sql).all.size.positive?
|
12
|
+
end
|
13
|
+
|
9
14
|
def check_sequences
|
10
15
|
fetch('SELECT * FROM `sqlite_sequence`;').all.to_a
|
11
16
|
end
|
@@ -44,18 +49,14 @@ module Sequel
|
|
44
49
|
alias currval lastval
|
45
50
|
|
46
51
|
def setval(name, value)
|
47
|
-
current = lastval(
|
52
|
+
current = lastval(name)
|
48
53
|
if current.nil?
|
49
54
|
create_sequence(stringify(name), { start: value })
|
50
55
|
elsif value < current
|
51
|
-
|
52
|
-
# sql << drop_sequence_table(name)
|
53
|
-
# sql << insert_into_sqlite_sequence(name, value)
|
54
|
-
# run(sql.join("\n"))
|
55
|
-
log_info DANGER_OPT_ID
|
56
|
+
log_info Sequel::Database::DANGER_OPT_ID
|
56
57
|
value = current
|
57
58
|
else
|
58
|
-
run(
|
59
|
+
run(update_sqlite_sequence(stringify(name), value))
|
59
60
|
end
|
60
61
|
value
|
61
62
|
end
|
@@ -83,7 +84,7 @@ module Sequel
|
|
83
84
|
|
84
85
|
def create_sequence_table(name, if_exists = nil)
|
85
86
|
%(
|
86
|
-
CREATE TABLE #{if_exists || IF_NOT_EXISTS} #{name}
|
87
|
+
CREATE TABLE #{if_exists || Sequel::Database::IF_NOT_EXISTS} #{name}
|
87
88
|
(id integer primary key autoincrement, fiction integer);
|
88
89
|
)
|
89
90
|
end
|
@@ -96,25 +97,16 @@ module Sequel
|
|
96
97
|
"INSERT INTO #{name} (fiction) VALUES (#{num_label});"
|
97
98
|
end
|
98
99
|
|
99
|
-
def
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
UPDATE sqlite_sequence
|
106
|
-
SET seq = #{[current, value].max}
|
107
|
-
WHERE name = '#{name}';
|
108
|
-
)
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
def delete_from_sqlite_sequence(name)
|
113
|
-
"DELETE FROM sqlite_sequence WHERE name = '#{name}';"
|
100
|
+
def update_sqlite_sequence(name, value)
|
101
|
+
%(
|
102
|
+
UPDATE sqlite_sequence
|
103
|
+
SET seq = #{value}
|
104
|
+
WHERE name = '#{name}';
|
105
|
+
)
|
114
106
|
end
|
115
107
|
|
116
108
|
def drop_sequence_table(name, if_exists = nil)
|
117
|
-
"DROP TABLE #{if_exists || IF_EXISTS} #{name};"
|
109
|
+
"DROP TABLE #{if_exists || Sequel::Database::IF_EXISTS} #{name};"
|
118
110
|
end
|
119
111
|
|
120
112
|
def select_max_seq(name)
|
@@ -14,24 +14,24 @@ module Sequel
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def custom_sequence?(_sequence_name)
|
17
|
-
raise Sequel::MethodNotAllowed, Sequel::
|
17
|
+
raise Sequel::MethodNotAllowed, Sequel::Database::METHOD_NOT_ALLOWED
|
18
18
|
end
|
19
19
|
|
20
20
|
def check_sequences
|
21
|
-
raise Sequel::MethodNotAllowed, Sequel::
|
21
|
+
raise Sequel::MethodNotAllowed, Sequel::Database::METHOD_NOT_ALLOWED
|
22
22
|
end
|
23
23
|
|
24
24
|
def create_sequence(_name, _options = {})
|
25
|
-
raise Sequel::MethodNotAllowed, Sequel::
|
25
|
+
raise Sequel::MethodNotAllowed, Sequel::Database::METHOD_NOT_ALLOWED
|
26
26
|
end
|
27
27
|
|
28
28
|
def drop_sequence(_name, _options = {})
|
29
|
-
raise Sequel::MethodNotAllowed, Sequel::
|
29
|
+
raise Sequel::MethodNotAllowed, Sequel::Database::METHOD_NOT_ALLOWED
|
30
30
|
end
|
31
31
|
|
32
32
|
def quote_name(name)
|
33
33
|
unless respond_to?(:quote_column_name, false)
|
34
|
-
raise Sequel::MethodNotAllowed, Sequel::
|
34
|
+
raise Sequel::MethodNotAllowed, Sequel::Database::METHOD_NOT_ALLOWED
|
35
35
|
end
|
36
36
|
|
37
37
|
name.to_s.split('.', 2).map { |part| quote_column_name(part) }.join('.')
|
@@ -39,30 +39,30 @@ module Sequel
|
|
39
39
|
|
40
40
|
def quote(name)
|
41
41
|
unless respond_to?(:quote_sequence_name, false)
|
42
|
-
raise Sequel::MethodNotAllowed, Sequel::
|
42
|
+
raise Sequel::MethodNotAllowed, Sequel::Database::METHOD_NOT_ALLOWED
|
43
43
|
end
|
44
44
|
|
45
45
|
name.to_s.split('.', 2).map { |part| quote_sequence_name(part) }.join('.')
|
46
46
|
end
|
47
47
|
|
48
48
|
def nextval_with_label(_name, _num_label = 0)
|
49
|
-
raise Sequel::MethodNotAllowed, Sequel::
|
49
|
+
raise Sequel::MethodNotAllowed, Sequel::Database::METHOD_NOT_ALLOWED
|
50
50
|
end
|
51
51
|
|
52
52
|
def nextval(_name)
|
53
|
-
raise Sequel::MethodNotAllowed, Sequel::
|
53
|
+
raise Sequel::MethodNotAllowed, Sequel::Database::METHOD_NOT_ALLOWED
|
54
54
|
end
|
55
55
|
|
56
56
|
# for Postgres
|
57
57
|
def currval(_name)
|
58
|
-
raise Sequel::MethodNotAllowed, Sequel::
|
58
|
+
raise Sequel::MethodNotAllowed, Sequel::Database::METHOD_NOT_ALLOWED
|
59
59
|
end
|
60
60
|
|
61
61
|
# for MariaDB
|
62
62
|
alias lastval currval
|
63
63
|
|
64
64
|
def setval(_name, _value)
|
65
|
-
raise Sequel::MethodNotAllowed, Sequel::
|
65
|
+
raise Sequel::MethodNotAllowed, Sequel::Database::METHOD_NOT_ALLOWED
|
66
66
|
end
|
67
67
|
|
68
68
|
def build_exists_condition(option)
|
@@ -14,9 +14,13 @@ module Sequel
|
|
14
14
|
define_singleton_method(:connect) do |*args|
|
15
15
|
db = old_connect.call(*args)
|
16
16
|
if db.adapter_scheme == :mysql2
|
17
|
-
@dbms = db.mariadb?
|
18
|
-
|
19
|
-
|
17
|
+
@dbms = if db.mariadb?
|
18
|
+
Sequel::Sequence::Database::Server::Mariadb
|
19
|
+
else
|
20
|
+
Sequel::Sequence::Database::Server::Mysql
|
21
|
+
end
|
22
|
+
db.log_info "Sequel::Database.connect (mariadb? = #{db.mariadb?.inspect})"
|
23
|
+
db.log_info "Sequel::Database.connect (server_version = #{db.server_version.inspect})"
|
20
24
|
Sequel::Mysql2::Database.include(@dbms)
|
21
25
|
end
|
22
26
|
db
|
data/lib/sequel/sequence.rb
CHANGED
@@ -1,29 +1,61 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'sequel/database'
|
4
|
-
require 'sequel/adapters/postgres'
|
5
|
-
require 'sequel/adapters/mysql2'
|
6
|
-
require 'sequel/adapters/sqlite'
|
7
4
|
require 'sequel/error'
|
8
5
|
require 'sequel/sequence/database_ext_connection'
|
9
6
|
|
10
7
|
module Sequel
|
11
8
|
module Sequence
|
12
9
|
require 'sequel/sequence/database'
|
13
|
-
|
14
|
-
module Database
|
15
|
-
require 'sequel/sequence/database/postgresql'
|
16
|
-
require 'sequel/sequence/database/sqlite'
|
17
|
-
end
|
18
10
|
end
|
19
11
|
end
|
20
12
|
|
21
13
|
Sequel::Database.include(
|
22
14
|
Sequel::Sequence::Database
|
23
15
|
)
|
24
|
-
|
25
|
-
|
26
|
-
)
|
27
|
-
|
28
|
-
|
29
|
-
|
16
|
+
|
17
|
+
begin
|
18
|
+
if Gem::Specification.find_by_name('pg')
|
19
|
+
require 'sequel/adapters/postgres'
|
20
|
+
|
21
|
+
module Sequel
|
22
|
+
module Sequence
|
23
|
+
module Database
|
24
|
+
require 'sequel/sequence/database/postgresql'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
Sequel::Postgres::Database.include(
|
30
|
+
Sequel::Sequence::Database::PostgreSQL
|
31
|
+
)
|
32
|
+
end
|
33
|
+
rescue Gem::LoadError
|
34
|
+
# do nothing
|
35
|
+
end
|
36
|
+
|
37
|
+
begin
|
38
|
+
require 'sequel/adapters/mysql2' if Gem::Specification.find_by_name('mysql2')
|
39
|
+
rescue Gem::LoadError
|
40
|
+
# do nothing
|
41
|
+
end
|
42
|
+
|
43
|
+
begin
|
44
|
+
if Gem::Specification.find_by_name('sqlite3')
|
45
|
+
require 'sequel/adapters/sqlite'
|
46
|
+
|
47
|
+
module Sequel
|
48
|
+
module Sequence
|
49
|
+
module Database
|
50
|
+
require 'sequel/sequence/database/sqlite'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
Sequel::SQLite::Database.include(
|
56
|
+
Sequel::Sequence::Database::SQLite
|
57
|
+
)
|
58
|
+
end
|
59
|
+
rescue Gem::LoadError
|
60
|
+
# do nothing
|
61
|
+
end
|
data/sequel-sequence.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.summary = \
|
10
10
|
'Adds SEQUENCE support to Sequel for migrations to PostgreSQL, MariaDB, MySQL and SQLite.'
|
11
11
|
spec.description = <<-DES
|
12
|
-
This gem provides a single interface for SEQUENCE functionality
|
12
|
+
This gem provides a single user-friendly interface for SEQUENCE functionality
|
13
13
|
in Postgresql and MariaDB DBMS within the Sequel ORM.
|
14
14
|
It also models the Sequences to meet the needs of SQLite and MySQL users.
|
15
15
|
DES
|
@@ -27,22 +27,22 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.platform = Gem::Platform::RUBY
|
28
28
|
spec.required_ruby_version = '>= 2.7.0'
|
29
29
|
|
30
|
-
spec.add_dependency 'sequel', '>= 5.28', '<
|
30
|
+
spec.add_dependency 'sequel', '>= 5.28', '<6.0'
|
31
31
|
spec.add_development_dependency 'bundler', '>= 2.2.4'
|
32
32
|
spec.add_development_dependency 'minitest-utils', '~> 0.4.6'
|
33
33
|
spec.add_development_dependency 'pry-byebug', '~> 3.10.1'
|
34
34
|
spec.add_development_dependency 'rake', '~> 13.0.2'
|
35
35
|
spec.add_development_dependency 'rubocop', '~> 1.56.3'
|
36
36
|
spec.add_development_dependency 'simplecov', '~> 0.22.0'
|
37
|
-
if RUBY_ENGINE == 'jruby'
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
else
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
37
|
+
# if RUBY_ENGINE == 'jruby'
|
38
|
+
# # JRuby Adapter Dependencies
|
39
|
+
# spec.add_development_dependency 'jdbc-mysql', '~> 8.0.17'
|
40
|
+
# spec.add_development_dependency 'jdbc-postgres', '~> 42.2.14'
|
41
|
+
# spec.add_development_dependency 'jdbc-sqlite3', '~> 3.42'
|
42
|
+
# else
|
43
|
+
# # MRI/Rubinius Adapter Dependencies
|
44
|
+
# spec.add_development_dependency 'mysql2', '~> 0.5.3'
|
45
|
+
# spec.add_development_dependency 'pg', '~> 1.5.4'
|
46
|
+
# spec.add_development_dependency 'sqlite3', '~> 1.6.0'
|
47
|
+
# end
|
48
48
|
end
|
data/test/mariadb_test_helper.rb
CHANGED
@@ -13,7 +13,9 @@ MariaDB = Sequel.connect(
|
|
13
13
|
|
14
14
|
module MariadbTestHelper
|
15
15
|
def recreate_table
|
16
|
+
MariaDB.run 'DROP TABLE IF EXISTS builders'
|
16
17
|
MariaDB.run 'DROP SEQUENCE IF EXISTS position'
|
18
|
+
MariaDB.run 'DROP SEQUENCE IF EXISTS position_id'
|
17
19
|
MariaDB.run 'DROP TABLE IF EXISTS wares'
|
18
20
|
MariaDB.run 'DROP SEQUENCE IF EXISTS a'
|
19
21
|
MariaDB.run 'DROP SEQUENCE IF EXISTS b'
|