active_record-postgres-constraints 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ff6e3c4d2843cef1ef885a47229ce08d7b1c1464
4
- data.tar.gz: 99953ab207b97f628c2750f1c1f96f84c8f86a95
2
+ SHA256:
3
+ metadata.gz: 590c9903ba5ee75b0ee276ced8118f89b9c0d20d8e29953afa0b5e2c596a7998
4
+ data.tar.gz: 880f0d33689a35515e3a56c6a847d3766da94d21fee5a16e2b64ab1d3f1e1c76
5
5
  SHA512:
6
- metadata.gz: 652b7f44473db5a57194f344b37a9a4930df83180a363fab18333a519b31fcd1bb5db3780f4bb202af54a434977ba105189de7171b219ddf8107dcc574a6cef5
7
- data.tar.gz: c9e6256c894e13f477e763326ada5df24787a8f0eb5461486521e3128f4024619c77ac39d14c46835ed807da23e59e66d916d04814f5c140ca4fc465466d69fc
6
+ metadata.gz: 9f8aa9f3635049259ff5cd216f96a76f080e1d7cd3c49c2bc0089716cb765457f329e467fbd2a072299f11847375fbcb94236e57fdcd5515b5e07d70c209bdc4
7
+ data.tar.gz: 9fae7cacb9bd526a05acd2b59e9b073c9e9834e9b6b5e9b4eaefa7193f9d9b4ae08cb3c9ed12c8c7df6453d42e5ac6b73d41413256601692d0c3e4e6c4da3c08
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  begin
3
4
  require 'bundler/setup'
4
5
  rescue LoadError
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require_relative 'constraints/command_recorder'
3
4
  require_relative 'constraints/postgresql_adapter'
4
5
  require_relative 'constraints/railtie'
@@ -22,6 +23,7 @@ module ActiveRecord
22
23
  end
23
24
 
24
25
  return conditions.first if 1 == conditions.length
26
+
25
27
  "(#{conditions.join(') AND (')})"
26
28
  end
27
29
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module ActiveRecord
3
4
  module Postgres
4
5
  module Constraints
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module ActiveRecord
3
4
  module Postgres
4
5
  module Constraints
@@ -1,31 +1,49 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module ActiveRecord
3
4
  module Postgres
4
5
  module Constraints
5
6
  class Railtie < Rails::Railtie
6
- initializer 'active_record.postgres.constraints.patch_active_record' do
7
+ initializer 'active_record.postgres.constraints.patch_active_record' do |*_args|
8
+ engine = self
7
9
  ActiveSupport.on_load(:active_record) do
8
10
  AR_CAS = ::ActiveRecord::ConnectionAdapters
9
11
 
10
- connection = ActiveRecord::Base.connection
11
- using_pg = connection.class.to_s == "#{AR_CAS}::PostgreSQLAdapter"
12
- if using_pg
13
- Rails.logger.info do
14
- 'Applying Postgres Constraints patches to ActiveRecord'
15
- end
16
- AR_CAS::TableDefinition.include TableDefinition
17
- AR_CAS::PostgreSQLAdapter.include PostgreSQLAdapter
18
- AR_CAS::AbstractAdapter::SchemaCreation.prepend SchemaCreation
12
+ engine.apply_patch! if engine.pg?
13
+ end
14
+ end
15
+
16
+ def apply_patch!
17
+ Rails.logger.info do
18
+ 'Applying Postgres Constraints patches to ActiveRecord'
19
+ end
20
+ AR_CAS::TableDefinition.include TableDefinition
21
+ AR_CAS::PostgreSQLAdapter.include PostgreSQLAdapter
22
+ AR_CAS::AbstractAdapter::SchemaCreation.prepend SchemaCreation
19
23
 
20
- ::ActiveRecord::Migration::CommandRecorder.include CommandRecorder
21
- ::ActiveRecord::SchemaDumper.prepend SchemaDumper
22
- else
23
- Rails.logger.warn do
24
- 'Not applying Postgres Constraints patches to ActiveRecord ' \
25
- 'since the database is not postgres'
26
- end
24
+ ::ActiveRecord::Migration::CommandRecorder.include CommandRecorder
25
+ ::ActiveRecord::SchemaDumper.prepend SchemaDumper
26
+ end
27
+
28
+ def pg?
29
+ begin
30
+ connection = ActiveRecord::Base.connection
31
+ rescue ActiveRecord::NoDatabaseError
32
+ Rails.logger.warn do
33
+ 'Not applying Postgres Constraints patches to ActiveRecord ' \
34
+ 'since the database does not exist'
27
35
  end
36
+ return false
37
+ end
38
+
39
+ pg = connection.class.to_s == "#{AR_CAS}::PostgreSQLAdapter"
40
+ return true if pg
41
+
42
+ Rails.logger.warn do
43
+ 'Not applying Postgres Constraints patches to ActiveRecord ' \
44
+ 'since the database is not postgres'
28
45
  end
46
+ false
29
47
  end
30
48
  end
31
49
  end
@@ -1,13 +1,15 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module ActiveRecord
3
4
  module Postgres
4
5
  module Constraints
5
6
  module SchemaCreation
6
- # rubocop:disable Style/MethodName
7
- def visit_TableDefinition(o)
8
- # rubocop:enable Style/MethodName
7
+ # rubocop:disable Naming/MethodName
8
+ def visit_TableDefinition(table_definition)
9
+ # rubocop:enable Naming/MethodName
9
10
  result = super
10
- return result unless o.check_constraints
11
+ return result unless table_definition.check_constraints
12
+
11
13
  nesting = 0
12
14
  # Find the closing paren of the "CREATE TABLE ( ... )" clause
13
15
  index = result.length.times do |i|
@@ -15,7 +17,7 @@ module ActiveRecord
15
17
  nesting, should_break = adjust_nesting(nesting, token)
16
18
  break i if should_break
17
19
  end
18
- result[index] = ", #{o.check_constraints.join(', ')})"
20
+ result[index] = ", #{table_definition.check_constraints.join(', ')})"
19
21
  result
20
22
  end
21
23
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module ActiveRecord
3
4
  module Postgres
4
5
  module Constraints
@@ -7,6 +8,7 @@ module ActiveRecord
7
8
  super
8
9
  constraints = @connection.constraints(table)
9
10
  return unless constraints.any?
11
+
10
12
  constraint_statements = constraints.map do |constraint|
11
13
  name = constraint['conname']
12
14
  conditions = constraint['consrc']
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module ActiveRecord
3
4
  module Postgres
4
5
  module Constraints
@@ -1,8 +1,9 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module ActiveRecord
3
4
  module Postgres
4
5
  module Constraints
5
- VERSION = '0.1.2'
6
+ VERSION = '0.1.3'
6
7
  end
7
8
  end
8
9
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record-postgres-constraints
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Isaac Betesh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-23 00:00:00.000000000 Z
11
+ date: 2018-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pg
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rails
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -25,13 +39,13 @@ dependencies:
25
39
  - !ruby/object:Gem::Version
26
40
  version: '5.0'
27
41
  - !ruby/object:Gem::Dependency
28
- name: pg
42
+ name: osm-rubocop
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ">="
32
46
  - !ruby/object:Gem::Version
33
47
  version: '0'
34
- type: :runtime
48
+ type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
@@ -39,19 +53,19 @@ dependencies:
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
- name: rubocop
56
+ name: rspec
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - ">="
59
+ - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '0'
61
+ version: '3.8'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - ">="
66
+ - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '0'
68
+ version: '3.8'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rspec-rails
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -111,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
125
  version: '0'
112
126
  requirements: []
113
127
  rubyforge_project:
114
- rubygems_version: 2.6.10
128
+ rubygems_version: 2.7.7
115
129
  signing_key:
116
130
  specification_version: 4
117
131
  summary: Store your constraints in db/schema.rb