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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03e9d44bf58ac8d7ea43a9e5278704e8d23d974e414da000cbc085e592690138
|
4
|
+
data.tar.gz: 6f46c5f3e22c46f7ab4562c66ee28102aec68abc5920a698578cf5443e3ddf19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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,
|
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['
|
17
|
+
conditions = constraint['definition'].gsub(/^CHECK\s*\((.*)\)\s*$/, '\\1')
|
18
18
|
" t.check_constraint :#{name}, #{conditions.inspect}"
|
19
19
|
end
|
20
20
|
|
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.
|
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-
|
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.
|
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.
|
60
|
+
version: 0.1.16
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: rspec
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|