activerecord-postgres_enum 1.3.0 → 1.6.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: 2e453014b2e32bcb23b20fd8c1f2dbb628690f303a61368bfad37564868244e4
4
- data.tar.gz: 55b98925e297a91892c5c284e53564a6012cdb82e2494b93505974207e8d7de2
3
+ metadata.gz: 1df28277031794a3f9e309a5339cee4ba229b548932d64e50c28413902a00991
4
+ data.tar.gz: f0538fb0989288c4b692bbffc379fde0a26108a57ce6ff41d9320b3738008f7f
5
5
  SHA512:
6
- metadata.gz: 45e0ba20aeaf52968c9022fca7aed356272ad2deb9883c98020d0bcdc17dfa73786fac4776f1f8cd02b45babe4a1344b5bcf9e516b8c3161275713910babc797
7
- data.tar.gz: 66fd78a22198c3326b66ce410fac6782599164d3087473b1e3d5550e94801af37407d85786ca38c5f4c5c0503b5320dcde7c377a5d1ef3f94db72f4b236a73f2
6
+ metadata.gz: 6b724dfcf0872fc8abd7134b4f0bc6b7c885c82996841aa9762c7e53b912f9f969b0ac4d8dc912eac1049ca6ae7eb1298bfd57575a956a00c27e781150c8f735
7
+ data.tar.gz: 777b145a8bbaabed85431b408f630da1f80066e54311500e4fe3daa6ccf5039961c3ffa5a20a55501eb07313e2cfa96100305d26e97be569db7a07759c1cf5c8
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/activerecord-postgres_enum.svg)](https://badge.fury.io/rb/activerecord-postgres_enum)
2
- [![Build Status](https://travis-ci.org/bibendi/activerecord-postgres_enum.svg?branch=master)](https://travis-ci.org/bibendi/activerecord-postgres_enum)
2
+ [![Build Status](https://github.com/bibendi/activerecord-postgres_enum/workflows/Ruby/badge.svg?branch=master)](https://github.com/bibendi/activerecord-postgres_enum/actions?query=branch%3Amaster)
3
3
 
4
4
  # ActiveRecord::PostgresEnum
5
5
 
@@ -32,7 +32,7 @@ ActiveSupport.on_load(:active_record) do
32
32
  end
33
33
 
34
34
  ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::NATIVE_DATABASE_TYPES[:enum] = {
35
- name: 'enum'
35
+ name: "enum"
36
36
  }
37
37
 
38
38
  ActiveRecord::Migration::CommandRecorder.prepend ActiveRecord::PostgresEnum::CommandRecorder
@@ -16,15 +16,15 @@ module ActiveRecord
16
16
  class TypeMapInitializer
17
17
  # We need to know the column name, and the default implementation discards it
18
18
  def register_enum_type(row)
19
- register row['oid'], OID::Enum.new(enum_name: row['typname'])
19
+ register row["oid"], OID::Enum.new(enum_name: row["typname"])
20
20
  end
21
21
  end
22
22
  end
23
23
 
24
24
  module ColumnMethods # :nodoc:
25
25
  # Enables `t.enum :my_field, enum_name: :my_enum_name` on migrations
26
- def enum(name, options = {})
27
- column(name, options.delete(:enum_name), options.except(:enum_name))
26
+ def enum(name, enum_name:, **options)
27
+ column(name, enum_name, **options)
28
28
  end
29
29
  end
30
30
  end
@@ -38,20 +38,22 @@ module ActiveRecord
38
38
 
39
39
  def enums
40
40
  select_all(DEFINED_ENUMS_QUERY).each_with_object({}) do |row, memo|
41
- memo[row["typname"].to_sym] = row['enumlabels'].split("\t\t")
41
+ memo[row["typname"].to_sym] = row["enumlabels"].split("\t\t")
42
42
  end
43
43
  end
44
44
 
45
- def create_enum(name, values, if_not_exists: nil)
45
+ def create_enum(name, values, force: false, if_not_exists: nil)
46
46
  return if if_not_exists && enums.include?(name.to_sym)
47
47
 
48
+ drop_enum(name, cascade: force == :cascade, if_exists: true) if force
49
+
48
50
  values = values.map { |v| quote v }
49
- execute "CREATE TYPE #{name} AS ENUM (#{values.join(', ')})"
51
+ execute "CREATE TYPE #{name} AS ENUM (#{values.join(", ")})"
50
52
  end
51
53
 
52
54
  def drop_enum(name, cascade: nil, if_exists: nil)
53
- if_exists_statement = 'IF EXISTS' if if_exists
54
- cascade_statement = 'CASCADE' if cascade
55
+ if_exists_statement = "IF EXISTS" if if_exists
56
+ cascade_statement = "CASCADE" if cascade
55
57
 
56
58
  sql = "DROP TYPE #{if_exists_statement} #{name} #{cascade_statement}"
57
59
  execute sql
@@ -62,7 +64,7 @@ module ActiveRecord
62
64
  end
63
65
 
64
66
  def add_enum_value(name, value, after: nil, before: nil, if_not_exists: nil)
65
- if_not_exists_statement = 'IF NOT EXISTS' if if_not_exists
67
+ if_not_exists_statement = "IF NOT EXISTS" if if_not_exists
66
68
 
67
69
  sql = "ALTER TYPE #{name} ADD VALUE #{if_not_exists_statement} #{quote value}"
68
70
  if after
@@ -14,14 +14,15 @@ module ActiveRecord
14
14
 
15
15
  def dump_enums(stream)
16
16
  statements = []
17
+ if @connection.respond_to?(:enums)
18
+ @connection.enums.each do |name, values|
19
+ values = values.map { |v| " #{v.inspect}," }.join("\n")
20
+ statements << " create_enum #{name.inspect}, [\n#{values}\n ], force: :cascade"
21
+ end
17
22
 
18
- @connection.enums.each do |name, values|
19
- values = values.map { |v| " #{v.inspect}," }.join("\n")
20
- statements << " create_enum #{name.inspect}, [\n#{values}\n ]"
23
+ stream.puts statements.join("\n\n")
24
+ stream.puts
21
25
  end
22
-
23
- stream.puts statements.join("\n")
24
- stream.puts
25
26
  end
26
27
  end
27
28
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveRecord
4
4
  module PostgresEnum
5
- VERSION = "1.3.0"
5
+ VERSION = "1.6.1"
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.3.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Merkushin
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-26 00:00:00.000000000 Z
11
+ date: 2021-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '5'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '6.1'
22
+ version: '6.2'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '5'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '6.1'
32
+ version: '6.2'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: pg
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -120,29 +120,29 @@ dependencies:
120
120
  requirements:
121
121
  - - "~>"
122
122
  - !ruby/object:Gem::Version
123
- version: '3.8'
123
+ version: '5.0'
124
124
  type: :development
125
125
  prerelease: false
126
126
  version_requirements: !ruby/object:Gem::Requirement
127
127
  requirements:
128
128
  - - "~>"
129
129
  - !ruby/object:Gem::Version
130
- version: '3.8'
130
+ version: '5.0'
131
131
  - !ruby/object:Gem::Dependency
132
- name: rubocop
132
+ name: standard
133
133
  requirement: !ruby/object:Gem::Requirement
134
134
  requirements:
135
135
  - - "~>"
136
136
  - !ruby/object:Gem::Version
137
- version: '0.58'
137
+ version: '1.1'
138
138
  type: :development
139
139
  prerelease: false
140
140
  version_requirements: !ruby/object:Gem::Requirement
141
141
  requirements:
142
142
  - - "~>"
143
143
  - !ruby/object:Gem::Version
144
- version: '0.58'
145
- description:
144
+ version: '1.1'
145
+ description:
146
146
  email:
147
147
  - merkushin.m.s@gmail.com
148
148
  executables: []
@@ -164,7 +164,7 @@ licenses:
164
164
  - MIT
165
165
  metadata:
166
166
  allowed_push_host: https://rubygems.org
167
- post_install_message:
167
+ post_install_message:
168
168
  rdoc_options: []
169
169
  require_paths:
170
170
  - lib
@@ -172,7 +172,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
172
172
  requirements:
173
173
  - - ">="
174
174
  - !ruby/object:Gem::Version
175
- version: '0'
175
+ version: '2.5'
176
176
  required_rubygems_version: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - ">="
@@ -180,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
180
  version: '0'
181
181
  requirements: []
182
182
  rubygems_version: 3.1.2
183
- signing_key:
183
+ signing_key:
184
184
  specification_version: 4
185
185
  summary: Integrate PostgreSQL's enum data type into ActiveRecord's schema and migrations.
186
186
  test_files: []