sql_enum 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +7 -6
- data/.gitignore +2 -0
- data/Appraisals +10 -6
- data/Dockerfile +1 -1
- data/Gemfile.lock +34 -14
- data/README.md +4 -4
- data/gemfiles/rails_7.1.gemfile +1 -1
- data/gemfiles/{rails_6.1.gemfile → rails_7.2.gemfile} +1 -1
- data/gemfiles/{rails_7.0.gemfile → rails_8.0.gemfile} +1 -1
- data/gemfiles/rails_8.1.gemfile +7 -0
- data/lib/active_record/connection_adapters/abstract_mysql.rb +4 -33
- data/lib/active_record/connection_adapters/mysql2.rb +8 -7
- data/lib/sql_enum/class_methods.rb +12 -3
- data/lib/sql_enum/enum_column.rb +6 -6
- data/lib/sql_enum/version.rb +1 -1
- data/lib/sql_enum.rb +0 -4
- data/sql_enum.gemspec +4 -2
- metadata +11 -14
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a7a8723f0b471f08ceeade1092288485c811c8cdef91378456ceaff35820837c
|
|
4
|
+
data.tar.gz: 2ab5049a981c4b18244b66229125b5fe370ee856290ffa86c38fb6e959383cb1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 46eaa353cfaff0414fd857f0a7a763f169ec89d26a182e648419f0b8546db2bbf5397a943993b5ab8d27a3865940ae504106c6c58c114ac4bd02f3a2e8f63d03
|
|
7
|
+
data.tar.gz: b9e8e4b15f749739b968078d827f7b485acde671b51866f1b960a8aa25922d9d4e13c0f833f90735e5474ff1f1cdd27a61abe5eb6d3f483cfeffff678eb2e8c4
|
data/.github/workflows/tests.yml
CHANGED
|
@@ -10,15 +10,16 @@ jobs:
|
|
|
10
10
|
strategy:
|
|
11
11
|
matrix:
|
|
12
12
|
ruby:
|
|
13
|
-
- '3.0'
|
|
14
|
-
- '3.1'
|
|
15
13
|
- '3.2'
|
|
16
14
|
- '3.3'
|
|
15
|
+
- '3.4'
|
|
16
|
+
- '4.0'
|
|
17
17
|
rails:
|
|
18
|
-
- '6.1'
|
|
19
|
-
- '7.0'
|
|
20
18
|
- '7.1'
|
|
21
|
-
|
|
19
|
+
- '7.2'
|
|
20
|
+
- '8.0'
|
|
21
|
+
- '8.1'
|
|
22
|
+
runs-on: ubuntu-22.04
|
|
22
23
|
|
|
23
24
|
name: RSpec (Rails ${{ matrix.rails }}) (Ruby ${{ matrix.ruby }})
|
|
24
25
|
|
|
@@ -29,4 +30,4 @@ jobs:
|
|
|
29
30
|
ruby-version: ${{ matrix.ruby }}
|
|
30
31
|
bundler-cache: true
|
|
31
32
|
- name: Test
|
|
32
|
-
run: docker
|
|
33
|
+
run: docker compose run --rm rspec bundle exec appraisal rails-${{ matrix.rails }} rspec
|
data/.gitignore
CHANGED
data/Appraisals
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
appraise "rails-
|
|
2
|
-
gem "rails", "~>
|
|
1
|
+
appraise "rails-7.1" do
|
|
2
|
+
gem "rails", "~> 7.1.0"
|
|
3
3
|
end
|
|
4
4
|
|
|
5
|
-
appraise "rails-7.
|
|
6
|
-
gem "rails", "~> 7.0"
|
|
5
|
+
appraise "rails-7.2" do
|
|
6
|
+
gem "rails", "~> 7.2.0"
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
appraise "rails-
|
|
10
|
-
gem "rails", "~>
|
|
9
|
+
appraise "rails-8.0" do
|
|
10
|
+
gem "rails", "~> 8.0.0"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
appraise "rails-8.1" do
|
|
14
|
+
gem "rails", "~> 8.1.0"
|
|
11
15
|
end
|
data/Dockerfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,46 +1,63 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
sql_enum (
|
|
5
|
-
activerecord (>=
|
|
6
|
-
activesupport (>=
|
|
4
|
+
sql_enum (2.0.0)
|
|
5
|
+
activerecord (>= 7.1.0)
|
|
6
|
+
activesupport (>= 7.1.0)
|
|
7
7
|
mysql2
|
|
8
8
|
|
|
9
9
|
GEM
|
|
10
10
|
remote: https://rubygems.org/
|
|
11
11
|
specs:
|
|
12
|
-
activemodel (
|
|
13
|
-
activesupport (=
|
|
14
|
-
activerecord (
|
|
15
|
-
activemodel (=
|
|
16
|
-
activesupport (=
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
activemodel (8.1.2)
|
|
13
|
+
activesupport (= 8.1.2)
|
|
14
|
+
activerecord (8.1.2)
|
|
15
|
+
activemodel (= 8.1.2)
|
|
16
|
+
activesupport (= 8.1.2)
|
|
17
|
+
timeout (>= 0.4.0)
|
|
18
|
+
activesupport (8.1.2)
|
|
19
|
+
base64
|
|
20
|
+
bigdecimal
|
|
21
|
+
concurrent-ruby (~> 1.0, >= 1.3.1)
|
|
22
|
+
connection_pool (>= 2.2.5)
|
|
23
|
+
drb
|
|
19
24
|
i18n (>= 1.6, < 2)
|
|
25
|
+
json
|
|
26
|
+
logger (>= 1.4.2)
|
|
20
27
|
minitest (>= 5.1)
|
|
21
|
-
|
|
28
|
+
securerandom (>= 0.3)
|
|
29
|
+
tzinfo (~> 2.0, >= 2.0.5)
|
|
30
|
+
uri (>= 0.13.1)
|
|
22
31
|
appraisal (2.5.0)
|
|
23
32
|
bundler
|
|
24
33
|
rake
|
|
25
34
|
thor (>= 0.14.0)
|
|
26
35
|
awesome_print (1.9.2)
|
|
27
|
-
|
|
36
|
+
base64 (0.3.0)
|
|
37
|
+
bigdecimal (4.0.1)
|
|
38
|
+
concurrent-ruby (1.3.6)
|
|
39
|
+
connection_pool (3.0.2)
|
|
28
40
|
debug (1.9.1)
|
|
29
41
|
irb (~> 1.10)
|
|
30
42
|
reline (>= 0.3.8)
|
|
31
43
|
diff-lcs (1.5.0)
|
|
44
|
+
drb (2.2.3)
|
|
32
45
|
i18n (1.14.1)
|
|
33
46
|
concurrent-ruby (~> 1.0)
|
|
34
47
|
io-console (0.7.2)
|
|
35
48
|
irb (1.11.1)
|
|
36
49
|
rdoc
|
|
37
50
|
reline (>= 0.4.2)
|
|
38
|
-
|
|
51
|
+
json (2.18.1)
|
|
52
|
+
logger (1.7.0)
|
|
53
|
+
minitest (6.0.1)
|
|
54
|
+
prism (~> 1.5)
|
|
39
55
|
mysql2 (0.5.5)
|
|
56
|
+
prism (1.9.0)
|
|
40
57
|
psych (5.1.2)
|
|
41
58
|
stringio
|
|
42
59
|
rake (13.1.0)
|
|
43
|
-
rdoc (6.6.
|
|
60
|
+
rdoc (6.6.3.1)
|
|
44
61
|
psych (>= 4.0.0)
|
|
45
62
|
reline (0.4.2)
|
|
46
63
|
io-console (~> 0.5)
|
|
@@ -57,10 +74,13 @@ GEM
|
|
|
57
74
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
58
75
|
rspec-support (~> 3.12.0)
|
|
59
76
|
rspec-support (3.12.1)
|
|
77
|
+
securerandom (0.4.1)
|
|
60
78
|
stringio (3.1.0)
|
|
61
79
|
thor (1.3.0)
|
|
80
|
+
timeout (0.6.0)
|
|
62
81
|
tzinfo (2.0.6)
|
|
63
82
|
concurrent-ruby (~> 1.0)
|
|
83
|
+
uri (1.1.1)
|
|
64
84
|
|
|
65
85
|
PLATFORMS
|
|
66
86
|
ruby
|
data/README.md
CHANGED
|
@@ -4,9 +4,9 @@ Enables usage of native sql enums with ActiveRecord
|
|
|
4
4
|
|
|
5
5
|
## NOTE
|
|
6
6
|
|
|
7
|
-
Version
|
|
7
|
+
Version 2.0 of this gem requires Rails 7.1+ and Ruby 3.2+.
|
|
8
8
|
|
|
9
|
-
For Rails versions below
|
|
9
|
+
For Rails 7.0 and 7.1, use version 1.0. For Rails versions below 7, use version 0.4.
|
|
10
10
|
|
|
11
11
|
## Installation
|
|
12
12
|
|
|
@@ -30,7 +30,7 @@ Or install it yourself as:
|
|
|
30
30
|
|
|
31
31
|
Use a part of table definition:
|
|
32
32
|
```ruby
|
|
33
|
-
class CreateUsers < ActiveRecord::Migration[
|
|
33
|
+
class CreateUsers < ActiveRecord::Migration[7.1]
|
|
34
34
|
def change
|
|
35
35
|
create_table :users do |t|
|
|
36
36
|
t.enum :status, limit: [:active, :pending, :inactive], default: :active
|
|
@@ -58,7 +58,7 @@ end
|
|
|
58
58
|
|
|
59
59
|
### Testing
|
|
60
60
|
|
|
61
|
-
Run `docker
|
|
61
|
+
Run `docker compose run --rm rspec` to run the specs in a docker container alongside Mysql.
|
|
62
62
|
|
|
63
63
|
## Contributing
|
|
64
64
|
|
data/gemfiles/rails_7.1.gemfile
CHANGED
|
@@ -9,39 +9,10 @@ module ActiveRecord
|
|
|
9
9
|
end
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
#
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
# but in Rails 7.1, we need to call register_enum_type explicitly.
|
|
17
|
-
|
|
18
|
-
if SqlEnum.rails_version_match?("6.1")
|
|
19
|
-
module SqlEnumMapper
|
|
20
|
-
def initialize_type_map(m = type_map)
|
|
21
|
-
super(m)
|
|
22
|
-
AbstractMysqlAdapter.register_enum_type(m)
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
ActiveRecord::ConnectionAdapters::Mysql2Adapter.prepend(SqlEnumMapper)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if SqlEnum.rails_version_match?("7.0")
|
|
31
|
-
[
|
|
32
|
-
ActiveRecord::ConnectionAdapters::Mysql2Adapter::TYPE_MAP,
|
|
33
|
-
ActiveRecord::ConnectionAdapters::Mysql2Adapter::TYPE_MAP_WITH_BOOLEAN
|
|
34
|
-
].each do |m|
|
|
35
|
-
AbstractMysqlAdapter.register_enum_type(m)
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
# Rails 7.1 drops the TYPE_MAP_WITH_BOOLEAN constant
|
|
40
|
-
if SqlEnum.rails_version_match?("7.1")
|
|
41
|
-
AbstractMysqlAdapter.register_enum_type(
|
|
42
|
-
ActiveRecord::ConnectionAdapters::Mysql2Adapter::TYPE_MAP
|
|
43
|
-
)
|
|
44
|
-
end
|
|
12
|
+
# Rails 7.1+ uses a single TYPE_MAP constant on the adapter class
|
|
13
|
+
AbstractMysqlAdapter.register_enum_type(
|
|
14
|
+
ActiveRecord::ConnectionAdapters::Mysql2Adapter::TYPE_MAP
|
|
15
|
+
)
|
|
45
16
|
end
|
|
46
17
|
end
|
|
47
18
|
end
|
|
@@ -7,16 +7,17 @@ module ActiveRecord
|
|
|
7
7
|
self.class::NATIVE_DATABASE_TYPES.merge(enum: {name: "enum"})
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
module SqlEnumTypeToSql
|
|
11
|
+
def type_to_sql(type, limit: nil, **)
|
|
12
|
+
if type.to_sym == :enum
|
|
13
|
+
"#{type}(#{limit.map { |n| "'#{n}'" }.join(",")})"
|
|
14
|
+
else
|
|
15
|
+
super
|
|
16
|
+
end
|
|
15
17
|
end
|
|
16
18
|
end
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
alias_method :type_to_sql, :type_to_sql_with_enum
|
|
20
|
+
prepend SqlEnumTypeToSql
|
|
20
21
|
end
|
|
21
22
|
end
|
|
22
23
|
end
|
|
@@ -13,11 +13,20 @@ module SqlEnum
|
|
|
13
13
|
suffix = options.fetch(:_suffix, !!SqlEnum.configuration&.default_suffix)
|
|
14
14
|
|
|
15
15
|
# Define enum using Rails enum
|
|
16
|
-
enum(column_name
|
|
16
|
+
enum(column_name, values_map, prefix: prefix, suffix: suffix)
|
|
17
17
|
|
|
18
18
|
# Override reader to return symbols
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
col_name = column_name.to_s
|
|
20
|
+
enum_type = ->(subtype) do
|
|
21
|
+
subtype = subtype.subtype if ActiveRecord::Enum::EnumType === subtype
|
|
22
|
+
EnumType.new(col_name, send(col_name.pluralize), subtype)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
if respond_to?(:decorate_attributes, true)
|
|
26
|
+
decorate_attributes([col_name]) { |_name, subtype| enum_type.call(subtype) }
|
|
27
|
+
else
|
|
28
|
+
attribute(column_name, &enum_type)
|
|
29
|
+
end
|
|
21
30
|
|
|
22
31
|
prefix_str = format_affix(column_name, prefix, suffix: '_')
|
|
23
32
|
suffix_str = format_affix(column_name, suffix, prefix: '_')
|
data/lib/sql_enum/enum_column.rb
CHANGED
|
@@ -9,15 +9,15 @@ module SqlEnum
|
|
|
9
9
|
private
|
|
10
10
|
|
|
11
11
|
def schema_values
|
|
12
|
-
ActiveRecord::Base.
|
|
12
|
+
if ActiveRecord::Base.respond_to?(:with_connection)
|
|
13
|
+
ActiveRecord::Base.with_connection { |conn| conn.exec_query(schema_values_query).rows.dig(0, 0) }
|
|
14
|
+
else
|
|
15
|
+
ActiveRecord::Base.connection.exec_query(schema_values_query).rows.dig(0, 0)
|
|
16
|
+
end
|
|
13
17
|
end
|
|
14
18
|
|
|
15
19
|
def database_name
|
|
16
|
-
|
|
17
|
-
ActiveRecord::Base.connection_db_config.configuration_hash[:database]
|
|
18
|
-
else
|
|
19
|
-
ActiveRecord::Base.connection_config.values_at(:database, :database_name).find(&:present?)
|
|
20
|
-
end
|
|
20
|
+
ActiveRecord::Base.connection_db_config.configuration_hash[:database]
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def schema_values_query
|
data/lib/sql_enum/version.rb
CHANGED
data/lib/sql_enum.rb
CHANGED
data/sql_enum.gemspec
CHANGED
|
@@ -25,9 +25,11 @@ Gem::Specification.new do |spec|
|
|
|
25
25
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
26
26
|
spec.require_paths = ["lib"]
|
|
27
27
|
|
|
28
|
+
spec.required_ruby_version = ">= 3.2.0"
|
|
29
|
+
|
|
28
30
|
spec.add_dependency "mysql2"
|
|
29
|
-
spec.add_dependency "activesupport", ">=
|
|
30
|
-
spec.add_dependency "activerecord", ">=
|
|
31
|
+
spec.add_dependency "activesupport", ">= 7.1.0"
|
|
32
|
+
spec.add_dependency "activerecord", ">= 7.1.0"
|
|
31
33
|
|
|
32
34
|
spec.add_development_dependency "appraisal"
|
|
33
35
|
spec.add_development_dependency "awesome_print"
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sql_enum
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Fletcher Fowler
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: mysql2
|
|
@@ -30,28 +29,28 @@ dependencies:
|
|
|
30
29
|
requirements:
|
|
31
30
|
- - ">="
|
|
32
31
|
- !ruby/object:Gem::Version
|
|
33
|
-
version:
|
|
32
|
+
version: 7.1.0
|
|
34
33
|
type: :runtime
|
|
35
34
|
prerelease: false
|
|
36
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
36
|
requirements:
|
|
38
37
|
- - ">="
|
|
39
38
|
- !ruby/object:Gem::Version
|
|
40
|
-
version:
|
|
39
|
+
version: 7.1.0
|
|
41
40
|
- !ruby/object:Gem::Dependency
|
|
42
41
|
name: activerecord
|
|
43
42
|
requirement: !ruby/object:Gem::Requirement
|
|
44
43
|
requirements:
|
|
45
44
|
- - ">="
|
|
46
45
|
- !ruby/object:Gem::Version
|
|
47
|
-
version:
|
|
46
|
+
version: 7.1.0
|
|
48
47
|
type: :runtime
|
|
49
48
|
prerelease: false
|
|
50
49
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
50
|
requirements:
|
|
52
51
|
- - ">="
|
|
53
52
|
- !ruby/object:Gem::Version
|
|
54
|
-
version:
|
|
53
|
+
version: 7.1.0
|
|
55
54
|
- !ruby/object:Gem::Dependency
|
|
56
55
|
name: appraisal
|
|
57
56
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -136,7 +135,6 @@ dependencies:
|
|
|
136
135
|
- - "~>"
|
|
137
136
|
- !ruby/object:Gem::Version
|
|
138
137
|
version: '3.0'
|
|
139
|
-
description:
|
|
140
138
|
email:
|
|
141
139
|
- fletch@fzf.me
|
|
142
140
|
executables: []
|
|
@@ -160,9 +158,10 @@ files:
|
|
|
160
158
|
- bin/console
|
|
161
159
|
- bin/setup
|
|
162
160
|
- docker-compose.yml
|
|
163
|
-
- gemfiles/rails_6.1.gemfile
|
|
164
|
-
- gemfiles/rails_7.0.gemfile
|
|
165
161
|
- gemfiles/rails_7.1.gemfile
|
|
162
|
+
- gemfiles/rails_7.2.gemfile
|
|
163
|
+
- gemfiles/rails_8.0.gemfile
|
|
164
|
+
- gemfiles/rails_8.1.gemfile
|
|
166
165
|
- lib/active_record/connection_adapters/abstract_mysql.rb
|
|
167
166
|
- lib/active_record/connection_adapters/mysql/column_methods.rb
|
|
168
167
|
- lib/active_record/connection_adapters/mysql2.rb
|
|
@@ -181,7 +180,6 @@ licenses:
|
|
|
181
180
|
metadata:
|
|
182
181
|
homepage_uri: https://github.com/1debit/sql_enum
|
|
183
182
|
source_code_uri: https://github.com/1debit/sql_enum
|
|
184
|
-
post_install_message:
|
|
185
183
|
rdoc_options: []
|
|
186
184
|
require_paths:
|
|
187
185
|
- lib
|
|
@@ -189,15 +187,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
189
187
|
requirements:
|
|
190
188
|
- - ">="
|
|
191
189
|
- !ruby/object:Gem::Version
|
|
192
|
-
version:
|
|
190
|
+
version: 3.2.0
|
|
193
191
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
194
192
|
requirements:
|
|
195
193
|
- - ">="
|
|
196
194
|
- !ruby/object:Gem::Version
|
|
197
195
|
version: '0'
|
|
198
196
|
requirements: []
|
|
199
|
-
rubygems_version: 3.
|
|
200
|
-
signing_key:
|
|
197
|
+
rubygems_version: 3.6.7
|
|
201
198
|
specification_version: 4
|
|
202
199
|
summary: Enable using native sql enums
|
|
203
200
|
test_files: []
|