activerecord-pg_enum 1.0.3 → 1.2.1

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: 552cd4fa6b85fd2002965150aca5e1f92f9752bfce9ab6628241dce0ef40406f
4
- data.tar.gz: b7915cd86940a3f2c5b2e9053712369f639073e22123b7a3a173f5403539aca1
3
+ metadata.gz: b134179642533a863076d742b3650d8206950d606059ac10be38d38bdee70789
4
+ data.tar.gz: d10ed445144b43dd6e0f9fd06997b198fd80b49411917a26014bc65539b60426
5
5
  SHA512:
6
- metadata.gz: 5b48750e4060fb131d1099ddf2198362e750901873e590ca488cb376e99ef30ab09c11857d9aa91ae9e0caea2903367a97bb34073f31f1ee1a9c4377cf9a27a5
7
- data.tar.gz: 66fc8ee9467a8dc96445e5e5f8fdab62b77ad4740086b17fa1d3a673415c657f3fdccf5cc09898f8153534951ccfa88b644359b7ebb2ccb81fd187e5465b4655
6
+ metadata.gz: 37b15da659116a26e3e94097a5ccf698dc1cfcdc59fe2aa8ab20f8a2402bf8534a4bbc373cbaadbd18b585da420e1f14ea7f944f3400e759f7a9d4a80230cfae
7
+ data.tar.gz: 379a854b1d0a307ebfcb6a02f4cf4eb75135c941d6beda0e5ba53eb067a14398379e9102af6d76b2ac7116f896b5ba61a61fab0948a953ba1200d7436eb57eb1
@@ -15,6 +15,8 @@ matrix:
15
15
  gemfile: gemfiles/5.2.gemfile
16
16
  - rvm: 2.6.0
17
17
  gemfile: gemfiles/6.0.gemfile
18
+ - rvm: 2.7.0
19
+ gemfile: gemfiles/6.1.gemfile
18
20
  - rvm: ruby-head
19
21
  gemfile: gemfiles/edge.gemfile
20
22
  allow_failures:
@@ -22,7 +24,7 @@ matrix:
22
24
  services:
23
25
  - postgresql
24
26
  addons:
25
- postgresql: "9.6"
27
+ postgresql: "10"
26
28
  before_install: gem install bundler -v 1.17.3
27
29
  script: "bundle exec rake spec"
28
30
  env:
data/Appraisals CHANGED
@@ -1,5 +1,9 @@
1
+ appraise "6.1" do
2
+ gem "activerecord", "~> 6.1"
3
+ end
4
+
1
5
  appraise "6.0" do
2
- gem "activerecord", "6.0.0"
6
+ gem "activerecord", "~> 6.0"
3
7
  end
4
8
 
5
9
  appraise "5.2" do
@@ -6,6 +6,31 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.2.1] - 2021-01-05
10
+ ### Fixed
11
+ - Argument bug that surfaced in Ruby 3.0
12
+
13
+ ## [1.2.0] - 2020-12-09
14
+ ### Added
15
+ - Support for 6.1
16
+
17
+ ## [1.1.0] - 2020-01-18
18
+ ### Added
19
+ - `rename_enum` command for changing the type name
20
+ - `rename_enum_value` command for changing an enum label (PostgreSQL 10+ only)
21
+
22
+ ### Changed
23
+ - Refactored some code to eliminate deprecation warnings in 2.7 related to kwargs
24
+
25
+ ## [1.0.5] - 2019-11-22
26
+ ### Fixed
27
+ - Don't include schema name in dumped enum types to be consistent with the way tables are dumped (@TylerRick)
28
+
29
+ ## [1.0.4] - 2019-11-16
30
+ ### Fixed
31
+ - Dump enums declared in non-public schemas
32
+ - Fix missing `enum` method with using `change_table`
33
+
9
34
  ## [1.0.3] - 2019-10-13
10
35
  ### Fixed
11
36
  - Allow enum labels to contain spaces (@AndrewSpeed)
data/README.md CHANGED
@@ -117,6 +117,36 @@ class AddStatusToOrder < ActiveRecord::Migration[5.2]
117
117
  end
118
118
  ```
119
119
 
120
+ Renaming an enum type
121
+
122
+ ```ruby
123
+ class RenameStatusType < ActiveRecord::Migration[6.0]
124
+ def change
125
+ rename_enum "status_type", to: "order_status_type"
126
+ end
127
+ end
128
+ ```
129
+
130
+ ```SQL
131
+ ALTER TYPE status_type RENAME TO order_status_type;
132
+ ```
133
+
134
+ **PostgreSQL 10+ required**:
135
+
136
+ Changing an enum label
137
+
138
+ ```ruby
139
+ class ChangeStatusHoldLabel < ActiveRecord::Migration[6.0]
140
+ def change
141
+ rename_enum_value "status_type", from: "on hold", to: "OnHold"
142
+ end
143
+ end
144
+ ```
145
+
146
+ ```SQL
147
+ ALTER TYPE status_type RENAME VALUE 'on hold' TO 'OnHold';
148
+ ```
149
+
120
150
  ### Module Builder
121
151
 
122
152
  ```ruby
@@ -133,6 +163,20 @@ class ContactInfo < ActiveRecord::Base
133
163
  end
134
164
  ```
135
165
 
166
+ Additionally, `enum` options are fully supported, for example
167
+ ```ruby
168
+ class User < ActiveRecord::Base
169
+ include PGEnum(status: %w[active inactive deleted], _prefix: 'user', _suffix: true)
170
+ end
171
+ ```
172
+
173
+ is equivalent to
174
+ ```ruby
175
+ class User < ActiveRecord::Base
176
+ enum status: { active: 'active', inactive: 'inactive', deleted: 'deleted' }, _prefix: 'user', _suffix: true
177
+ end
178
+ ```
179
+
136
180
  There's no technical reason why you couldn't detect enum columns at startup time and automatically do this wireup, but I feel that the benefit of self-documenting outweighs the convenience.
137
181
 
138
182
  ## Development
data/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
3
  require "appraisal"
4
+ require "pry"
4
5
 
5
6
  if !ENV["APPRAISAL_INITIALIZED"] && !ENV["TRAVIS"]
6
7
  task :default => :appraisal
@@ -10,13 +11,15 @@ end
10
11
 
11
12
  task :connection do
12
13
  require "active_record"
14
+ require_relative "spec/support/connection_config"
13
15
 
14
- ActiveRecord::Base.establish_connection(
15
- adapter: "postgresql",
16
- port: ENV.fetch("PGPORT", "5432"),
17
- username: ENV.fetch("TEST_USER") { ENV.fetch("USER", "pg_enum") },
18
- password: ENV["TEST_PASSWORD"]
19
- )
16
+ config = db_config_hash.except(:database)
17
+
18
+ if ActiveRecord.constants.include?(:DatabaseConfigurations)
19
+ config = ActiveRecord::DatabaseConfigurations::HashConfig.new("test", "primary", config)
20
+ end
21
+
22
+ ActiveRecord::Base.establish_connection(config)
20
23
  end
21
24
 
22
25
  namespace :spec do
@@ -35,6 +38,8 @@ namespace :spec do
35
38
  conn.drop_database ENV.fetch("TEST_DATABASE", "pg_enum_test")
36
39
  end
37
40
  end
41
+
42
+ task reset: [:teardown, :setup]
38
43
  end
39
44
 
40
45
  task spec: %w[spec:setup spec:run spec:teardown]
@@ -36,7 +36,7 @@ Gem::Specification.new do |spec|
36
36
  spec.add_dependency "activesupport"
37
37
 
38
38
  spec.add_development_dependency "appraisal"
39
- spec.add_development_dependency "bundler", "~> 1.15"
39
+ spec.add_development_dependency "bundler", "~> 1.17"
40
40
  spec.add_development_dependency "rake", "~> 10.0"
41
41
  spec.add_development_dependency "rspec", "~> 3.0"
42
42
  spec.add_development_dependency "pry"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- activerecord-pg_enum (1.0.3)
4
+ activerecord-pg_enum (1.2.0)
5
5
  activerecord (>= 4.1.0)
6
6
  activesupport
7
7
  pg
@@ -27,15 +27,15 @@ GEM
27
27
  rake
28
28
  thor (>= 0.14.0)
29
29
  arel (5.0.1.20140414130214)
30
- builder (3.2.3)
30
+ builder (3.2.4)
31
31
  coderay (1.1.2)
32
- concurrent-ruby (1.1.5)
32
+ concurrent-ruby (1.1.7)
33
33
  diff-lcs (1.3)
34
34
  i18n (0.9.5)
35
35
  concurrent-ruby (~> 1.0)
36
36
  json (1.8.6)
37
37
  method_source (0.9.2)
38
- minitest (5.11.3)
38
+ minitest (5.14.2)
39
39
  pg (0.21.0)
40
40
  pry (0.12.2)
41
41
  coderay (~> 1.1.0)
@@ -56,7 +56,7 @@ GEM
56
56
  rspec-support (3.8.2)
57
57
  thor (0.20.3)
58
58
  thread_safe (0.3.6)
59
- tzinfo (1.2.5)
59
+ tzinfo (1.2.8)
60
60
  thread_safe (~> 0.1)
61
61
 
62
62
  PLATFORMS
@@ -66,7 +66,7 @@ DEPENDENCIES
66
66
  activerecord (>= 4.1.0, < 4.2.0)
67
67
  activerecord-pg_enum!
68
68
  appraisal
69
- bundler (~> 1.15)
69
+ bundler (~> 1.17)
70
70
  i18n (~> 0.7)
71
71
  pg (~> 0.15)
72
72
  pry
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- activerecord-pg_enum (1.0.3)
4
+ activerecord-pg_enum (1.2.0)
5
5
  activerecord (>= 4.1.0)
6
6
  activesupport
7
7
  pg
@@ -9,14 +9,14 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activemodel (4.2.11.1)
13
- activesupport (= 4.2.11.1)
12
+ activemodel (4.2.11.3)
13
+ activesupport (= 4.2.11.3)
14
14
  builder (~> 3.1)
15
- activerecord (4.2.11.1)
16
- activemodel (= 4.2.11.1)
17
- activesupport (= 4.2.11.1)
15
+ activerecord (4.2.11.3)
16
+ activemodel (= 4.2.11.3)
17
+ activesupport (= 4.2.11.3)
18
18
  arel (~> 6.0)
19
- activesupport (4.2.11.1)
19
+ activesupport (4.2.11.3)
20
20
  i18n (~> 0.7)
21
21
  minitest (~> 5.1)
22
22
  thread_safe (~> 0.3, >= 0.3.4)
@@ -26,14 +26,14 @@ GEM
26
26
  rake
27
27
  thor (>= 0.14.0)
28
28
  arel (6.0.4)
29
- builder (3.2.3)
29
+ builder (3.2.4)
30
30
  coderay (1.1.2)
31
- concurrent-ruby (1.1.5)
31
+ concurrent-ruby (1.1.7)
32
32
  diff-lcs (1.3)
33
33
  i18n (0.9.5)
34
34
  concurrent-ruby (~> 1.0)
35
35
  method_source (0.9.2)
36
- minitest (5.11.3)
36
+ minitest (5.14.2)
37
37
  pg (0.21.0)
38
38
  pry (0.12.2)
39
39
  coderay (~> 1.1.0)
@@ -54,7 +54,7 @@ GEM
54
54
  rspec-support (3.8.2)
55
55
  thor (0.20.3)
56
56
  thread_safe (0.3.6)
57
- tzinfo (1.2.5)
57
+ tzinfo (1.2.8)
58
58
  thread_safe (~> 0.1)
59
59
 
60
60
  PLATFORMS
@@ -64,7 +64,7 @@ DEPENDENCIES
64
64
  activerecord (>= 4.2.0, < 5.0.0)
65
65
  activerecord-pg_enum!
66
66
  appraisal
67
- bundler (~> 1.15)
67
+ bundler (~> 1.17)
68
68
  i18n (~> 0.7)
69
69
  pg (~> 0.15)
70
70
  pry
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- activerecord-pg_enum (1.0.3)
4
+ activerecord-pg_enum (1.2.0)
5
5
  activerecord (>= 4.1.0)
6
6
  activesupport
7
7
  pg
@@ -9,13 +9,13 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activemodel (5.0.7.1)
13
- activesupport (= 5.0.7.1)
14
- activerecord (5.0.7.1)
15
- activemodel (= 5.0.7.1)
16
- activesupport (= 5.0.7.1)
12
+ activemodel (5.0.7.2)
13
+ activesupport (= 5.0.7.2)
14
+ activerecord (5.0.7.2)
15
+ activemodel (= 5.0.7.2)
16
+ activesupport (= 5.0.7.2)
17
17
  arel (~> 7.0)
18
- activesupport (5.0.7.1)
18
+ activesupport (5.0.7.2)
19
19
  concurrent-ruby (~> 1.0, >= 1.0.2)
20
20
  i18n (>= 0.7, < 2)
21
21
  minitest (~> 5.1)
@@ -26,13 +26,13 @@ GEM
26
26
  thor (>= 0.14.0)
27
27
  arel (7.1.4)
28
28
  coderay (1.1.2)
29
- concurrent-ruby (1.1.4)
29
+ concurrent-ruby (1.1.7)
30
30
  diff-lcs (1.3)
31
31
  i18n (1.5.1)
32
32
  concurrent-ruby (~> 1.0)
33
33
  method_source (0.9.2)
34
- minitest (5.11.3)
35
- pg (1.1.4)
34
+ minitest (5.14.2)
35
+ pg (1.2.3)
36
36
  pry (0.12.2)
37
37
  coderay (~> 1.1.0)
38
38
  method_source (~> 0.9.0)
@@ -52,7 +52,7 @@ GEM
52
52
  rspec-support (3.8.0)
53
53
  thor (0.20.3)
54
54
  thread_safe (0.3.6)
55
- tzinfo (1.2.5)
55
+ tzinfo (1.2.8)
56
56
  thread_safe (~> 0.1)
57
57
 
58
58
  PLATFORMS
@@ -62,7 +62,7 @@ DEPENDENCIES
62
62
  activerecord (>= 5.0.0, < 5.1.0)
63
63
  activerecord-pg_enum!
64
64
  appraisal
65
- bundler (~> 1.15)
65
+ bundler (~> 1.17)
66
66
  i18n (= 1.5.1)
67
67
  pry
68
68
  rake (~> 10.0)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- activerecord-pg_enum (1.0.3)
4
+ activerecord-pg_enum (1.2.0)
5
5
  activerecord (>= 4.1.0)
6
6
  activesupport
7
7
  pg
@@ -9,13 +9,13 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activemodel (5.1.6)
13
- activesupport (= 5.1.6)
14
- activerecord (5.1.6)
15
- activemodel (= 5.1.6)
16
- activesupport (= 5.1.6)
12
+ activemodel (5.1.7)
13
+ activesupport (= 5.1.7)
14
+ activerecord (5.1.7)
15
+ activemodel (= 5.1.7)
16
+ activesupport (= 5.1.7)
17
17
  arel (~> 8.0)
18
- activesupport (5.1.6)
18
+ activesupport (5.1.7)
19
19
  concurrent-ruby (~> 1.0, >= 1.0.2)
20
20
  i18n (>= 0.7, < 2)
21
21
  minitest (~> 5.1)
@@ -26,13 +26,13 @@ GEM
26
26
  thor (>= 0.14.0)
27
27
  arel (8.0.0)
28
28
  coderay (1.1.2)
29
- concurrent-ruby (1.0.5)
29
+ concurrent-ruby (1.1.7)
30
30
  diff-lcs (1.3)
31
- i18n (1.1.0)
31
+ i18n (1.8.5)
32
32
  concurrent-ruby (~> 1.0)
33
33
  method_source (0.9.0)
34
- minitest (5.11.3)
35
- pg (1.1.4)
34
+ minitest (5.14.2)
35
+ pg (1.2.3)
36
36
  pry (0.11.3)
37
37
  coderay (~> 1.1.0)
38
38
  method_source (~> 0.9.0)
@@ -52,7 +52,7 @@ GEM
52
52
  rspec-support (3.8.0)
53
53
  thor (0.20.0)
54
54
  thread_safe (0.3.6)
55
- tzinfo (1.2.5)
55
+ tzinfo (1.2.8)
56
56
  thread_safe (~> 0.1)
57
57
 
58
58
  PLATFORMS
@@ -62,7 +62,7 @@ DEPENDENCIES
62
62
  activerecord (>= 5.1.0, < 5.2.0)
63
63
  activerecord-pg_enum!
64
64
  appraisal
65
- bundler (~> 1.15)
65
+ bundler (~> 1.17)
66
66
  pry
67
67
  rake (~> 10.0)
68
68
  rspec (~> 3.0)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- activerecord-pg_enum (1.0.3)
4
+ activerecord-pg_enum (1.2.0)
5
5
  activerecord (>= 4.1.0)
6
6
  activesupport
7
7
  pg
@@ -9,13 +9,13 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activemodel (5.2.1)
13
- activesupport (= 5.2.1)
14
- activerecord (5.2.1)
15
- activemodel (= 5.2.1)
16
- activesupport (= 5.2.1)
12
+ activemodel (5.2.4.4)
13
+ activesupport (= 5.2.4.4)
14
+ activerecord (5.2.4.4)
15
+ activemodel (= 5.2.4.4)
16
+ activesupport (= 5.2.4.4)
17
17
  arel (>= 9.0)
18
- activesupport (5.2.1)
18
+ activesupport (5.2.4.4)
19
19
  concurrent-ruby (~> 1.0, >= 1.0.2)
20
20
  i18n (>= 0.7, < 2)
21
21
  minitest (~> 5.1)
@@ -26,13 +26,13 @@ GEM
26
26
  thor (>= 0.14.0)
27
27
  arel (9.0.0)
28
28
  coderay (1.1.2)
29
- concurrent-ruby (1.0.5)
29
+ concurrent-ruby (1.1.7)
30
30
  diff-lcs (1.3)
31
- i18n (1.1.0)
31
+ i18n (1.8.5)
32
32
  concurrent-ruby (~> 1.0)
33
33
  method_source (0.9.0)
34
- minitest (5.11.3)
35
- pg (1.1.4)
34
+ minitest (5.14.2)
35
+ pg (1.2.3)
36
36
  pry (0.11.3)
37
37
  coderay (~> 1.1.0)
38
38
  method_source (~> 0.9.0)
@@ -52,7 +52,7 @@ GEM
52
52
  rspec-support (3.8.0)
53
53
  thor (0.20.0)
54
54
  thread_safe (0.3.6)
55
- tzinfo (1.2.5)
55
+ tzinfo (1.2.8)
56
56
  thread_safe (~> 0.1)
57
57
 
58
58
  PLATFORMS
@@ -62,7 +62,7 @@ DEPENDENCIES
62
62
  activerecord (~> 5.2)
63
63
  activerecord-pg_enum!
64
64
  appraisal
65
- bundler (~> 1.15)
65
+ bundler (~> 1.17)
66
66
  pry
67
67
  rake (~> 10.0)
68
68
  rspec (~> 3.0)
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "6.0.0"
5
+ gem "activerecord", "< 6.1"
6
6
 
7
7
  gemspec path: "../"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- activerecord-pg_enum (1.0.3)
4
+ activerecord-pg_enum (1.2.0)
5
5
  activerecord (>= 4.1.0)
6
6
  activesupport
7
7
  pg
@@ -9,29 +9,29 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activemodel (6.0.0)
13
- activesupport (= 6.0.0)
14
- activerecord (6.0.0)
15
- activemodel (= 6.0.0)
16
- activesupport (= 6.0.0)
17
- activesupport (6.0.0)
12
+ activemodel (6.0.3.4)
13
+ activesupport (= 6.0.3.4)
14
+ activerecord (6.0.3.4)
15
+ activemodel (= 6.0.3.4)
16
+ activesupport (= 6.0.3.4)
17
+ activesupport (6.0.3.4)
18
18
  concurrent-ruby (~> 1.0, >= 1.0.2)
19
19
  i18n (>= 0.7, < 2)
20
20
  minitest (~> 5.1)
21
21
  tzinfo (~> 1.1)
22
- zeitwerk (~> 2.1, >= 2.1.8)
22
+ zeitwerk (~> 2.2, >= 2.2.2)
23
23
  appraisal (2.2.0)
24
24
  bundler
25
25
  rake
26
26
  thor (>= 0.14.0)
27
27
  coderay (1.1.2)
28
- concurrent-ruby (1.1.5)
28
+ concurrent-ruby (1.1.7)
29
29
  diff-lcs (1.3)
30
- i18n (1.6.0)
30
+ i18n (1.8.5)
31
31
  concurrent-ruby (~> 1.0)
32
32
  method_source (0.9.2)
33
- minitest (5.11.3)
34
- pg (1.1.4)
33
+ minitest (5.14.2)
34
+ pg (1.2.3)
35
35
  pry (0.12.2)
36
36
  coderay (~> 1.1.0)
37
37
  method_source (~> 0.9.0)
@@ -51,18 +51,18 @@ GEM
51
51
  rspec-support (3.8.2)
52
52
  thor (0.20.3)
53
53
  thread_safe (0.3.6)
54
- tzinfo (1.2.5)
54
+ tzinfo (1.2.8)
55
55
  thread_safe (~> 0.1)
56
- zeitwerk (2.1.9)
56
+ zeitwerk (2.4.2)
57
57
 
58
58
  PLATFORMS
59
59
  ruby
60
60
 
61
61
  DEPENDENCIES
62
- activerecord (= 6.0.0)
62
+ activerecord (< 6.1)
63
63
  activerecord-pg_enum!
64
64
  appraisal
65
- bundler (~> 1.15)
65
+ bundler (~> 1.17)
66
66
  pry
67
67
  rake (~> 10.0)
68
68
  rspec (~> 3.0)
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 6.1"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,70 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ activerecord-pg_enum (1.2.0)
5
+ activerecord (>= 4.1.0)
6
+ activesupport
7
+ pg
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activemodel (6.1.0)
13
+ activesupport (= 6.1.0)
14
+ activerecord (6.1.0)
15
+ activemodel (= 6.1.0)
16
+ activesupport (= 6.1.0)
17
+ activesupport (6.1.0)
18
+ concurrent-ruby (~> 1.0, >= 1.0.2)
19
+ i18n (>= 1.6, < 2)
20
+ minitest (>= 5.1)
21
+ tzinfo (~> 2.0)
22
+ zeitwerk (~> 2.3)
23
+ appraisal (2.3.0)
24
+ bundler
25
+ rake
26
+ thor (>= 0.14.0)
27
+ coderay (1.1.3)
28
+ concurrent-ruby (1.1.7)
29
+ diff-lcs (1.4.4)
30
+ i18n (1.8.5)
31
+ concurrent-ruby (~> 1.0)
32
+ method_source (1.0.0)
33
+ minitest (5.14.2)
34
+ pg (1.2.3)
35
+ pry (0.13.1)
36
+ coderay (~> 1.1)
37
+ method_source (~> 1.0)
38
+ rake (10.5.0)
39
+ rspec (3.10.0)
40
+ rspec-core (~> 3.10.0)
41
+ rspec-expectations (~> 3.10.0)
42
+ rspec-mocks (~> 3.10.0)
43
+ rspec-core (3.10.0)
44
+ rspec-support (~> 3.10.0)
45
+ rspec-expectations (3.10.0)
46
+ diff-lcs (>= 1.2.0, < 2.0)
47
+ rspec-support (~> 3.10.0)
48
+ rspec-mocks (3.10.0)
49
+ diff-lcs (>= 1.2.0, < 2.0)
50
+ rspec-support (~> 3.10.0)
51
+ rspec-support (3.10.0)
52
+ thor (1.0.1)
53
+ tzinfo (2.0.3)
54
+ concurrent-ruby (~> 1.0)
55
+ zeitwerk (2.4.2)
56
+
57
+ PLATFORMS
58
+ ruby
59
+
60
+ DEPENDENCIES
61
+ activerecord (~> 6.1)
62
+ activerecord-pg_enum!
63
+ appraisal
64
+ bundler (~> 1.17)
65
+ pry
66
+ rake (~> 10.0)
67
+ rspec (~> 3.0)
68
+
69
+ BUNDLED WITH
70
+ 1.17.3
@@ -1,72 +1,93 @@
1
1
  GIT
2
2
  remote: https://github.com/rails/rails.git
3
- revision: dc796a0d407dfaf84abd464fc1aa2966cddb51e0
3
+ revision: 46337faa795fa40dedb1b9b906bec1793358d7f3
4
4
  branch: master
5
5
  specs:
6
- actioncable (6.0.0.alpha)
7
- actionpack (= 6.0.0.alpha)
6
+ actioncable (6.2.0.alpha)
7
+ actionpack (= 6.2.0.alpha)
8
+ activesupport (= 6.2.0.alpha)
8
9
  nio4r (~> 2.0)
9
10
  websocket-driver (>= 0.6.1)
10
- actionmailer (6.0.0.alpha)
11
- actionpack (= 6.0.0.alpha)
12
- actionview (= 6.0.0.alpha)
13
- activejob (= 6.0.0.alpha)
11
+ actionmailbox (6.2.0.alpha)
12
+ actionpack (= 6.2.0.alpha)
13
+ activejob (= 6.2.0.alpha)
14
+ activerecord (= 6.2.0.alpha)
15
+ activestorage (= 6.2.0.alpha)
16
+ activesupport (= 6.2.0.alpha)
17
+ mail (>= 2.7.1)
18
+ actionmailer (6.2.0.alpha)
19
+ actionpack (= 6.2.0.alpha)
20
+ actionview (= 6.2.0.alpha)
21
+ activejob (= 6.2.0.alpha)
22
+ activesupport (= 6.2.0.alpha)
14
23
  mail (~> 2.5, >= 2.5.4)
15
24
  rails-dom-testing (~> 2.0)
16
- actionpack (6.0.0.alpha)
17
- actionview (= 6.0.0.alpha)
18
- activesupport (= 6.0.0.alpha)
19
- rack (~> 2.0)
25
+ actionpack (6.2.0.alpha)
26
+ actionview (= 6.2.0.alpha)
27
+ activesupport (= 6.2.0.alpha)
28
+ rack (~> 2.0, >= 2.0.9)
20
29
  rack-test (>= 0.6.3)
21
30
  rails-dom-testing (~> 2.0)
22
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
23
- actionview (6.0.0.alpha)
24
- activesupport (= 6.0.0.alpha)
31
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
32
+ actiontext (6.2.0.alpha)
33
+ actionpack (= 6.2.0.alpha)
34
+ activerecord (= 6.2.0.alpha)
35
+ activestorage (= 6.2.0.alpha)
36
+ activesupport (= 6.2.0.alpha)
37
+ nokogiri (>= 1.8.5)
38
+ actionview (6.2.0.alpha)
39
+ activesupport (= 6.2.0.alpha)
25
40
  builder (~> 3.1)
26
41
  erubi (~> 1.4)
27
42
  rails-dom-testing (~> 2.0)
28
- rails-html-sanitizer (~> 1.0, >= 1.0.3)
29
- activejob (6.0.0.alpha)
30
- activesupport (= 6.0.0.alpha)
43
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
44
+ activejob (6.2.0.alpha)
45
+ activesupport (= 6.2.0.alpha)
31
46
  globalid (>= 0.3.6)
32
- activemodel (6.0.0.alpha)
33
- activesupport (= 6.0.0.alpha)
34
- activerecord (6.0.0.alpha)
35
- activemodel (= 6.0.0.alpha)
36
- activesupport (= 6.0.0.alpha)
37
- activestorage (6.0.0.alpha)
38
- actionpack (= 6.0.0.alpha)
39
- activerecord (= 6.0.0.alpha)
47
+ activemodel (6.2.0.alpha)
48
+ activesupport (= 6.2.0.alpha)
49
+ activerecord (6.2.0.alpha)
50
+ activemodel (= 6.2.0.alpha)
51
+ activesupport (= 6.2.0.alpha)
52
+ activestorage (6.2.0.alpha)
53
+ actionpack (= 6.2.0.alpha)
54
+ activejob (= 6.2.0.alpha)
55
+ activerecord (= 6.2.0.alpha)
56
+ activesupport (= 6.2.0.alpha)
40
57
  marcel (~> 0.3.1)
41
- activesupport (6.0.0.alpha)
58
+ mimemagic (~> 0.3.2)
59
+ activesupport (6.2.0.alpha)
42
60
  concurrent-ruby (~> 1.0, >= 1.0.2)
43
- i18n (>= 0.7, < 2)
44
- minitest (~> 5.1)
45
- tzinfo (~> 1.1)
46
- rails (6.0.0.alpha)
47
- actioncable (= 6.0.0.alpha)
48
- actionmailer (= 6.0.0.alpha)
49
- actionpack (= 6.0.0.alpha)
50
- actionview (= 6.0.0.alpha)
51
- activejob (= 6.0.0.alpha)
52
- activemodel (= 6.0.0.alpha)
53
- activerecord (= 6.0.0.alpha)
54
- activestorage (= 6.0.0.alpha)
55
- activesupport (= 6.0.0.alpha)
56
- bundler (>= 1.3.0)
57
- railties (= 6.0.0.alpha)
61
+ i18n (>= 1.6, < 2)
62
+ minitest (>= 5.1)
63
+ tzinfo (~> 2.0)
64
+ zeitwerk (~> 2.3)
65
+ rails (6.2.0.alpha)
66
+ actioncable (= 6.2.0.alpha)
67
+ actionmailbox (= 6.2.0.alpha)
68
+ actionmailer (= 6.2.0.alpha)
69
+ actionpack (= 6.2.0.alpha)
70
+ actiontext (= 6.2.0.alpha)
71
+ actionview (= 6.2.0.alpha)
72
+ activejob (= 6.2.0.alpha)
73
+ activemodel (= 6.2.0.alpha)
74
+ activerecord (= 6.2.0.alpha)
75
+ activestorage (= 6.2.0.alpha)
76
+ activesupport (= 6.2.0.alpha)
77
+ bundler (>= 1.15.0)
78
+ railties (= 6.2.0.alpha)
58
79
  sprockets-rails (>= 2.0.0)
59
- railties (6.0.0.alpha)
60
- actionpack (= 6.0.0.alpha)
61
- activesupport (= 6.0.0.alpha)
80
+ railties (6.2.0.alpha)
81
+ actionpack (= 6.2.0.alpha)
82
+ activesupport (= 6.2.0.alpha)
62
83
  method_source
63
84
  rake (>= 0.8.7)
64
- thor (>= 0.19.0, < 2.0)
85
+ thor (~> 1.0)
65
86
 
66
87
  PATH
67
88
  remote: ..
68
89
  specs:
69
- activerecord-pg_enum (1.0.3)
90
+ activerecord-pg_enum (1.2.0)
70
91
  activerecord (>= 4.1.0)
71
92
  activesupport
72
93
  pg
@@ -74,75 +95,75 @@ PATH
74
95
  GEM
75
96
  remote: https://rubygems.org/
76
97
  specs:
77
- appraisal (2.2.0)
98
+ appraisal (2.3.0)
78
99
  bundler
79
100
  rake
80
101
  thor (>= 0.14.0)
81
- builder (3.2.3)
82
- coderay (1.1.2)
83
- concurrent-ruby (1.0.5)
84
- crass (1.0.4)
85
- diff-lcs (1.3)
86
- erubi (1.7.1)
87
- globalid (0.4.1)
102
+ builder (3.2.4)
103
+ coderay (1.1.3)
104
+ concurrent-ruby (1.1.7)
105
+ crass (1.0.6)
106
+ diff-lcs (1.4.4)
107
+ erubi (1.10.0)
108
+ globalid (0.4.2)
88
109
  activesupport (>= 4.2.0)
89
- i18n (1.1.0)
110
+ i18n (1.8.5)
90
111
  concurrent-ruby (~> 1.0)
91
- loofah (2.2.2)
112
+ loofah (2.8.0)
92
113
  crass (~> 1.0.2)
93
114
  nokogiri (>= 1.5.9)
94
- mail (2.7.0)
115
+ mail (2.7.1)
95
116
  mini_mime (>= 0.1.1)
96
- marcel (0.3.2)
117
+ marcel (0.3.3)
97
118
  mimemagic (~> 0.3.2)
98
- method_source (0.9.0)
99
- mimemagic (0.3.2)
100
- mini_mime (1.0.1)
101
- mini_portile2 (2.3.0)
102
- minitest (5.11.3)
103
- nio4r (2.3.1)
104
- nokogiri (1.8.4)
105
- mini_portile2 (~> 2.3.0)
106
- pg (1.1.4)
107
- pry (0.11.3)
108
- coderay (~> 1.1.0)
109
- method_source (~> 0.9.0)
110
- rack (2.0.5)
119
+ method_source (1.0.0)
120
+ mimemagic (0.3.5)
121
+ mini_mime (1.0.2)
122
+ mini_portile2 (2.4.0)
123
+ minitest (5.14.2)
124
+ nio4r (2.5.4)
125
+ nokogiri (1.10.10)
126
+ mini_portile2 (~> 2.4.0)
127
+ pg (1.2.3)
128
+ pry (0.13.1)
129
+ coderay (~> 1.1)
130
+ method_source (~> 1.0)
131
+ rack (2.2.3)
111
132
  rack-test (1.1.0)
112
133
  rack (>= 1.0, < 3)
113
134
  rails-dom-testing (2.0.3)
114
135
  activesupport (>= 4.2.0)
115
136
  nokogiri (>= 1.6)
116
- rails-html-sanitizer (1.0.4)
117
- loofah (~> 2.2, >= 2.2.2)
137
+ rails-html-sanitizer (1.3.0)
138
+ loofah (~> 2.3)
118
139
  rake (10.5.0)
119
- rspec (3.8.0)
120
- rspec-core (~> 3.8.0)
121
- rspec-expectations (~> 3.8.0)
122
- rspec-mocks (~> 3.8.0)
123
- rspec-core (3.8.0)
124
- rspec-support (~> 3.8.0)
125
- rspec-expectations (3.8.1)
140
+ rspec (3.10.0)
141
+ rspec-core (~> 3.10.0)
142
+ rspec-expectations (~> 3.10.0)
143
+ rspec-mocks (~> 3.10.0)
144
+ rspec-core (3.10.0)
145
+ rspec-support (~> 3.10.0)
146
+ rspec-expectations (3.10.0)
126
147
  diff-lcs (>= 1.2.0, < 2.0)
127
- rspec-support (~> 3.8.0)
128
- rspec-mocks (3.8.0)
148
+ rspec-support (~> 3.10.0)
149
+ rspec-mocks (3.10.0)
129
150
  diff-lcs (>= 1.2.0, < 2.0)
130
- rspec-support (~> 3.8.0)
131
- rspec-support (3.8.0)
132
- sprockets (3.7.2)
151
+ rspec-support (~> 3.10.0)
152
+ rspec-support (3.10.0)
153
+ sprockets (4.0.2)
133
154
  concurrent-ruby (~> 1.0)
134
155
  rack (> 1, < 3)
135
- sprockets-rails (3.2.1)
156
+ sprockets-rails (3.2.2)
136
157
  actionpack (>= 4.0)
137
158
  activesupport (>= 4.0)
138
159
  sprockets (>= 3.0.0)
139
- thor (0.20.0)
140
- thread_safe (0.3.6)
141
- tzinfo (1.2.5)
142
- thread_safe (~> 0.1)
143
- websocket-driver (0.7.0)
160
+ thor (1.0.1)
161
+ tzinfo (2.0.3)
162
+ concurrent-ruby (~> 1.0)
163
+ websocket-driver (0.7.3)
144
164
  websocket-extensions (>= 0.1.0)
145
- websocket-extensions (0.1.3)
165
+ websocket-extensions (0.1.5)
166
+ zeitwerk (2.4.2)
146
167
 
147
168
  PLATFORMS
148
169
  ruby
@@ -150,7 +171,7 @@ PLATFORMS
150
171
  DEPENDENCIES
151
172
  activerecord-pg_enum!
152
173
  appraisal
153
- bundler (~> 1.15)
174
+ bundler (~> 1.17)
154
175
  pry
155
176
  rails!
156
177
  rake (~> 10.0)
@@ -3,7 +3,7 @@ require "active_support/lazy_load_hooks"
3
3
 
4
4
  module ActiveRecord
5
5
  module PGEnum
6
- KNOWN_VERSIONS = %w[4.1 4.2 5.0 5.1 5.2 6.0].map { |v| Gem::Version.new(v) }
6
+ KNOWN_VERSIONS = %w[4.1 4.2 5.0 5.1 5.2 6.0 6.1].map { |v| Gem::Version.new(v) }
7
7
 
8
8
  class << self
9
9
  attr_reader :enabled_version
@@ -25,6 +25,10 @@ module ActiveRecord
25
25
  monkeypatches[patch] = block
26
26
  end
27
27
 
28
+ def detected_version
29
+ approximate_version Gem.loaded_specs["activerecord"].version
30
+ end
31
+
28
32
  private
29
33
 
30
34
  def monkeypatches
@@ -3,6 +3,7 @@ module ActiveRecord
3
3
  register :table_definition do
4
4
  require "active_record/connection_adapters/postgresql_adapter"
5
5
  ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::TableDefinition.include TableDefinition
6
+ ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::Table.include TableDefinition
6
7
  end
7
8
 
8
9
  module TableDefinition
@@ -5,6 +5,7 @@ module ActiveRecord
5
5
  register :table_definition do
6
6
  require "active_record/connection_adapters/postgresql_adapter"
7
7
  ActiveRecord::ConnectionAdapters::PostgreSQL::TableDefinition.include TableDefinition
8
+ ActiveRecord::ConnectionAdapters::PostgreSQL::Table.include TableDefinition
8
9
  end
9
10
  end
10
11
  end
@@ -1,2 +1,18 @@
1
1
  require "active_record/pg_enum/4.2/table_definition"
2
2
 
3
+ module ActiveRecord
4
+ module PGEnum
5
+ module TableDefinition
6
+ # Create an enum column inside a TableDefinition
7
+ #
8
+ # Example:
9
+ #
10
+ # create_table :orders do |t|
11
+ # t.enum :status, as: "status_type"
12
+ # end
13
+ def enum(name, as:, **options)
14
+ column(name, as, **options)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1 @@
1
+ require "active_record/pg_enum/5.2/prepare_column_options"
@@ -0,0 +1 @@
1
+ require "active_record/pg_enum/5.2/schema_dumper"
@@ -0,0 +1 @@
1
+ require "active_record/pg_enum/6.0/table_definition"
@@ -34,12 +34,31 @@ module ActiveRecord
34
34
  record(:add_enum_value, args, &block)
35
35
  end
36
36
 
37
+ def rename_enum(name, options = {})
38
+ record(:rename_enum, [name, options])
39
+ end
40
+
41
+ def rename_enum_value(type, options = {})
42
+ record(:rename_enum_value, [type, options])
43
+ end
44
+
37
45
  private
38
46
 
39
47
  def invert_create_enum(args)
40
48
  [:drop_enum, args]
41
49
  end
42
50
 
51
+ def invert_rename_enum_value(args)
52
+ type, args = args
53
+ reversed = %i[from to].zip(args.values_at(:to, :from))
54
+
55
+ [:rename_enum_value, [type, Hash[reversed]]]
56
+ end
57
+
58
+ def invert_rename_enum(args)
59
+ [:rename_enum, [args.last[:to], to: args.first]]
60
+ end
61
+
43
62
  def invert_drop_enum(args)
44
63
  raise ActiveRecord::IrreversibleMigration, "drop_enum is only reversible if given a list of values" unless args.length > 1
45
64
  [:create_enum, args]
@@ -18,8 +18,8 @@ module ActiveRecord
18
18
  FROM pg_type t
19
19
  JOIN pg_enum e ON t.oid = e.enumtypid
20
20
  JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace
21
- WHERE n.nspname = 'public'
22
- GROUP BY enum_name
21
+ WHERE n.nspname = ANY (current_schemas(false))
22
+ GROUP BY enum_name;
23
23
  SQL
24
24
 
25
25
  coltype = res.column_types["enum_value"]
@@ -31,10 +31,10 @@ module ActiveRecord
31
31
  proc { |values| coltype.type_cast(values) }
32
32
  end
33
33
 
34
- res.rows.inject({}) do |memo, (name, values)|
35
- memo[name] = deserialize.call(values)
36
- memo
37
- end
34
+ res.rows
35
+ .map { |name, values| [name, values] }
36
+ .sort { |a, b| a.first <=> b.first }
37
+ .each_with_object({}) { |(name, values), memo| memo[name] = deserialize.call(values) }
38
38
  end
39
39
  end
40
40
  end
@@ -24,6 +24,14 @@ module ActiveRecord
24
24
  }
25
25
  end
26
26
 
27
+ # Rename an existing ENUM type
28
+ def rename_enum(name, options = {})
29
+ to = options.fetch(:to) { raise ArgumentError, ":to is required" }
30
+ execute("ALTER TYPE #{name} RENAME TO #{to}").tap {
31
+ reload_type_map
32
+ }
33
+ end
34
+
27
35
  # Add a new value to an existing ENUM type.
28
36
  # Only one value at a time is supported by PostgreSQL.
29
37
  #
@@ -34,7 +42,8 @@ module ActiveRecord
34
42
  # Example:
35
43
  #
36
44
  # add_enum_value("foo_type", "quux", before: "bar")
37
- def add_enum_value(type, value, before: nil, after: nil)
45
+ def add_enum_value(type, value, options = {})
46
+ before, after = options.values_at(:before, :after)
38
47
  cmd = "ALTER TYPE #{type} ADD VALUE '#{value}'"
39
48
 
40
49
  if before && after
@@ -47,6 +56,26 @@ module ActiveRecord
47
56
 
48
57
  execute(cmd).tap { reload_type_map }
49
58
  end
59
+
60
+ # Change the label of an existing ENUM value
61
+ #
62
+ # Options:
63
+ # from: The original label string
64
+ # to: The desired label string
65
+ #
66
+ # Example:
67
+ #
68
+ # rename_enum_value "foo_type", from: "quux", to: "Quux"
69
+ #
70
+ # Note: This feature requires PostgreSQL 10 or later
71
+ def rename_enum_value(type, options = {})
72
+ from = options.fetch(:from) { raise ArgumentError, ":from is required" }
73
+ to = options.fetch(:to) { raise ArgumentError, ":to is required" }
74
+
75
+ execute("ALTER TYPE #{type} RENAME VALUE '#{from}' TO '#{to}'").tap {
76
+ reload_type_map
77
+ }
78
+ end
50
79
  end
51
80
  end
52
81
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module PGEnum
3
- VERSION = "1.0.3"
3
+ VERSION = "1.2.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-pg_enum
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Lassek
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-13 00:00:00.000000000 Z
11
+ date: 2021-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '1.15'
75
+ version: '1.17'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '1.15'
82
+ version: '1.17'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -122,7 +122,7 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
- description:
125
+ description:
126
126
  email:
127
127
  - adam@doubleprime.net
128
128
  executables: []
@@ -155,6 +155,8 @@ files:
155
155
  - gemfiles/5.2.gemfile.lock
156
156
  - gemfiles/6.0.gemfile
157
157
  - gemfiles/6.0.gemfile.lock
158
+ - gemfiles/6.1.gemfile
159
+ - gemfiles/6.1.gemfile.lock
158
160
  - gemfiles/edge.gemfile
159
161
  - gemfiles/edge.gemfile.lock
160
162
  - lib/active_record/pg_enum.rb
@@ -181,6 +183,9 @@ files:
181
183
  - lib/active_record/pg_enum/6.0/prepare_column_options.rb
182
184
  - lib/active_record/pg_enum/6.0/schema_dumper.rb
183
185
  - lib/active_record/pg_enum/6.0/table_definition.rb
186
+ - lib/active_record/pg_enum/6.1/prepare_column_options.rb
187
+ - lib/active_record/pg_enum/6.1/schema_dumper.rb
188
+ - lib/active_record/pg_enum/6.1/table_definition.rb
184
189
  - lib/active_record/pg_enum/command_recorder.rb
185
190
  - lib/active_record/pg_enum/postgresql_adapter.rb
186
191
  - lib/active_record/pg_enum/schema_statements.rb
@@ -194,7 +199,7 @@ metadata:
194
199
  changelog_uri: https://github.com/alassek/activerecord-pg_enum/blob/master/CHANGELOG.md
195
200
  pgp_keys_uri: https://keybase.io/alassek/pgp_keys.asc
196
201
  signatures_uri: https://keybase.pub/alassek/gems/
197
- post_install_message:
202
+ post_install_message:
198
203
  rdoc_options: []
199
204
  require_paths:
200
205
  - lib
@@ -209,8 +214,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
209
214
  - !ruby/object:Gem::Version
210
215
  version: '0'
211
216
  requirements: []
212
- rubygems_version: 3.0.3
213
- signing_key:
217
+ rubygems_version: 3.2.3
218
+ signing_key:
214
219
  specification_version: 4
215
220
  summary: Integrate PostgreSQL's enumerated types with the Rails enum feature
216
221
  test_files: []