activerecord-pg_enum 1.0.2 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '068a2c10c5375f5842445a5bff077ec28e14cd633d99dd7b8ef98690b28b2d2b'
4
- data.tar.gz: aca6f592f676a8f6cd866a3bb1b3ca0eb0081976e8c1bbb99c71b25f5fc5192b
3
+ metadata.gz: 85cd85e713014a5ff4908c18f1fce5ca4ac095f8a96e920f9d88c6ce2ba98d56
4
+ data.tar.gz: 1cccaa9ca8d9159026f9481f2ea4140cae92d512e319a63a57d61c4df89cebd4
5
5
  SHA512:
6
- metadata.gz: 8c10ce8c87fada1997551cc9257cfd1cf7a8af5182f048c0b4f8fc56738e8bfe6fdda0bd88bd4e5126dba8102d9f1107cd1c1c40a5693fc8e860b190935c673d
7
- data.tar.gz: ef59bbe1f7ea8dba8191c40c74aa703e1a00de17b26457ee26b4b73bf95fe24ceb2f85f105d480f6e49877d2bf466dfed39dfd323c8643e7cb35ddeb79737eb3
6
+ metadata.gz: ea13c3305043508405f0884c2a7af0debd0a226284975a1c2459dd641316de2b3f44b74b45d10164c11a74035be6abad5587314e9a5ccf62052f62398923cf4c
7
+ data.tar.gz: 65e9812276e32202570e1eb1b8d997d327b3bfbaf68fb883aa127e13747cbda0cb570384ec375ed5ee8320cf9df89dffb59fbc533bd432b769185f54cd947d9c
@@ -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,27 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.1.0] - 2020-01-18
10
+ ### Added
11
+ - `rename_enum` command for changing the type name
12
+ - `rename_enum_value` command for changing an enum label (PostgreSQL 10+ only)
13
+
14
+ ### Changed
15
+ - Refactored some code to eliminate deprecation warnings in 2.7 related to kwargs
16
+
17
+ ## [1.0.5] - 2019-11-22
18
+ ### Fixed
19
+ - Don't include schema name in dumped enum types to be consistent with the way tables are dumped (@TylerRick)
20
+
21
+ ## [1.0.4] - 2019-11-16
22
+ ### Fixed
23
+ - Dump enums declared in non-public schemas
24
+ - Fix missing `enum` method with using `change_table`
25
+
26
+ ## [1.0.3] - 2019-10-13
27
+ ### Fixed
28
+ - Allow enum labels to contain spaces (@AndrewSpeed)
29
+
9
30
  ## [1.0.2] - 2019-08-29
10
31
  - Move the active_record load hook to a different place to ensure things run in the correct order
11
32
 
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,10 @@
1
1
  require "bundler/gem_tasks"
2
+ :q
3
+ :q
4
+
2
5
  require "rspec/core/rake_task"
3
6
  require "appraisal"
7
+ require "pry"
4
8
 
5
9
  if !ENV["APPRAISAL_INITIALIZED"] && !ENV["TRAVIS"]
6
10
  task :default => :appraisal
@@ -10,13 +14,15 @@ end
10
14
 
11
15
  task :connection do
12
16
  require "active_record"
17
+ require_relative "spec/support/connection_config"
18
+
19
+ config = db_config_hash.except(:database)
13
20
 
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
- )
21
+ if ActiveRecord.constants.include?(:DatabaseConfigurations)
22
+ config = ActiveRecord::DatabaseConfigurations::HashConfig.new("test", "primary", config)
23
+ end
24
+
25
+ ActiveRecord::Base.establish_connection(config)
20
26
  end
21
27
 
22
28
  namespace :spec do
@@ -35,6 +41,8 @@ namespace :spec do
35
41
  conn.drop_database ENV.fetch("TEST_DATABASE", "pg_enum_test")
36
42
  end
37
43
  end
44
+
45
+ task reset: [:teardown, :setup]
38
46
  end
39
47
 
40
48
  task spec: %w[spec:setup spec:run spec:teardown]
@@ -14,6 +14,13 @@ Gem::Specification.new do |spec|
14
14
  spec.homepage = "https://github.com/alassek/activerecord-pg_enum"
15
15
  spec.license = "MIT"
16
16
 
17
+ spec.metadata = {
18
+ "bug_tracker_uri" => "https://github.com/alassek/activerecord-pg_enum/issues",
19
+ "changelog_uri" => "https://github.com/alassek/activerecord-pg_enum/blob/master/CHANGELOG.md",
20
+ "pgp_keys_uri" => "https://keybase.io/alassek/pgp_keys.asc",
21
+ "signatures_uri" => "https://keybase.pub/alassek/gems/"
22
+ }
23
+
17
24
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
25
  f.match(%r{^(test|spec|features)/})
19
26
  end
@@ -29,7 +36,7 @@ Gem::Specification.new do |spec|
29
36
  spec.add_dependency "activesupport"
30
37
 
31
38
  spec.add_development_dependency "appraisal"
32
- spec.add_development_dependency "bundler", "~> 1.15"
39
+ spec.add_development_dependency "bundler", "~> 1.17"
33
40
  spec.add_development_dependency "rake", "~> 10.0"
34
41
  spec.add_development_dependency "rspec", "~> 3.0"
35
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.1)
4
+ activerecord-pg_enum (1.1.0)
5
5
  activerecord (>= 4.1.0)
6
6
  activesupport
7
7
  pg
@@ -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.1)
4
+ activerecord-pg_enum (1.1.0)
5
5
  activerecord (>= 4.1.0)
6
6
  activesupport
7
7
  pg
@@ -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.1)
4
+ activerecord-pg_enum (1.1.0)
5
5
  activerecord (>= 4.1.0)
6
6
  activesupport
7
7
  pg
@@ -32,7 +32,7 @@ GEM
32
32
  concurrent-ruby (~> 1.0)
33
33
  method_source (0.9.2)
34
34
  minitest (5.11.3)
35
- pg (1.1.4)
35
+ pg (1.2.2)
36
36
  pry (0.12.2)
37
37
  coderay (~> 1.1.0)
38
38
  method_source (~> 0.9.0)
@@ -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.1)
4
+ activerecord-pg_enum (1.1.0)
5
5
  activerecord (>= 4.1.0)
6
6
  activesupport
7
7
  pg
@@ -32,7 +32,7 @@ GEM
32
32
  concurrent-ruby (~> 1.0)
33
33
  method_source (0.9.0)
34
34
  minitest (5.11.3)
35
- pg (1.1.4)
35
+ pg (1.2.2)
36
36
  pry (0.11.3)
37
37
  coderay (~> 1.1.0)
38
38
  method_source (~> 0.9.0)
@@ -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.1)
4
+ activerecord-pg_enum (1.1.0)
5
5
  activerecord (>= 4.1.0)
6
6
  activesupport
7
7
  pg
@@ -32,7 +32,7 @@ GEM
32
32
  concurrent-ruby (~> 1.0)
33
33
  method_source (0.9.0)
34
34
  minitest (5.11.3)
35
- pg (1.1.4)
35
+ pg (1.2.2)
36
36
  pry (0.11.3)
37
37
  coderay (~> 1.1.0)
38
38
  method_source (~> 0.9.0)
@@ -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.1)
4
+ activerecord-pg_enum (1.1.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.2)
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.1.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.1)
90
+ activerecord-pg_enum (1.1.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
@@ -19,7 +19,7 @@ module ActiveRecord
19
19
  stream.puts " # These are custom enum types that must be created before they can be used in the schema definition"
20
20
 
21
21
  enum_types.each do |name, definition|
22
- stream.puts %Q{ create_enum "#{name}", %w[#{definition.join(" ")}]}
22
+ stream.puts %Q{ create_enum "#{name}", #{definition}}
23
23
  end
24
24
 
25
25
  stream.puts
@@ -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 @@
1
1
  require "active_record/pg_enum/4.2/table_definition"
2
-
@@ -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/4.2/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]
@@ -14,24 +14,27 @@ module ActiveRecord
14
14
  # { "foo_type" => ["foo", "bar", "baz"] }
15
15
  def enum_types
16
16
  res = exec_query(<<-SQL.strip_heredoc, "SCHEMA")
17
- SELECT t.typname AS enum_name, string_agg(e.enumlabel, ' ' ORDER BY e.enumsortorder) AS enum_value
17
+ SELECT t.typname AS enum_name, array_agg(e.enumlabel ORDER BY e.enumsortorder) AS enum_value
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
- if res.respond_to?(:cast_values)
26
- res = res.cast_values
25
+ coltype = res.column_types["enum_value"]
26
+ deserialize = if coltype.respond_to?(:deserialize)
27
+ proc { |values| coltype.deserialize(values) }
28
+ elsif coltype.respond_to?(:type_cast_from_database)
29
+ proc { |values| coltype.type_cast_from_database(values) }
27
30
  else
28
- res = res.rows
31
+ proc { |values| coltype.type_cast(values) }
29
32
  end
30
33
 
31
- res.inject({}) do |memo, (name, values)|
32
- memo[name] = values.split(" ")
33
- memo
34
- 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) }
35
38
  end
36
39
  end
37
40
  end
@@ -10,7 +10,7 @@ module ActiveRecord
10
10
  #
11
11
  # Example:
12
12
  #
13
- # create_enum("foo_type", "foo", "bar", "baz")
13
+ # create_enum("foo_type", "foo", "bar", "baz", "foo bar")
14
14
  def create_enum(name, values)
15
15
  execute("CREATE TYPE #{name} AS ENUM (#{Array(values).map { |v| "'#{v}'" }.join(", ")})").tap {
16
16
  reload_type_map
@@ -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.2"
3
+ VERSION = "1.2.0"
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.2
4
+ version: 1.2.0
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-08-29 00:00:00.000000000 Z
11
+ date: 2020-12-10 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
@@ -189,8 +194,12 @@ files:
189
194
  homepage: https://github.com/alassek/activerecord-pg_enum
190
195
  licenses:
191
196
  - MIT
192
- metadata: {}
193
- post_install_message:
197
+ metadata:
198
+ bug_tracker_uri: https://github.com/alassek/activerecord-pg_enum/issues
199
+ changelog_uri: https://github.com/alassek/activerecord-pg_enum/blob/master/CHANGELOG.md
200
+ pgp_keys_uri: https://keybase.io/alassek/pgp_keys.asc
201
+ signatures_uri: https://keybase.pub/alassek/gems/
202
+ post_install_message:
194
203
  rdoc_options: []
195
204
  require_paths:
196
205
  - lib
@@ -205,8 +214,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
205
214
  - !ruby/object:Gem::Version
206
215
  version: '0'
207
216
  requirements: []
208
- rubygems_version: 3.0.3
209
- signing_key:
217
+ rubygems_version: 3.0.6
218
+ signing_key:
210
219
  specification_version: 4
211
220
  summary: Integrate PostgreSQL's enumerated types with the Rails enum feature
212
221
  test_files: []