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: 11be6863582ca701d4d5d01e48fef1c95c6654c5889d6c82823e7eeb7e548667
4
- data.tar.gz: c7324a3933d4345cb222d3378dcd74815a7860ec5d4c90e01bf4cb213c986b61
3
+ metadata.gz: 65fc162010507d18b3607853f938bc02f2106ba56764d020943a241c00af3f07
4
+ data.tar.gz: 42eb21dd6b8441e8ca5589b38a30da8cbc646de28c89ecf58f09df5c92c67f54
5
5
  SHA512:
6
- metadata.gz: 4a65ec7099464c6f1fd5863efdad17316702cc4a0427c2ed6008a42e059f72c22d094b79a564c6880da5072c3cd3f0db3bd36ddf4bde1e8a847fa5391623c1e9
7
- data.tar.gz: '099ee04842e690d703ff3e859067c5b07c22bc52a03166caedce11f03060365b11f6140d7e614d83cd692eef8b4a8bc06f3ace730d17a68a5913953d91c5c11a'
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
- sql = "ALTER TYPE #{name} ADD VALUE #{quote value}"
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
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveRecord
4
4
  module PostgresEnum
5
- VERSION = "1.1.0"
5
+ VERSION = "1.2.0"
6
6
  end
7
7
  end
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.1.0
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-06-19 00:00:00.000000000 Z
11
+ date: 2020-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord