sequel-sequence 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 10902f0e1d1afb59a3461ea44138203c9ddf3f0455b49ffe811c7b23aadc8ede
4
- data.tar.gz: 6e928d7c8827d2cc67c32d4fe28156490b99b187cbf6cbc19f546c2706e55087
3
+ metadata.gz: 39e70601cb32fc0e4240423134984c665c0691ebb68aa2b1038b43ea0e978176
4
+ data.tar.gz: ad285adcee5907a0d40d3ecd7d4e2bb67d3711876c75687276a58f71304cf48a
5
5
  SHA512:
6
- metadata.gz: 545bb293f276fd0f92441941fa9efc7dc432fd1b1a5131bb10a7465aba833db72f2ca2e29abc3f6cc427b958df3bc47354abf1d9d420efa77d1d610de85e2166
7
- data.tar.gz: 20273fe64a4e90fd2f8345ea8b08d96819bb4c52ff26684b2e67d49674c0360fc0926a66c565041b6a16f8e49d348133cca80cc629c4c14614a1116eb3e6dc60
6
+ metadata.gz: 0b97dc0b9a8b1c531d3863de2c52fde8ae2f0013aca027035fef391e2977db84520e6a00b059118a7c62ce77c57f7333abbfab56dad13d0b425d2ff4f923c02f
7
+ data.tar.gz: e35322803655e71d7118c3ec3e63e554ffaa73e0669e3d0947ad386d277d8b465c66b677ee9aa9bc14843062fef0331865682df769e2b2aa3fa136bca8e7029c
@@ -0,0 +1,41 @@
1
+ ---
2
+ name: "🐛 Bug Report"
3
+ about: Report a reproducible bug or regression.
4
+ title: 'Bug: '
5
+ labels: 'Status: Unconfirmed'
6
+
7
+ ---
8
+
9
+ <!--
10
+ - Please provide a clear and concise description of what the bug is.
11
+ - If possible, add an example reproducing your issue.
12
+ - Please test using the latest version of ar-sequence
13
+ to make sure your issue has not already been fixed.
14
+ -->
15
+
16
+ ## Description
17
+
18
+ [Add bug description here]
19
+
20
+ ## How to reproduce
21
+
22
+ [Add steps on how to reproduce this issue]
23
+
24
+ ## What do you expect
25
+
26
+ [Describe what do you expect to happen]
27
+
28
+ ## What happened instead
29
+
30
+ [Describe the actual results]
31
+
32
+ ## Software:
33
+
34
+ - Gem version: [Add gem version here]
35
+ - Ruby version: [Add version here]
36
+
37
+ ## Full backtrace
38
+
39
+ ```text
40
+ [Paste full backtrace here]
41
+ ```
@@ -0,0 +1,23 @@
1
+ ---
2
+ name: "💡 Feature request"
3
+ about: Have an idea that may be useful? Make a suggestion!
4
+ title: 'Feature Request: '
5
+ labels: 'Feature request'
6
+
7
+ ---
8
+
9
+ ## Description
10
+
11
+ _A clear and concise description of what the problem is._
12
+
13
+ ## Describe the solution
14
+
15
+ _A clear and concise description of what you want to happen._
16
+
17
+ ## Alternatives you considered
18
+
19
+ _A clear and concise description of any alternative solutions or features you've considered._
20
+
21
+ ## Additional context
22
+
23
+ _Add any other context, screenshots, links, etc about the feature request here._
@@ -0,0 +1,38 @@
1
+ <!--
2
+ If you're making a doc PR or something tiny where the below is irrelevant,
3
+ delete this template and use a short description, but in your description aim to
4
+ include both what the change is, and why it is being made, with enough context
5
+ for anyone to understand.
6
+ -->
7
+
8
+ <details>
9
+ <summary>PR Checklist</summary>
10
+
11
+ ### PR Structure
12
+
13
+ - [ ] This PR has reasonably narrow scope (if not, break it down into smaller
14
+ PRs).
15
+ - [ ] This PR avoids mixing refactoring changes with feature changes (split into
16
+ two PRs otherwise).
17
+ - [ ] This PR's title starts is concise and descriptive.
18
+
19
+ ### Thoroughness
20
+
21
+ - [ ] This PR adds tests for the most critical parts of the new functionality or
22
+ fixes.
23
+ - [ ] I've updated any docs, `.md` files, etc… affected by this change.
24
+
25
+ </details>
26
+
27
+ ### What
28
+
29
+ [TODO: Short statement about what is changing.]
30
+
31
+ ### Why
32
+
33
+ [TODO: Why this change is being made. Include any context required to understand
34
+ the why.]
35
+
36
+ ### Known limitations
37
+
38
+ [TODO or N/A]
@@ -0,0 +1,14 @@
1
+ # Documentation:
2
+ # https://docs.github.com/en/free-pro-team@latest/github/administering-a-repository/configuration-options-for-dependency-updates
3
+
4
+ version: 2
5
+ updates:
6
+ - package-ecosystem: "github-actions"
7
+ directory: "/"
8
+ schedule:
9
+ interval: "monthly"
10
+
11
+ - package-ecosystem: "bundler"
12
+ directory: "/"
13
+ schedule:
14
+ interval: "monthly"
@@ -0,0 +1,91 @@
1
+ name: CI
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ inputs: {}
6
+ push:
7
+ branches: [ master ]
8
+ pull_request:
9
+ branches: ['**']
10
+
11
+ jobs:
12
+ tests:
13
+ strategy:
14
+ fail-fast: false
15
+ matrix:
16
+ os: ['ubuntu-latest']
17
+ sequel: ['~>5.28']
18
+ ruby: ['3.2', '3.1', '3.0', '2.7']
19
+ gemfile: ['Gemfile']
20
+ runs-on: ${{ matrix.os }}
21
+ name: Tests with Ruby ${{ matrix.ruby }}
22
+
23
+ services:
24
+ postgres:
25
+ image: postgres:13
26
+ env:
27
+ POSTGRES_USER: postgres
28
+ POSTGRES_PASSWORD: postgres
29
+ ports:
30
+ - 5432:5432
31
+ options: >-
32
+ --health-cmd pg_isready
33
+ --health-interval 10s
34
+ --health-timeout 5s
35
+ --health-retries 5
36
+ mysql:
37
+ image: mariadb:11.1
38
+ env:
39
+ MARIADB_ROOT_PASSWORD: root
40
+ ports:
41
+ - 3306:3306
42
+ options: >-
43
+ --health-cmd="healthcheck.sh --connect --innodb_initialized"
44
+ --health-interval 10s
45
+ --health-timeout 5s
46
+ --health-retries 3
47
+
48
+ env:
49
+ SEQUEL: ${{ matrix.sequel }}
50
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
51
+ steps:
52
+ - uses: actions/checkout@v4
53
+
54
+ - name: Install db dependencies and check connections
55
+ run: |
56
+ DEBIAN_FRONTEND="noninteractive" sudo apt-get install -yqq mysql-client libmysqlclient-dev postgresql-client libpq-dev
57
+ mysql --host 127.0.0.1 --port ${{ job.services.mysql.ports[3306] }} -uroot -proot -e "SHOW GRANTS FOR 'root'@'localhost'"
58
+ env PGPASSWORD=postgres psql -h localhost -p ${{ job.services.postgres.ports[5432] }} -U postgres -l
59
+
60
+ - name: Set up Ruby
61
+ uses: ruby/setup-ruby@v1
62
+ with:
63
+ ruby-version: ${{ matrix.ruby }}
64
+ bundler-cache: true
65
+
66
+ - name: Create MySQL database
67
+ run: |
68
+ mysql -e 'create database test; use test; create table if not exists wares(id int auto_increment, primary key(id)); create table if not exists builders(id int auto_increment, primary key(id));' --host 127.0.0.1 --port ${{ job.services.mysql.ports[3306] }} -uroot -proot
69
+
70
+ - name: Create PostgreSQL database
71
+ env:
72
+ PGPASSWORD: postgres
73
+ run: |
74
+ psql -c 'create database "test";' -U postgres -h localhost -p ${{ job.services.postgres.ports[5432] }}
75
+
76
+ - name: Run Tests
77
+ run: bundle exec rake test
78
+ env:
79
+ TEST_POSTGRES_DATABASE: test
80
+ TEST_POSTGRES_HOST: localhost
81
+ TEST_POSTGRES_PORT: ${{ job.services.postgres.ports[5432] }}
82
+ TEST_POSTGRES_USERNAME: postgres
83
+ TEST_POSTGRES_PASSWORD: postgres
84
+ TEST_MYSQL_DATABASE: test
85
+ TEST_MYSQL_HOST: 127.0.0.1
86
+ TEST_MYSQL_PORT: ${{ job.services.mysql.ports[3306] }}
87
+ TEST_MYSQL_USERNAME: root
88
+ TEST_MYSQL_PASSWORD: root
89
+
90
+ - name: Run Rubocop
91
+ run: bundle exec rake rubocop
data/.gitignore CHANGED
@@ -1,11 +1,14 @@
1
- .bundle
2
-
3
1
  ## MAC OS
4
2
  .DS_Store
5
3
 
6
4
  ## PROJECT::GENERAL
7
5
  coverage
6
+ rdoc
8
7
  doc
9
8
  pkg
10
9
  tmp
10
+ log
11
+
12
+ ## PROJECT::SPECIFIC
13
+ .bundle
11
14
  Gemfile.lock
data/.rubocop.yml ADDED
@@ -0,0 +1,37 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+ NewCops: enable
4
+ SuggestExtensions:
5
+ rubocop-rake: false
6
+
7
+ Naming/FileName:
8
+ Enabled: false
9
+
10
+ Metrics/MethodLength:
11
+ Enabled: false
12
+
13
+ Metrics/ClassLength:
14
+ Exclude:
15
+ - test/**/*
16
+
17
+ Metrics/AbcSize:
18
+ Enabled: false
19
+
20
+ Metrics/CyclomaticComplexity:
21
+ Enabled: false
22
+
23
+ Metrics/PerceivedComplexity:
24
+ Enabled: false
25
+
26
+ Gemspec/RequireMFA:
27
+ Enabled: false
28
+
29
+ Gemspec/DevelopmentDependencies:
30
+ EnforcedStyle: gemspec
31
+
32
+ Style/Documentation:
33
+ Enabled: false
34
+
35
+ Lint/ConstantDefinitionInBlock:
36
+ Exclude:
37
+ - test/**/*
data/CHANGELOG.md CHANGED
@@ -11,6 +11,13 @@ Prefix your message with one of the following:
11
11
  - [Security] in case of vulnerabilities.
12
12
  -->
13
13
 
14
+ ## v0.2.0 - 2023-09-14
15
+
16
+ - [Added] CI features based on GitHub Actions.
17
+ - [Fixed] README.md
18
+ - [Changed] Unit tests.
19
+ - [Fixed] Sequel::Sequence::Database exceptions.
20
+
14
21
  ## v0.1.0 - 2023-09-10
15
22
 
16
23
  - Initial release.
data/CONTRIBUTING.md CHANGED
@@ -9,7 +9,7 @@ changes to this document in a pull request.
9
9
  ## Code of Conduct
10
10
 
11
11
  Everyone interacting in this project's codebases, issue trackers, chat rooms and
12
- mailing lists is expected to follow the [code of conduct](https://github.com/fnando/sequel-sequence/blob/main/CODE_OF_CONDUCT.md).
12
+ mailing lists is expected to follow the [code of conduct](https://github.com/oreol-group/sequel-sequence/blob/master/CODE_OF_CONDUCT.md).
13
13
 
14
14
  ## Reporting bugs
15
15
 
@@ -26,7 +26,7 @@ the behavior, and find related reports.
26
26
  ## Contributing with code
27
27
 
28
28
  Before making any radicals changes, please make sure you discuss your intention
29
- by [opening an issue on Github](https://github.com/fnando/sequel-sequence/issues).
29
+ by [opening an issue on Github](https://github.com/oreol-group/sequel-sequence/issues).
30
30
 
31
31
  When you're ready to make your pull request, follow checklist below to make sure
32
32
  your contribution is according to how this project works.
@@ -81,11 +81,22 @@ test=# \dt
81
81
  --------+---------+-------+-----------
82
82
  public | masters | table | USER_NAME
83
83
  public | things | table | USER_NAME
84
- (2 rows)
85
84
  ```
86
- - If it doesn't exists, create one with a couple of tables:
85
+ and role `postgres`
86
+ ```bash
87
+ psql -d test -c 'SELECT rolname FROM pg_roles;'
88
+ rolname
89
+ ---------------------------
90
+ postgres
91
+ ```
92
+ - If none of them exist, create role
93
+ ```bash
94
+ psql -d postgres -c "create role postgres superuser createdb login password 'postgres';"
95
+ ```
96
+ and database with a couple of tables:
97
+
87
98
  ```bash
88
- sudo psql -U USER_NAME -d postgres
99
+ sudo psql -U postgres -d postgres
89
100
  postgres=# CREATE DATABASE test;
90
101
  postgres=# \c test
91
102
  test=# CREATE TABLE IF NOT EXISTS things ();
@@ -104,7 +115,6 @@ MariaDB [test]> SHOW TABLES;
104
115
  | builders |
105
116
  | wares |
106
117
  +----------------------+
107
- 4 rows in set (0.001 sec)
108
118
  ```
109
119
  - If it doesn't exists, create one with a couple of tables:
110
120
  ```bash
@@ -115,6 +125,6 @@ MariaDB [test]> CREATE TABLE IF NOT EXISTS builders(id int auto_increment, prima
115
125
  ```
116
126
  - Run the tests separately:
117
127
  ```bash
118
- bundle exec rake TEST=test/ar/postgresql_sequence_test.rb
119
- bundle exec rake TEST=test/ar/mysql_sequence_test.rb
128
+ bundle exec rake TEST=test/sequel/postgresql_sequence_test.rb
129
+ bundle exec rake TEST=test/sequel/mysql_sequence_test.rb
120
130
  ```
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # sequel-sequence
2
2
 
3
- [![Tests](https://github.com/oreol-group/sequel-sequence/workflows/Tests/badge.svg)](https://github.com/oreol-group/sequel-sequence)
3
+ [![CI](https://github.com/oreol-group/sequel-sequence/actions/workflows/ci.yml/badge.svg)](https://github.com/oreol-group/sequel-sequence)
4
4
  [![Gem](https://img.shields.io/gem/v/sequel-sequence.svg)](https://rubygems.org/gems/sequel-sequence)
5
- [![Downloads total](https://img.shields.io/gem/dt/sequel-sequence.svg)](https://rubygems.org/gems/sequel-sequence)
5
+ [![Downloads total](https://img.shields.io/gem/dt/sequel-sequence.svg)](https://rubygems.org/profiles/it_architect)
6
6
 
7
7
  Adds a useful interface and support for PostgreSQL and MySQL `SEQUENCE` on Sequel migrations
8
8
 
@@ -93,16 +93,16 @@ DB.setval("position", 1234)
93
93
  ## Contributing
94
94
 
95
95
  For more details about how to contribute, please read
96
- https://github.com/oreol-group/sequel-sequence/blob/main/CONTRIBUTING.md.
96
+ https://github.com/oreol-group/sequel-sequence/blob/master/CONTRIBUTING.md.
97
97
 
98
98
  ## License
99
99
 
100
100
  The gem is available as open source under the terms of the
101
101
  [MIT License](https://opensource.org/licenses/MIT). A copy of the license can be
102
- found at https://github.com/oreol-group/sequel-sequence/blob/main/LICENSE.md.
102
+ found at https://github.com/oreol-group/sequel-sequence/blob/master/LICENSE.md.
103
103
 
104
104
  ## Code of Conduct
105
105
 
106
106
  Everyone interacting in the sequel-sequence project's codebases, issue trackers,
107
107
  chat rooms and mailing lists is expected to follow the
108
- [code of conduct](https://github.com/oreol-group/sequel-sequence/blob/main/CODE_OF_CONDUCT.md).
108
+ [code of conduct](https://github.com/oreol-group/sequel-sequence/blob/master/CODE_OF_CONDUCT.md).
@@ -3,12 +3,12 @@
3
3
  module Sequel
4
4
  module Sequence
5
5
  module Database
6
- # def custom_sequence?(_sequence_name)
7
- # false
8
- # end
6
+ def custom_sequence?(_sequence_name)
7
+ raise Sequel::MethodNotAllowed, Sequel::MethodNotAllowed::METHOD_NOT_ALLOWED
8
+ end
9
9
 
10
10
  def check_sequences
11
- []
11
+ raise Sequel::MethodNotAllowed, Sequel::MethodNotAllowed::METHOD_NOT_ALLOWED
12
12
  end
13
13
 
14
14
  def create_sequence(_name, _options = {})
@@ -20,10 +20,18 @@ module Sequel
20
20
  end
21
21
 
22
22
  def quote_name(name)
23
+ unless respond_to?(:quote_column_name, false)
24
+ raise Sequel::MethodNotAllowed, Sequel::MethodNotAllowed::METHOD_NOT_ALLOWED
25
+ end
26
+
23
27
  name.to_s.split('.', 2).map { |part| quote_column_name(part) }.join('.')
24
28
  end
25
29
 
26
30
  def quote(name)
31
+ unless respond_to?(:quote_sequence_name, false)
32
+ raise Sequel::MethodNotAllowed, Sequel::MethodNotAllowed::METHOD_NOT_ALLOWED
33
+ end
34
+
27
35
  name.to_s.split('.', 2).map { |part| quote_sequence_name(part) }.join('.')
28
36
  end
29
37
 
@@ -40,7 +48,7 @@ module Sequel
40
48
  alias lastval currval
41
49
 
42
50
  def setval(_name, _value)
43
- raise AR::MethodNotAllowed, AR::MethodNotAllowed::METHOD_NOT_ALLOWED
51
+ raise Sequel::MethodNotAllowed, Sequel::MethodNotAllowed::METHOD_NOT_ALLOWED
44
52
  end
45
53
  end
46
54
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sequel
4
4
  module Sequence
5
- VERSION = '0.1.0'
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
@@ -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,20 @@ 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
40
  else
41
41
  # MRI/Rubinius Adapter Dependencies
42
- spec.add_development_dependency 'mysql2'
43
- spec.add_development_dependency 'pg'
42
+ spec.add_development_dependency 'mysql2', '~> 0.5.3'
43
+ spec.add_development_dependency 'pg', '~> 1.5.4'
44
44
  end
45
45
  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
75
  test 'returns current/last sequence value without incrementing it' do
68
- Sequel.migration do
69
- up 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,11 +119,11 @@ 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
129
  seq[:sequence_name] == 'position'
@@ -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
160
  create_sequence :position_id, if_exists: false
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
75
  test 'returns current (or last as alias) sequence value without incrementing it' do
69
- Sequel.migration do
70
- up 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
167
  create_sequence :position_id, if_exists: false
162
- create_table :masters do
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)
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.1.0
4
+ version: 0.2.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 00:00:00.000000000 Z
11
+ date: 2023-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -16,126 +16,132 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '5.28'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.73'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
26
- version: '0'
29
+ version: '5.28'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.73'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: bundler
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
37
  - - ">="
32
38
  - !ruby/object:Gem::Version
33
- version: '0'
39
+ version: 2.2.4
34
40
  type: :development
35
41
  prerelease: false
36
42
  version_requirements: !ruby/object:Gem::Requirement
37
43
  requirements:
38
44
  - - ">="
39
45
  - !ruby/object:Gem::Version
40
- version: '0'
46
+ version: 2.2.4
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: minitest-utils
43
49
  requirement: !ruby/object:Gem::Requirement
44
50
  requirements:
45
- - - ">="
51
+ - - "~>"
46
52
  - !ruby/object:Gem::Version
47
- version: '0'
53
+ version: 0.4.6
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
51
57
  requirements:
52
- - - ">="
58
+ - - "~>"
53
59
  - !ruby/object:Gem::Version
54
- version: '0'
60
+ version: 0.4.6
55
61
  - !ruby/object:Gem::Dependency
56
62
  name: pry-byebug
57
63
  requirement: !ruby/object:Gem::Requirement
58
64
  requirements:
59
- - - ">="
65
+ - - "~>"
60
66
  - !ruby/object:Gem::Version
61
- version: '0'
67
+ version: 3.10.1
62
68
  type: :development
63
69
  prerelease: false
64
70
  version_requirements: !ruby/object:Gem::Requirement
65
71
  requirements:
66
- - - ">="
72
+ - - "~>"
67
73
  - !ruby/object:Gem::Version
68
- version: '0'
74
+ version: 3.10.1
69
75
  - !ruby/object:Gem::Dependency
70
76
  name: rake
71
77
  requirement: !ruby/object:Gem::Requirement
72
78
  requirements:
73
- - - ">="
79
+ - - "~>"
74
80
  - !ruby/object:Gem::Version
75
- version: '0'
81
+ version: 13.0.2
76
82
  type: :development
77
83
  prerelease: false
78
84
  version_requirements: !ruby/object:Gem::Requirement
79
85
  requirements:
80
- - - ">="
86
+ - - "~>"
81
87
  - !ruby/object:Gem::Version
82
- version: '0'
88
+ version: 13.0.2
83
89
  - !ruby/object:Gem::Dependency
84
90
  name: rubocop
85
91
  requirement: !ruby/object:Gem::Requirement
86
92
  requirements:
87
- - - ">="
93
+ - - "~>"
88
94
  - !ruby/object:Gem::Version
89
- version: '0'
95
+ version: 1.56.3
90
96
  type: :development
91
97
  prerelease: false
92
98
  version_requirements: !ruby/object:Gem::Requirement
93
99
  requirements:
94
- - - ">="
100
+ - - "~>"
95
101
  - !ruby/object:Gem::Version
96
- version: '0'
102
+ version: 1.56.3
97
103
  - !ruby/object:Gem::Dependency
98
104
  name: simplecov
99
105
  requirement: !ruby/object:Gem::Requirement
100
106
  requirements:
101
- - - ">="
107
+ - - "~>"
102
108
  - !ruby/object:Gem::Version
103
- version: '0'
109
+ version: 0.22.0
104
110
  type: :development
105
111
  prerelease: false
106
112
  version_requirements: !ruby/object:Gem::Requirement
107
113
  requirements:
108
- - - ">="
114
+ - - "~>"
109
115
  - !ruby/object:Gem::Version
110
- version: '0'
116
+ version: 0.22.0
111
117
  - !ruby/object:Gem::Dependency
112
118
  name: mysql2
113
119
  requirement: !ruby/object:Gem::Requirement
114
120
  requirements:
115
- - - ">="
121
+ - - "~>"
116
122
  - !ruby/object:Gem::Version
117
- version: '0'
123
+ version: 0.5.3
118
124
  type: :development
119
125
  prerelease: false
120
126
  version_requirements: !ruby/object:Gem::Requirement
121
127
  requirements:
122
- - - ">="
128
+ - - "~>"
123
129
  - !ruby/object:Gem::Version
124
- version: '0'
130
+ version: 0.5.3
125
131
  - !ruby/object:Gem::Dependency
126
132
  name: pg
127
133
  requirement: !ruby/object:Gem::Requirement
128
134
  requirements:
129
- - - ">="
135
+ - - "~>"
130
136
  - !ruby/object:Gem::Version
131
- version: '0'
137
+ version: 1.5.4
132
138
  type: :development
133
139
  prerelease: false
134
140
  version_requirements: !ruby/object:Gem::Requirement
135
141
  requirements:
136
- - - ">="
142
+ - - "~>"
137
143
  - !ruby/object:Gem::Version
138
- version: '0'
144
+ version: 1.5.4
139
145
  description: |2
140
146
  This gem provides a single interface for SEQUENCE functionality
141
147
  in Postgresql and Mysql databases within the Sequel ORM.
@@ -145,8 +151,15 @@ executables: []
145
151
  extensions: []
146
152
  extra_rdoc_files:
147
153
  - README.md
154
+ - LICENSE.md
148
155
  files:
156
+ - ".github/ISSUE_TEMPLATE/bug_report.md"
157
+ - ".github/ISSUE_TEMPLATE/feature_request.md"
158
+ - ".github/PULL_REQUEST_TEMPLATE.md"
159
+ - ".github/dependabot.yml"
160
+ - ".github/workflows/ci.yml"
149
161
  - ".gitignore"
162
+ - ".rubocop.yml"
150
163
  - CHANGELOG.md
151
164
  - CODE_OF_CONDUCT.md
152
165
  - CONTRIBUTING.md