postgresql-check 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -5
- data/lib/postgresql/check/schema_definitions.rb +15 -5
- data/lib/postgresql/check/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03755b91fbd278362a4e4df07e83bbabdd6d0c75
|
4
|
+
data.tar.gz: a9046295300501600d907d6e0cf1b9a6dae71f53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f319888b385d891e05236aa20ec1d9aa2ea80a411491b091e9c19103ded82984f22b45ffb0660f8895660b567f0d8014f5fc0938c7842300ea94a8377541d6fa
|
7
|
+
data.tar.gz: 277c4baf68afe7e6696f127f74b126e586e3ef3ffe09bb7d41f7c28b4a1926f1afed0b105bf216f8ecab6025c32d6ed324100a36c5a8c2416a259ae5ad1a53ac
|
data/README.md
CHANGED
@@ -45,15 +45,22 @@ end
|
|
45
45
|
You can add a check constraint in your migration:
|
46
46
|
|
47
47
|
```ruby
|
48
|
-
add_check :products, 'price > 0', :name => '
|
48
|
+
add_check :products, 'price > 0', :name => 'price_check'
|
49
49
|
```
|
50
50
|
|
51
|
-
|
51
|
+
The code above generates following SQL:
|
52
|
+
|
53
|
+
```sql
|
54
|
+
ALTER TABLE "products" ADD CONSTRAINT "products_price_check" (price > 0)
|
55
|
+
```
|
56
|
+
|
57
|
+
**NOTE**: `:name` option is mandatory now. Also note that table name auto-included
|
58
|
+
to constraint name.
|
52
59
|
|
53
60
|
To remove constraint use `remove_check` method:
|
54
61
|
|
55
62
|
```ruby
|
56
|
-
remove_check :products, :name => '
|
63
|
+
remove_check :products, :name => 'price_check'
|
57
64
|
```
|
58
65
|
|
59
66
|
## Change Table methods
|
@@ -63,7 +70,7 @@ This gem adds extra methods to `create_table` and `change_table`:
|
|
63
70
|
```ruby
|
64
71
|
create_table :products do |t|
|
65
72
|
t.decimal :price, :null => false
|
66
|
-
t.check 'price > 0', :name => '
|
73
|
+
t.check 'price > 0', :name => 'price_check'
|
67
74
|
end
|
68
75
|
```
|
69
76
|
|
@@ -71,7 +78,7 @@ Remove a check constraint:
|
|
71
78
|
|
72
79
|
```ruby
|
73
80
|
change_table :products do |t|
|
74
|
-
t.remove_check :name => '
|
81
|
+
t.remove_check :name => 'price_check'
|
75
82
|
end
|
76
83
|
```
|
77
84
|
|
@@ -2,12 +2,22 @@ module Postgresql
|
|
2
2
|
module Check
|
3
3
|
module SchemaDefinitions
|
4
4
|
def self.included(base)
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
if ActiveRecord::VERSION::STRING > "4.2"
|
6
|
+
ActiveRecord::ConnectionAdapters::PostgreSQL::Table.class_eval do
|
7
|
+
include Postgresql::Check::Table
|
8
|
+
end
|
9
|
+
|
10
|
+
ActiveRecord::ConnectionAdapters::PostgreSQL::TableDefinition.class_eval do
|
11
|
+
include Postgresql::Check::TableDefinition
|
12
|
+
end
|
13
|
+
else
|
14
|
+
base::Table.class_eval do
|
15
|
+
include Postgresql::Check::Table
|
16
|
+
end
|
8
17
|
|
9
|
-
|
10
|
-
|
18
|
+
base::TableDefinition.class_eval do
|
19
|
+
include Postgresql::Check::TableDefinition
|
20
|
+
end
|
11
21
|
end
|
12
22
|
end
|
13
23
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: postgresql-check
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexei Mikhailov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|