active_record-postgres-constraints 0.2.0 → 0.2.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: b3315c2077c81d530ad63720aea7fda16d01298233aec01e5f47990c2aa43969
4
- data.tar.gz: '048e1f4a77a7839d9eec3a75b8417dcfcd72390c960eeee3e75f2599369113a4'
3
+ metadata.gz: 03e9d44bf58ac8d7ea43a9e5278704e8d23d974e414da000cbc085e592690138
4
+ data.tar.gz: 6f46c5f3e22c46f7ab4562c66ee28102aec68abc5920a698578cf5443e3ddf19
5
5
  SHA512:
6
- metadata.gz: 3cdba026319a96312e707fb97efa408b1394c71812ed4fde78dd086f7916dc5cf0e854d8d86570e96e7ad8a69eb8fc01b02ff14f42cbf0aa3afe868abf454e61
7
- data.tar.gz: 3ccba16e546aa92e2d0d436cc66df0c84acd0605ede6b7ad40a12158879e223424ab0c1f03c53569f7b5e870c1cc9bdbcf73c17cdbd519f17a423ac8db221ad8
6
+ metadata.gz: 4f874156a54fd5384da04dfa347d29e3e883b86f09cf8383da8baf32fe8fdd66d8b3ece02e19b6fc1360f917bf5e457f9b5904a769bc8dae2c5038de970145a5
7
+ data.tar.gz: e362a852e1ffc5b88a3e08ccb862560d42ecc9897e6fa4aa2a356edb8198a6f217ba7cce9e920129389ac48394c9deca1e8027cfd69d9f6c8df008426bb94764
data/README.md CHANGED
@@ -72,6 +72,17 @@ remove_exclude_constraint :booking
72
72
  remove_exclude_constraint :booking, using: :gist, 'tsrange("from", "to")' => :overlaps, room_id: :equals
73
73
  ```
74
74
 
75
+ #### Constrainsts with custom conditions
76
+
77
+ If you need custom/complex conditions of any sort, you can even use string conditions:
78
+
79
+ ```ruby
80
+ create_table :people do |t|
81
+ t.string :title
82
+ t.check_constraint "title IS NULL OR title IN ['Mr.', 'Mrs.', 'Dr.']"
83
+ end
84
+ ```
85
+
75
86
  ## Installation
76
87
  Add this line to your application's Gemfile:
77
88
 
@@ -28,7 +28,7 @@ module ActiveRecord
28
28
 
29
29
  def constraints(table)
30
30
  types = CONSTRAINT_TYPES.values.map { |v| "'#{v}'" }.join(', ')
31
- sql = "SELECT conname, consrc, contype,
31
+ sql = "SELECT conname, contype,
32
32
  pg_get_constraintdef(pg_constraint.oid) AS definition
33
33
  FROM pg_constraint
34
34
  JOIN pg_class ON pg_constraint.conrelid = pg_class.oid
@@ -14,7 +14,7 @@ module ActiveRecord
14
14
 
15
15
  def to_schema_dump(constraint)
16
16
  name = constraint['conname']
17
- conditions = constraint['consrc']
17
+ conditions = constraint['definition'].gsub(/^CHECK\s*\((.*)\)\s*$/, '\\1')
18
18
  " t.check_constraint :#{name}, #{conditions.inspect}"
19
19
  end
20
20
 
@@ -3,7 +3,7 @@
3
3
  module ActiveRecord
4
4
  module Postgres
5
5
  module Constraints
6
- VERSION = '0.2.0'
6
+ VERSION = '0.2.1'
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record-postgres-constraints
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Isaac Betesh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-21 00:00:00.000000000 Z
11
+ date: 2020-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -50,14 +50,14 @@ dependencies:
50
50
  requirements:
51
51
  - - '='
52
52
  - !ruby/object:Gem::Version
53
- version: 0.1.15
53
+ version: 0.1.16
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - '='
59
59
  - !ruby/object:Gem::Version
60
- version: 0.1.15
60
+ version: 0.1.16
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: rspec
63
63
  requirement: !ruby/object:Gem::Requirement