sequel-sequence 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,30 +3,52 @@
3
3
  module Sequel
4
4
  module Sequence
5
5
  module Database
6
- # def custom_sequence?(_sequence_name)
7
- # false
8
- # end
6
+ DANGER_OPT_ID = "Warning! The new sequence ID can't be less than the current one."
7
+ DANGER_OPT_INCREMENT = 'Warning! Increments greater than 1 are not supported.'
8
+ IF_EXISTS = 'IF EXISTS'
9
+ IF_NOT_EXISTS = 'IF NOT EXISTS'
10
+
11
+ def check_options(params)
12
+ log_info DANGER_OPT_INCREMENT if params[:increment] && params[:increment] != 1
13
+ log_info DANGER_OPT_INCREMENT if params[:step] && params[:step] != 1
14
+ end
15
+
16
+ def custom_sequence?(_sequence_name)
17
+ raise Sequel::MethodNotAllowed, Sequel::MethodNotAllowed::METHOD_NOT_ALLOWED
18
+ end
9
19
 
10
20
  def check_sequences
11
- []
21
+ raise Sequel::MethodNotAllowed, Sequel::MethodNotAllowed::METHOD_NOT_ALLOWED
12
22
  end
13
23
 
14
24
  def create_sequence(_name, _options = {})
15
25
  raise Sequel::MethodNotAllowed, Sequel::MethodNotAllowed::METHOD_NOT_ALLOWED
16
26
  end
17
27
 
18
- def drop_sequence(_name)
28
+ def drop_sequence(_name, _options = {})
19
29
  raise Sequel::MethodNotAllowed, Sequel::MethodNotAllowed::METHOD_NOT_ALLOWED
20
30
  end
21
31
 
22
32
  def quote_name(name)
33
+ unless respond_to?(:quote_column_name, false)
34
+ raise Sequel::MethodNotAllowed, Sequel::MethodNotAllowed::METHOD_NOT_ALLOWED
35
+ end
36
+
23
37
  name.to_s.split('.', 2).map { |part| quote_column_name(part) }.join('.')
24
38
  end
25
39
 
26
40
  def quote(name)
41
+ unless respond_to?(:quote_sequence_name, false)
42
+ raise Sequel::MethodNotAllowed, Sequel::MethodNotAllowed::METHOD_NOT_ALLOWED
43
+ end
44
+
27
45
  name.to_s.split('.', 2).map { |part| quote_sequence_name(part) }.join('.')
28
46
  end
29
47
 
48
+ def nextval_with_label(_name, _num_label = 0)
49
+ raise Sequel::MethodNotAllowed, Sequel::MethodNotAllowed::METHOD_NOT_ALLOWED
50
+ end
51
+
30
52
  def nextval(_name)
31
53
  raise Sequel::MethodNotAllowed, Sequel::MethodNotAllowed::METHOD_NOT_ALLOWED
32
54
  end
@@ -40,7 +62,16 @@ module Sequel
40
62
  alias lastval currval
41
63
 
42
64
  def setval(_name, _value)
43
- raise AR::MethodNotAllowed, AR::MethodNotAllowed::METHOD_NOT_ALLOWED
65
+ raise Sequel::MethodNotAllowed, Sequel::MethodNotAllowed::METHOD_NOT_ALLOWED
66
+ end
67
+
68
+ def build_exists_condition(option)
69
+ case option
70
+ when true
71
+ IF_EXISTS
72
+ when false
73
+ IF_NOT_EXISTS
74
+ end
44
75
  end
45
76
  end
46
77
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sequel
4
4
  module Sequence
5
- VERSION = '0.1.0'
5
+ VERSION = '0.3.0'
6
6
  end
7
7
  end
@@ -4,6 +4,7 @@ require 'sequel/database'
4
4
  require 'sequel/adapters/postgres'
5
5
  # require 'sequel/adapters/mysql'
6
6
  require 'sequel/adapters/mysql2'
7
+ require 'sequel/adapters/sqlite'
7
8
  require 'sequel/error'
8
9
 
9
10
  module Sequel
@@ -14,6 +15,7 @@ module Sequel
14
15
  require 'sequel/sequence/database/postgresql'
15
16
  # require "sequel/sequence/database/mysql"
16
17
  require 'sequel/sequence/database/mysql2'
18
+ require 'sequel/sequence/database/sqlite'
17
19
  end
18
20
  end
19
21
  end
@@ -30,3 +32,6 @@ Sequel::Mysql2::Database.include(
30
32
  # Sequel::Mysql::Database.include(
31
33
  # Sequel::Sequence::Database::Mysql
32
34
  # )
35
+ Sequel::SQLite::Database.include(
36
+ Sequel::Sequence::Database::SQLite
37
+ )
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
16
16
  spec.email = ['it.architect@yahoo.com']
17
17
  spec.files = `git ls-files -z`.split("\x0")
18
18
  spec.require_paths = ['lib']
19
- spec.extra_rdoc_files = ['README.md']
19
+ spec.extra_rdoc_files = ['README.md', 'LICENSE.md']
20
20
  spec.homepage = 'https://rubygems.org/gems/sequel-sequence'
21
21
  spec.metadata = {
22
22
  'source_code_uri' => 'https://github.com/oreol-group/sequel-sequence',
@@ -26,20 +26,22 @@ Gem::Specification.new do |spec|
26
26
  spec.platform = Gem::Platform::RUBY
27
27
  spec.required_ruby_version = '>= 2.7.0'
28
28
 
29
- spec.add_dependency 'sequel'
30
- spec.add_development_dependency 'bundler'
31
- spec.add_development_dependency 'minitest-utils'
32
- spec.add_development_dependency 'pry-byebug'
33
- spec.add_development_dependency 'rake'
34
- spec.add_development_dependency 'rubocop'
35
- spec.add_development_dependency 'simplecov'
29
+ spec.add_dependency 'sequel', '>= 5.28', '<5.73'
30
+ spec.add_development_dependency 'bundler', '>= 2.2.4'
31
+ spec.add_development_dependency 'minitest-utils', '~> 0.4.6'
32
+ spec.add_development_dependency 'pry-byebug', '~> 3.10.1'
33
+ spec.add_development_dependency 'rake', '~> 13.0.2'
34
+ spec.add_development_dependency 'rubocop', '~> 1.56.3'
35
+ spec.add_development_dependency 'simplecov', '~> 0.22.0'
36
36
  if RUBY_ENGINE == 'jruby'
37
37
  # JRuby Adapter Dependencies
38
- spec.add_development_dependency 'jdbc-mysql'
39
- spec.add_development_dependency 'jdbc-postgres'
38
+ spec.add_development_dependency 'jdbc-mysql', '~> 8.0.17'
39
+ spec.add_development_dependency 'jdbc-postgres', '~> 42.2.14'
40
+ spec.add_development_dependency 'jdbc-sqlite3', '~> 3.42'
40
41
  else
41
42
  # MRI/Rubinius Adapter Dependencies
42
- spec.add_development_dependency 'mysql2'
43
- spec.add_development_dependency 'pg'
43
+ spec.add_development_dependency 'mysql2', '~> 0.5.3'
44
+ spec.add_development_dependency 'pg', '~> 1.5.4'
45
+ spec.add_development_dependency 'sqlite3', '~> 1.6.0'
44
46
  end
45
47
  end
@@ -2,18 +2,14 @@
2
2
 
3
3
  require 'test_helper'
4
4
 
5
- MysqlDB = Sequel.connect('mysql2://root:root@localhost/test')
6
-
7
- Sequel::Model.db = MysqlDB
8
-
9
- class Ware < Sequel::Model
10
- end
11
-
12
- class InheritedWare < Ware
13
- end
14
-
15
- class Builder < Sequel::Model
16
- end
5
+ MysqlDB = Sequel.connect(
6
+ adapter: 'mysql2',
7
+ user: ENV['TEST_MYSQL_USERNAME'] || 'root',
8
+ password: ENV['TEST_MYSQL_PASSWORD'] || 'root',
9
+ host: ENV['TEST_MYSQL_HOST'] || '127.0.0.1',
10
+ port: ENV['TEST_MYSQL_PORT'] || 3306,
11
+ database: ENV['TEST_MYSQL_DATABASE'] || 'test'
12
+ )
17
13
 
18
14
  module MysqlTestHelper
19
15
  def recreate_table
@@ -25,4 +21,12 @@ module MysqlTestHelper
25
21
  sql = 'CREATE TABLE wares (id INT AUTO_INCREMENT, slug VARCHAR(255), quantity INT DEFAULT(0), PRIMARY KEY(id));'
26
22
  MysqlDB.run sql
27
23
  end
24
+
25
+ def with_migration(&block)
26
+ migration_class = Sequel::Migration
27
+
28
+ Sequel::Model.db = MysqlDB
29
+
30
+ Class.new(migration_class, &block).new(MysqlDB)
31
+ end
28
32
  end
@@ -2,18 +2,14 @@
2
2
 
3
3
  require 'test_helper'
4
4
 
5
- PostgresqlDB = Sequel.connect('postgres:///test')
6
-
7
- Sequel::Model.db = PostgresqlDB
8
-
9
- class Thing < Sequel::Model
10
- end
11
-
12
- class InheritedThing < Thing
13
- end
14
-
15
- class Master < Sequel::Model
16
- end
5
+ PostgresqlDB = Sequel.connect(
6
+ adapter: 'postgres',
7
+ user: ENV['TEST_POSTGRES_USERNAME'] || 'postgres',
8
+ password: ENV['TEST_POSTGRES_PASSWORD'] || 'postgres',
9
+ host: ENV['TEST_POSTGRES_HOST'] || 'localhost',
10
+ port: ENV['TEST_POSTGRES_PORT'] || 5432,
11
+ database: ENV['TEST_POSTGRES_DATABASE'] || 'test'
12
+ )
17
13
 
18
14
  module PostgresqlTestHelper
19
15
  def recreate_table
@@ -25,4 +21,12 @@ module PostgresqlTestHelper
25
21
  sql = 'CREATE TABLE things (id SERIAL PRIMARY KEY, slug VARCHAR(255), quantity INTEGER DEFAULT 0);'
26
22
  PostgresqlDB.run sql
27
23
  end
24
+
25
+ def with_migration(&block)
26
+ migration_class = Sequel::Migration
27
+
28
+ Sequel::Model.db = PostgresqlDB
29
+
30
+ Class.new(migration_class, &block).new(PostgresqlDB)
31
+ end
28
32
  end
@@ -10,97 +10,108 @@ class MysqlSequenceTest < Minitest::Test
10
10
  end
11
11
 
12
12
  test 'adds sequence with default values' do
13
- Sequel.migration do
14
- up do
13
+ with_migration do
14
+ def up
15
+ # create_sequence :position, {start: 1, increment: 1} - default values
15
16
  create_sequence :position
16
17
  end
17
- end.apply(MysqlDB, :up)
18
+ end.up
18
19
 
19
- assert_equal 1, Ware.db.nextval(:position)
20
- assert_equal 2, Ware.db.nextval(:position)
20
+ assert_equal 1, MysqlDB.nextval(:position)
21
+ assert_equal 2, MysqlDB.nextval(:position)
21
22
  end
22
23
 
23
- test 'adds sequence reader within inherited class' do
24
- Sequel.migration do
25
- up do
24
+ test 'adds sequence reader within model and its inherited class' do
25
+ with_migration do
26
+ def up
26
27
  create_sequence :position
27
28
  end
28
- end.apply(MysqlDB, :up)
29
+ end.up
29
30
 
30
- assert_equal 1, InheritedWare.db.nextval(:position)
31
- assert_equal 2, InheritedWare.db.nextval(:position)
31
+ class Ware < Sequel::Model; end
32
+
33
+ assert_equal 1, Ware.db.nextval('position')
34
+ assert_equal 2, Ware.db.nextval('position')
35
+
36
+ class InheritedWare < Ware; end
37
+
38
+ assert_equal 3, InheritedWare.db.nextval(:position)
39
+ assert_equal 4, InheritedWare.db.nextval(:position)
32
40
  end
33
41
 
34
42
  test 'adds sequence starting at 100' do
35
- Sequel.migration do
36
- up do
43
+ with_migration do
44
+ def up
37
45
  create_sequence :position, start: 100
38
46
  end
39
- end.apply(MysqlDB, :up)
47
+ end.up
40
48
 
41
- assert_equal 100, Ware.db.nextval(:position)
42
- assert_equal 101, Ware.db.nextval(:position)
49
+ assert_equal 100, MysqlDB.nextval(:position)
50
+ assert_equal 101, MysqlDB.nextval(:position)
43
51
  end
44
52
 
45
53
  test 'adds sequence incremented by 2' do
46
- Sequel.migration do
47
- up do
54
+ with_migration do
55
+ def up
48
56
  create_sequence :position, increment: 2
49
57
  end
50
- end.apply(MysqlDB, :up)
58
+ end.up
51
59
 
52
- assert_equal 1, Ware.db.nextval(:position)
53
- assert_equal 3, Ware.db.nextval(:position)
60
+ assert_equal 1, MysqlDB.nextval(:position)
61
+ assert_equal 3, MysqlDB.nextval(:position)
54
62
  end
55
63
 
56
64
  test 'adds sequence incremented by 2 (using :step alias)' do
57
- Sequel.migration do
58
- up do
65
+ with_migration do
66
+ def up
59
67
  create_sequence :position, step: 2
60
68
  end
61
- end.apply(MysqlDB, :up)
69
+ end.up
62
70
 
63
- assert_equal 1, Ware.db.nextval(:position)
64
- assert_equal 3, Ware.db.nextval(:position)
71
+ assert_equal 1, MysqlDB.nextval(:position)
72
+ assert_equal 3, MysqlDB.nextval(:position)
65
73
  end
66
74
 
67
- test 'returns current/last sequence value without incrementing it' do
68
- Sequel.migration do
69
- up do
75
+ test "returns current/last sequence value, which doesn't increase by itself" do
76
+ with_migration do
77
+ def up
70
78
  create_sequence :position
71
79
  end
72
- end.apply(MysqlDB, :up)
80
+ end.up
73
81
 
74
- Ware.db.nextval(:position)
82
+ MysqlDB.nextval(:position)
75
83
 
76
- assert_equal 1, Ware.db.currval(:position)
77
- assert_equal 1, Ware.db.lastval(:position)
78
- assert_equal 1, Ware.db.currval(:position)
79
- assert_equal 1, Ware.db.lastval(:position)
84
+ assert_equal 1, MysqlDB.currval(:position)
85
+ assert_equal 1, MysqlDB.lastval(:position)
86
+ assert_equal 1, MysqlDB.currval(:position)
87
+ assert_equal 1, MysqlDB.lastval(:position)
80
88
  end
81
89
 
82
90
  test 'sets sequence value' do
83
- Sequel.migration do
84
- up do
91
+ with_migration do
92
+ def up
85
93
  create_sequence :position
86
94
  end
87
- end.apply(MysqlDB, :up)
95
+ end.up
88
96
 
89
- Ware.db.nextval(:position)
90
- assert_equal Ware.db.currval(:position), 1
97
+ MysqlDB.nextval(:position)
98
+ assert_equal MysqlDB.currval(:position), 1
91
99
 
100
+ MysqlDB.setval(:position, 101)
92
101
  # in mariaDB, 'lastval' only works after 'nextval' rather than 'setval'
93
- Ware.db.setval(:position, 101)
94
- Ware.db.nextval(:position)
95
- assert_equal Ware.db.lastval(:position), 102
102
+ assert_equal 1, MysqlDB.lastval(:position)
103
+
104
+ MysqlDB.nextval(:position)
105
+ # now the value is correct
106
+ assert_equal 102, MysqlDB.lastval(:position)
96
107
  end
97
108
 
98
109
  test 'drops sequence and check_sequences' do
99
- Sequel.migration do
100
- up do
110
+ with_migration do
111
+ def up
101
112
  create_sequence :position
102
113
  end
103
- end.apply(MysqlDB, :up)
114
+ end.up
104
115
 
105
116
  sequence = MysqlDB.check_sequences.find_all do |seq|
106
117
  seq[:Tables_in_test] == 'position'
@@ -108,14 +119,14 @@ class MysqlSequenceTest < Minitest::Test
108
119
 
109
120
  assert_equal 1, sequence.size
110
121
 
111
- Sequel.migration do
112
- down do
122
+ with_migration do
123
+ def down
113
124
  drop_sequence :position
114
125
  end
115
- end.apply(MysqlDB, :down)
126
+ end.down
116
127
 
117
128
  sequence = MysqlDB.check_sequences.find do |seq|
118
- seq[:sequence_name] == 'position'
129
+ seq[:Tables_in_test] == 'position'
119
130
  end
120
131
 
121
132
  assert_nil sequence
@@ -127,15 +138,14 @@ class MysqlSequenceTest < Minitest::Test
127
138
  assert !list.include?('b')
128
139
  assert !list.include?('c')
129
140
 
130
- Sequel.migration do
131
- up do
141
+ with_migration do
142
+ def up
132
143
  drop_table :things, if_exists: true
133
- # drop_table :masters, if_exists: true
134
144
  create_sequence :c
135
145
  create_sequence :a
136
146
  create_sequence :b
137
147
  end
138
- end.apply(MysqlDB, :up)
148
+ end.up
139
149
 
140
150
  list = MysqlDB.check_sequences.map { |s| s[:Tables_in_test] }
141
151
  assert list.include?('a')
@@ -144,20 +154,20 @@ class MysqlSequenceTest < Minitest::Test
144
154
  end
145
155
 
146
156
  test 'creates table that references sequence' do
147
- Sequel.migration do
148
- up do
157
+ with_migration do
158
+ def up
149
159
  drop_table :builders, if_exists: true
150
- create_sequence :position_id, if_exists: false
160
+ create_sequence :position_id, if_exists: false, start: 1
151
161
  create_table :builders do
152
162
  primary_key :id
153
163
  String :name, text: true
154
-
155
- # PostgreSQL uses bigint as the sequence's default type.
156
164
  Bignum :position, null: false
157
165
  end
158
166
  set_column_default_nextval :builders, :position, :position_id
159
167
  end
160
- end.apply(MysqlDB, :up)
168
+ end.up
169
+
170
+ class Builder < Sequel::Model; end
161
171
 
162
172
  builder1 = Builder.create(name: 'Builder 1')
163
173
  pos1 = MysqlDB.currval(:position_id)
@@ -10,96 +10,103 @@ class PostgresqlSequenceTest < Minitest::Test
10
10
  end
11
11
 
12
12
  test 'adds sequence with default values' do
13
- Sequel.migration do
14
- up do
13
+ with_migration do
14
+ def up
15
15
  # create_sequence :position, {start: 1, increment: 1} - default values
16
16
  create_sequence :position
17
17
  end
18
- end.apply(PostgresqlDB, :up)
18
+ end.up
19
19
 
20
20
  assert_equal 1, PostgresqlDB.nextval('position')
21
21
  assert_equal 2, PostgresqlDB.nextval('position')
22
22
  end
23
23
 
24
- test 'adds sequence reader within inherited class' do
25
- Sequel.migration do
26
- up do
24
+ test 'adds sequence reader within model and its inherited class' do
25
+ with_migration do
26
+ def up
27
27
  create_sequence :position
28
28
  end
29
- end.apply(PostgresqlDB, :up)
29
+ end.up
30
30
 
31
- assert_equal 1, InheritedThing.db.nextval(:position)
32
- assert_equal 2, InheritedThing.db.nextval(:position)
31
+ class Thing < Sequel::Model; end
32
+
33
+ assert_equal 1, Thing.db.nextval('position')
34
+ assert_equal 2, Thing.db.nextval('position')
35
+
36
+ class InheritedThing < Thing; end
37
+
38
+ assert_equal 3, InheritedThing.db.nextval(:position)
39
+ assert_equal 4, InheritedThing.db.nextval(:position)
33
40
  end
34
41
 
35
42
  test 'adds sequence starting at 100' do
36
- Sequel.migration do
37
- up do
43
+ with_migration do
44
+ def up
38
45
  create_sequence :position, start: 100
39
46
  end
40
- end.apply(PostgresqlDB, :up)
47
+ end.up
41
48
 
42
- assert_equal 100, Thing.db.nextval(:position)
43
- assert_equal 101, Thing.db.nextval(:position)
49
+ assert_equal 100, PostgresqlDB.nextval(:position)
50
+ assert_equal 101, PostgresqlDB.nextval(:position)
44
51
  end
45
52
 
46
53
  test 'adds sequence incremented by 2' do
47
- Sequel.migration do
48
- up do
54
+ with_migration do
55
+ def up
49
56
  create_sequence :position, increment: 2
50
57
  end
51
- end.apply(PostgresqlDB, :up)
58
+ end.up
52
59
 
53
- assert_equal 1, Thing.db.nextval(:position)
54
- assert_equal 3, Thing.db.nextval(:position)
60
+ assert_equal 1, PostgresqlDB.nextval(:position)
61
+ assert_equal 3, PostgresqlDB.nextval(:position)
55
62
  end
56
63
 
57
64
  test 'adds sequence incremented by 2 (using :step alias)' do
58
- Sequel.migration do
59
- up do
65
+ with_migration do
66
+ def up
60
67
  create_sequence :position, step: 2
61
68
  end
62
- end.apply(PostgresqlDB, :up)
69
+ end.up
63
70
 
64
- assert_equal 1, Thing.db.nextval(:position)
65
- assert_equal 3, Thing.db.nextval(:position)
71
+ assert_equal 1, PostgresqlDB.nextval(:position)
72
+ assert_equal 3, PostgresqlDB.nextval(:position)
66
73
  end
67
74
 
68
- test 'returns current (or last as alias) sequence value without incrementing it' do
69
- Sequel.migration do
70
- up do
75
+ test "returns current/last sequence value, which doesn't increase by itself" do
76
+ with_migration do
77
+ def up
71
78
  create_sequence :position, start: 2, increment: 2
72
79
  end
73
- end.apply(PostgresqlDB, :up)
80
+ end.up
74
81
 
75
- Thing.db.nextval(:position)
82
+ PostgresqlDB.nextval(:position)
76
83
 
77
- assert_equal 2, Thing.db.currval(:position)
78
- assert_equal 2, Thing.db.lastval(:position)
79
- assert_equal 2, Thing.db.currval(:position)
80
- assert_equal 2, Thing.db.lastval(:position)
84
+ assert_equal 2, PostgresqlDB.currval(:position)
85
+ assert_equal 2, PostgresqlDB.lastval(:position)
86
+ assert_equal 2, PostgresqlDB.currval(:position)
87
+ assert_equal 2, PostgresqlDB.lastval(:position)
81
88
  end
82
89
 
83
90
  test 'sets sequence value' do
84
- Sequel.migration do
85
- up do
91
+ with_migration do
92
+ def up
86
93
  create_sequence :position
87
94
  end
88
- end.apply(PostgresqlDB, :up)
95
+ end.up
89
96
 
90
- Thing.db.nextval(:position)
91
- assert_equal Thing.db.currval(:position), 1
97
+ PostgresqlDB.nextval(:position)
98
+ assert_equal PostgresqlDB.currval(:position), 1
92
99
 
93
- Thing.db.setval(:position, 101)
94
- assert_equal 101, Thing.db.currval(:position)
100
+ PostgresqlDB.setval(:position, 101)
101
+ assert_equal 101, PostgresqlDB.currval(:position)
95
102
  end
96
103
 
97
104
  test 'drops sequence and check_sequences' do
98
- Sequel.migration do
99
- up do
105
+ with_migration do
106
+ def up
100
107
  create_sequence :position
101
108
  end
102
- end.apply(PostgresqlDB, :up)
109
+ end.up
103
110
 
104
111
  sequence = PostgresqlDB.check_sequences.find_all do |seq|
105
112
  seq[:sequence_name] == 'position'
@@ -107,11 +114,11 @@ class PostgresqlSequenceTest < Minitest::Test
107
114
 
108
115
  assert_equal 1, sequence.size
109
116
 
110
- Sequel.migration do
111
- down do
117
+ with_migration do
118
+ def down
112
119
  drop_sequence :position
113
120
  end
114
- end.apply(PostgresqlDB, :down)
121
+ end.down
115
122
 
116
123
  sequence = PostgresqlDB.check_sequences.find do |seq|
117
124
  seq[:sequence_name] == 'position'
@@ -126,15 +133,14 @@ class PostgresqlSequenceTest < Minitest::Test
126
133
  assert !list.include?('b')
127
134
  assert !list.include?('c')
128
135
 
129
- Sequel.migration do
130
- up do
136
+ with_migration do
137
+ def up
131
138
  drop_table :things, if_exists: true
132
- # drop_table :masters, if_exists: true
133
139
  create_sequence :c
134
140
  create_sequence :a
135
141
  create_sequence :b
136
142
  end
137
- end.apply(PostgresqlDB, :up)
143
+ end.up
138
144
 
139
145
  list = PostgresqlDB.check_sequences.map { |s| s[:sequence_name] }
140
146
  assert list.include?('a')
@@ -145,30 +151,30 @@ class PostgresqlSequenceTest < Minitest::Test
145
151
  test 'checks custom sequence generated from code' do
146
152
  assert_equal PostgresqlDB.custom_sequence?(:c), false
147
153
 
148
- Sequel.migration do
149
- up do
154
+ with_migration do
155
+ def up
150
156
  create_sequence :c
151
157
  end
152
- end.apply(PostgresqlDB, :up)
158
+ end.up
153
159
 
154
160
  assert_equal PostgresqlDB.custom_sequence?(:c), true
155
161
  end
156
162
 
157
163
  test 'creates table that references sequence' do
158
- Sequel.migration do
159
- up do
164
+ with_migration do
165
+ def up
160
166
  drop_table :masters, if_exists: true
161
- create_sequence :position_id, if_exists: false
162
- create_table :masters do
167
+ create_sequence :position_id, if_exists: false, start: 1
168
+ create_table :masters, if_not_exists: true do
163
169
  primary_key :id
164
170
  String :name, text: true
165
-
166
- # PostgreSQL uses bigint as the sequence's default type.
167
171
  Bignum :position, null: false
168
172
  end
169
173
  set_column_default_nextval :masters, :position, :position_id
170
174
  end
171
- end.apply(PostgresqlDB, :up)
175
+ end.up
176
+
177
+ class Master < Sequel::Model; end
172
178
 
173
179
  master1 = Master.create(name: 'MASTER 1')
174
180
  pos1 = PostgresqlDB.currval(:position_id)