activerecord-pg_enum 1.0.5 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -1
- data/CHANGELOG.md +8 -0
- data/README.md +30 -0
- data/activerecord-pg_enum.gemspec +1 -1
- data/gemfiles/4.1.gemfile.lock +2 -2
- data/gemfiles/4.2.gemfile.lock +2 -2
- data/gemfiles/5.0.gemfile.lock +3 -3
- data/gemfiles/5.1.gemfile.lock +3 -3
- data/gemfiles/5.2.gemfile.lock +3 -3
- data/gemfiles/6.0.gemfile.lock +3 -3
- data/gemfiles/edge.gemfile.lock +3 -3
- data/lib/active_record/pg_enum/command_recorder.rb +19 -0
- data/lib/active_record/pg_enum/schema_statements.rb +30 -1
- data/lib/active_record/pg_enum/version.rb +1 -1
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90bcdccc808335d627ce5d332fdf60085adf1084c7d959a94182103a41af56c5
|
4
|
+
data.tar.gz: 1acb8b53eab8259bc6102401dc785743a716f00aed1d5756f4157f90bb7714fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 151cadf02f5a9ba4f8406ea2894dada997dd65f0901f1d0dd3445bfbd5774f47eb2946efcc3ba74d08a080cf4e1589bf772b3a74494f80c2bc5b60db14236552
|
7
|
+
data.tar.gz: e0dcbef82fe63676589d94d64f60b76c6786b08af8448c10ed23eecd8323f83dfc56058ecd7e3c2a938ece5420e7ae5d933585888d47465d39f7bd89789971e5
|
data/.travis.yml
CHANGED
@@ -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.0.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: "
|
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/CHANGELOG.md
CHANGED
@@ -6,6 +6,14 @@ 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
|
+
|
9
17
|
## [1.0.5] - 2019-11-22
|
10
18
|
### Fixed
|
11
19
|
- Don't include schema name in dumped enum types to be consistent with the way tables are dumped (@TylerRick)
|
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
|
@@ -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.
|
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"
|
data/gemfiles/4.1.gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
activerecord-pg_enum (1.0
|
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.
|
69
|
+
bundler (~> 1.17)
|
70
70
|
i18n (~> 0.7)
|
71
71
|
pg (~> 0.15)
|
72
72
|
pry
|
data/gemfiles/4.2.gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
activerecord-pg_enum (1.0
|
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.
|
67
|
+
bundler (~> 1.17)
|
68
68
|
i18n (~> 0.7)
|
69
69
|
pg (~> 0.15)
|
70
70
|
pry
|
data/gemfiles/5.0.gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
activerecord-pg_enum (1.0
|
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.
|
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.
|
65
|
+
bundler (~> 1.17)
|
66
66
|
i18n (= 1.5.1)
|
67
67
|
pry
|
68
68
|
rake (~> 10.0)
|
data/gemfiles/5.1.gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
activerecord-pg_enum (1.0
|
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.
|
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.
|
65
|
+
bundler (~> 1.17)
|
66
66
|
pry
|
67
67
|
rake (~> 10.0)
|
68
68
|
rspec (~> 3.0)
|
data/gemfiles/5.2.gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
activerecord-pg_enum (1.0
|
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.
|
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.
|
65
|
+
bundler (~> 1.17)
|
66
66
|
pry
|
67
67
|
rake (~> 10.0)
|
68
68
|
rspec (~> 3.0)
|
data/gemfiles/6.0.gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
activerecord-pg_enum (1.0
|
4
|
+
activerecord-pg_enum (1.1.0)
|
5
5
|
activerecord (>= 4.1.0)
|
6
6
|
activesupport
|
7
7
|
pg
|
@@ -31,7 +31,7 @@ GEM
|
|
31
31
|
concurrent-ruby (~> 1.0)
|
32
32
|
method_source (0.9.2)
|
33
33
|
minitest (5.11.3)
|
34
|
-
pg (1.
|
34
|
+
pg (1.2.2)
|
35
35
|
pry (0.12.2)
|
36
36
|
coderay (~> 1.1.0)
|
37
37
|
method_source (~> 0.9.0)
|
@@ -62,7 +62,7 @@ DEPENDENCIES
|
|
62
62
|
activerecord (= 6.0.0)
|
63
63
|
activerecord-pg_enum!
|
64
64
|
appraisal
|
65
|
-
bundler (~> 1.
|
65
|
+
bundler (~> 1.17)
|
66
66
|
pry
|
67
67
|
rake (~> 10.0)
|
68
68
|
rspec (~> 3.0)
|
data/gemfiles/edge.gemfile.lock
CHANGED
@@ -66,7 +66,7 @@ GIT
|
|
66
66
|
PATH
|
67
67
|
remote: ..
|
68
68
|
specs:
|
69
|
-
activerecord-pg_enum (1.0
|
69
|
+
activerecord-pg_enum (1.1.0)
|
70
70
|
activerecord (>= 4.1.0)
|
71
71
|
activesupport
|
72
72
|
pg
|
@@ -103,7 +103,7 @@ GEM
|
|
103
103
|
nio4r (2.3.1)
|
104
104
|
nokogiri (1.8.4)
|
105
105
|
mini_portile2 (~> 2.3.0)
|
106
|
-
pg (1.
|
106
|
+
pg (1.2.2)
|
107
107
|
pry (0.11.3)
|
108
108
|
coderay (~> 1.1.0)
|
109
109
|
method_source (~> 0.9.0)
|
@@ -150,7 +150,7 @@ PLATFORMS
|
|
150
150
|
DEPENDENCIES
|
151
151
|
activerecord-pg_enum!
|
152
152
|
appraisal
|
153
|
-
bundler (~> 1.
|
153
|
+
bundler (~> 1.17)
|
154
154
|
pry
|
155
155
|
rails!
|
156
156
|
rake (~> 10.0)
|
@@ -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]
|
@@ -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,
|
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
|
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
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Lassek
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-19 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.
|
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.
|
82
|
+
version: '1.17'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rake
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -209,8 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
209
209
|
- !ruby/object:Gem::Version
|
210
210
|
version: '0'
|
211
211
|
requirements: []
|
212
|
-
|
213
|
-
rubygems_version: 2.7.6.2
|
212
|
+
rubygems_version: 3.1.2
|
214
213
|
signing_key:
|
215
214
|
specification_version: 4
|
216
215
|
summary: Integrate PostgreSQL's enumerated types with the Rails enum feature
|