rescue_unique_constraint 1.3.0 → 1.4.0
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 +4 -4
- data/README.md +29 -22
- data/Rakefile +7 -0
- data/lib/rescue_unique_constraint/version.rb +1 -1
- data/rescue_unique_constraint.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea30803708b58175b2ea038bb6ebcb03b69d8db9
|
4
|
+
data.tar.gz: e28a19b92f52f1a71ec80e21b9a5f2ef5ca02e91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0d875de50c7fe791881a78812d1c3bd6521ecf0b794acf3dc16ba067b5229a6f0648f96c1ebfcfebe5077e8b565be414ef95e592cfe126a7c51e6b1b51ca6a0
|
7
|
+
data.tar.gz: 4e8118681c357af946e7fc0cae167a96e4e90d2faaa46ec285bdc45078dfb5a990d77580ffd77bace0570f8b8465cc96773b050e709b80363a680d4e06771604
|
data/README.md
CHANGED
@@ -30,22 +30,26 @@ Or install it yourself as:
|
|
30
30
|
|
31
31
|
Assuming you've added unique index:
|
32
32
|
|
33
|
-
|
34
|
-
|
33
|
+
```ruby
|
34
|
+
class AddIndexToThing < ActiveRecord::Migration
|
35
|
+
disable_ddl_transaction!
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
def change
|
38
|
+
add_index :things, :somefield, unique: true, algorithm: :concurrently, name: "my_unique_index"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
```
|
40
42
|
|
41
43
|
Before:
|
42
44
|
|
43
|
-
|
44
|
-
|
45
|
+
```ruby
|
46
|
+
class Thing < ActiveRecord::Base
|
47
|
+
end
|
45
48
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
+
thing = Thing.create(somefield: "foo")
|
50
|
+
dupe = Thing.create(somefield: "foo")
|
51
|
+
# => raises ActiveRecord::RecordNotUnique
|
52
|
+
```
|
49
53
|
|
50
54
|
Note that if you have `validates :uniqueness` in your model, it will prevent
|
51
55
|
the RecordNotUnique from being raised in _some_ cases, but not all, as race
|
@@ -54,25 +58,28 @@ enter your database.
|
|
54
58
|
|
55
59
|
After:
|
56
60
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
+
```ruby
|
62
|
+
class Thing < ActiveRecord::Base
|
63
|
+
include RescueUniqueConstraint
|
64
|
+
rescue_unique_constraint index: "my_unique_index", field: "somefield"
|
65
|
+
end
|
61
66
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
+
thing = Thing.create(somefield: "foo")
|
68
|
+
dupe = Thing.create(somefield: "foo")
|
69
|
+
# => false
|
70
|
+
thing.errors[:somefield] == "somefield has already been taken"
|
71
|
+
# => true
|
72
|
+
# => raises ActiveRecord::RecordNotUnique
|
73
|
+
```
|
67
74
|
|
68
75
|
## Testing
|
69
76
|
|
70
77
|
You'll need a database that supports unique constraints.
|
71
|
-
This gem has been tested with PostgreSQL and SQLite
|
78
|
+
This gem has been tested with PostgreSQL, MySQL and SQLite.
|
72
79
|
|
73
80
|
## Contributing
|
74
81
|
|
75
|
-
1. Fork it
|
82
|
+
1. [Fork it](https://github.com/reverbdotcom/rescue-unique-constraint/fork)
|
76
83
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
77
84
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
78
85
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/Rakefile
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "activerecord", ">=
|
21
|
+
spec.add_dependency "activerecord", ">= 3.2", "< 6"
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.6"
|
24
24
|
spec.add_development_dependency "rake", "~> 10.5"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rescue_unique_constraint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tam Dang
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-01-
|
12
|
+
date: 2018-01-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -17,7 +17,7 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
20
|
+
version: '3.2'
|
21
21
|
- - "<"
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: '6'
|
@@ -27,7 +27,7 @@ dependencies:
|
|
27
27
|
requirements:
|
28
28
|
- - ">="
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
version: '
|
30
|
+
version: '3.2'
|
31
31
|
- - "<"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '6'
|