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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c6eb60da5a7a04b6f3ba274a4e32de726bc1a675
4
- data.tar.gz: 6fb2dcf1dff2148952e0bbbbefb8d1d26887675d
3
+ metadata.gz: 03755b91fbd278362a4e4df07e83bbabdd6d0c75
4
+ data.tar.gz: a9046295300501600d907d6e0cf1b9a6dae71f53
5
5
  SHA512:
6
- metadata.gz: 02e9e39c308790b9452afd8d362f00a5e31249587e408919cdcdce8f77dbf2798c507d866a9e482bc2aa082796f683bc24d11a142f2abc8c286168ce93621cf0
7
- data.tar.gz: 8dd9938fe756ee6d7e4f76485014c4aa664af60da3f55c9127a72198a3b471be5ac52367d463beb37d3847620294907f83c511717708961d88b10cff69793507
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 => 'products_price_check'
48
+ add_check :products, 'price > 0', :name => 'price_check'
49
49
  ```
50
50
 
51
- **NOTE**: `:name` option is mandatory now.
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 => 'products_price_check'
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 => 'products_price_check'
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 => 'products_price_check'
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
- base::Table.class_eval do
6
- include Postgresql::Check::Table
7
- end
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
- base::TableDefinition.class_eval do
10
- include Postgresql::Check::TableDefinition
18
+ base::TableDefinition.class_eval do
19
+ include Postgresql::Check::TableDefinition
20
+ end
11
21
  end
12
22
  end
13
23
  end
@@ -1,5 +1,5 @@
1
1
  module Postgresql
2
2
  module Check
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
  end
5
5
  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.1
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: 2014-10-01 00:00:00.000000000 Z
11
+ date: 2015-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord