activerecord-postgres_enum 1.1.0 → 1.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65fc162010507d18b3607853f938bc02f2106ba56764d020943a241c00af3f07
|
4
|
+
data.tar.gz: 42eb21dd6b8441e8ca5589b38a30da8cbc646de28c89ecf58f09df5c92c67f54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 753abb413ecf0ee2a32e68c3bf1be93c3678c75b1b578a9c3177426bb31a8bbeff9010dc7550f66a2b710394ca97eb11e17eaeedbd17d1f6f0ddb7ddd1ce5799
|
7
|
+
data.tar.gz: 76200a6b37e19b00066a133d5ae377f9a3396681ac7bda6031b1cb89a1c0316ea9ae2c1de69c0f0ea1eb0fab196abad4cd7f0be23f7e04ae0fb34de614a51216
|
data/README.md
CHANGED
@@ -56,6 +56,14 @@ To add a value into existing enum:
|
|
56
56
|
add_enum_value :mood, "pensive"
|
57
57
|
```
|
58
58
|
|
59
|
+
To remove a value from existing enum:
|
60
|
+
|
61
|
+
> :warning: Make sure that value is not used anywhere in the database.
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
remove_enum_value :mood, "pensive"
|
65
|
+
```
|
66
|
+
|
59
67
|
To add a new enum column to an existing table:
|
60
68
|
|
61
69
|
```ruby
|
@@ -55,8 +55,10 @@ module ActiveRecord
|
|
55
55
|
execute "ALTER TYPE #{name} RENAME TO #{new_name}"
|
56
56
|
end
|
57
57
|
|
58
|
-
def add_enum_value(name, value, after: nil, before: nil)
|
59
|
-
|
58
|
+
def add_enum_value(name, value, after: nil, before: nil, if_not_exists: nil)
|
59
|
+
if_not_exists_statement = 'IF NOT EXISTS' if if_not_exists
|
60
|
+
|
61
|
+
sql = "ALTER TYPE #{name} ADD VALUE #{if_not_exists_statement} #{quote value}"
|
60
62
|
if after
|
61
63
|
sql += " AFTER #{quote after}"
|
62
64
|
elsif before
|
@@ -65,6 +67,15 @@ module ActiveRecord
|
|
65
67
|
execute sql
|
66
68
|
end
|
67
69
|
|
70
|
+
def remove_enum_value(name, value)
|
71
|
+
sql = %{
|
72
|
+
DELETE FROM pg_enum
|
73
|
+
WHERE enumlabel=#{quote value}
|
74
|
+
AND enumtypid=(SELECT oid FROM pg_type WHERE typname='#{name}')
|
75
|
+
}
|
76
|
+
execute sql
|
77
|
+
end
|
78
|
+
|
68
79
|
def rename_enum_value(name, existing_value, new_value)
|
69
80
|
raise "Renaming enum values is only supported in PostgreSQL 10.0+" unless rename_enum_value_supported?
|
70
81
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-postgres_enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Merkushin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|