activerecord-postgres_enum 2.0.1 → 2.1.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: 3d36ad353392d74fe6bdd5aaeb03cc682cb0f84205b5502ecff4681dd5833afb
4
- data.tar.gz: 3c854bb369675b9a188dc8b102d35053fbe942f5939ea8675ea0fb3cfe3f9848
3
+ metadata.gz: 1b774ca52773f7346d01b9db6bf6b5a914c10253597c6796f6b6619612dfba64
4
+ data.tar.gz: 92c8bfb4e74845ce4a44d381c775b9443a22e2d091a55904d3deb7d2c0d5d0bc
5
5
  SHA512:
6
- metadata.gz: 8a95d1362c9bd42e9201c386e26908d3cb0ea7162554a2fd81e5d1b102ff4087d6b47dd5966d3770e00efea5d18e7e8438947f55118057b6dc223d4a070d8ccd
7
- data.tar.gz: 827677270881d6e14b394fa043d8c40c6ac2f789f791d484ddf7f0d7f1cbdba365840b3c8e370002c3fb56db46a7f1ce493cb1a9d27fd2f99c4ccae9ad27cfb8
6
+ metadata.gz: 716129b56fd13a1630fb6de9fb0a74608921dcad4e35e47523bc0c2c901fb72aa202eb95f483bd0a0bcd2a1f2fd1cbeb3603fa6b80791274d30688bf82e3417a
7
+ data.tar.gz: a8c8a21b0164e61d16d2e3ef5ed3d2726bed463ddc0f63dcf36e9b60cb5bed87f699a4a639f68d642b0f11d63a13a057d8113417479091b93b91166dc64eb9b0
data/README.md CHANGED
@@ -36,7 +36,7 @@ create_table :person do
36
36
  end
37
37
  ```
38
38
 
39
- Running the above will create a table :person, with a column :person_mood of type :mood. This will also be saved on schema.rb so that `rake schema:load` works as expected.
39
+ Running the above will create a table :person, with a column :person_mood of type :mood. This will also be saved on schema.rb so that `rake db:schema:load` works as expected.
40
40
 
41
41
  To drop an existing enum:
42
42
 
@@ -85,7 +85,7 @@ rename_enum_value :mood, "pensive", "wistful"
85
85
 
86
86
  ## Development
87
87
 
88
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
88
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
89
89
 
90
90
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
91
91
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # frozen_string_literal: true
4
-
5
3
  module ActiveRecord
6
4
  module PostgresEnum
7
5
  module Column
@@ -3,7 +3,7 @@
3
3
  module ActiveRecord
4
4
  module PostgresEnum
5
5
  module CommandRecorder
6
- def create_enum(name, values)
6
+ def create_enum(name, values, _opts = nil)
7
7
  record(:create_enum, [name, values])
8
8
  end
9
9
 
@@ -10,8 +10,10 @@ module ActiveRecord
10
10
  t.typtype,
11
11
  array_to_string(array_agg(e.enumlabel ORDER BY e.enumsortorder), '\t\t', '') as enumlabels
12
12
  FROM pg_type t
13
+ INNER JOIN pg_namespace n ON n.oid = t.typnamespace
13
14
  LEFT JOIN pg_enum e ON e.enumtypid = t.oid
14
- WHERE typtype = 'e'
15
+ WHERE t.typtype = 'e'
16
+ AND n.nspname = ANY(current_schemas(true))
15
17
  GROUP BY t.OID, t.typname, t.typtype
16
18
  ORDER BY t.typname
17
19
  SQL
@@ -58,8 +60,12 @@ module ActiveRecord
58
60
  def remove_enum_value(name, value)
59
61
  sql = %{
60
62
  DELETE FROM pg_enum
61
- WHERE enumlabel=#{quote value}
62
- AND enumtypid=(SELECT oid FROM pg_type WHERE typname='#{name}')
63
+ WHERE enumlabel = #{quote value}
64
+ AND enumtypid IN (SELECT t.oid
65
+ FROM pg_type t
66
+ INNER JOIN pg_namespace n ON n.oid = t.typnamespace
67
+ WHERE t.typname = '#{name}'
68
+ AND n.nspname = ANY(current_schemas(true)))
63
69
  }
64
70
  execute sql
65
71
  end
@@ -22,8 +22,12 @@ module ActiveRecord
22
22
  statements << " create_enum #{name.inspect}, [\n#{values}\n ], force: :cascade"
23
23
  end
24
24
 
25
- stream.puts statements.join("\n\n")
26
- stream.puts
25
+ # Check if there any enum types to dump - otherwise don't output
26
+ # anything to prevent empty lines in schema.rb
27
+ if statements.any?
28
+ stream.puts statements.join("\n\n")
29
+ stream.puts
30
+ end
27
31
  end
28
32
  end
29
33
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveRecord
4
4
  module PostgresEnum
5
- VERSION = "2.0.1"
5
+ VERSION = "2.1.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: 2.0.1
4
+ version: 2.1.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: 2021-12-24 00:00:00.000000000 Z
11
+ date: 2024-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -168,7 +168,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
168
168
  requirements:
169
169
  - - ">="
170
170
  - !ruby/object:Gem::Version
171
- version: '2.5'
171
+ version: '2.7'
172
172
  required_rubygems_version: !ruby/object:Gem::Requirement
173
173
  requirements:
174
174
  - - ">="