umbrellio-sequel-plugins 0.3.1.77 → 0.4.0.81
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/CHANGELOG.md +4 -0
- data/README.md +54 -0
- data/lib/sequel/extensions/deferrable_foreign_keys.rb +22 -0
- data/umbrellio-sequel-plugins.gemspec +1 -1
- data/utils/database.rb +1 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1506132f68e964f7e3f06370a9766cdad8b89d84ad4e810e73ab3225e6f1140b
|
4
|
+
data.tar.gz: 0f1774262d2a637abd9dfd8a5bd379a2a22cac5a0f0836c7c742e115657ff467
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c2f62536da956885da8d21c21ca9704925e85dce9de4eafd24948e30dea6b354281384529b80f7bd6f1076f17348bb58e2aff378ec6d8a54b285e367f26b7cb
|
7
|
+
data.tar.gz: 58e5e45610d3dd9746b17bef038fd4609634d1050ed5619766dd30eeecf8c1fa5dc64b710c0b1cfa2a2b0660786a01e3264c6f21334a935bbce0d4aef7415ff7
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## [0.4.0] 2019-11-18
|
5
|
+
### Added
|
6
|
+
- `Sequel.extension(:deferrable_foreign_keys)` - makes foreign keys constraints deferrable by default;
|
7
|
+
|
4
8
|
## [0.3.2] 2018-07-03
|
5
9
|
### Added
|
6
10
|
- Support sequel expessions in `with_rates`
|
data/README.md
CHANGED
@@ -22,6 +22,7 @@ And then execute:
|
|
22
22
|
- `Slave`
|
23
23
|
- `Synchronize`
|
24
24
|
- `methods_in_migrations`
|
25
|
+
- `deferrable_foreign_keys`
|
25
26
|
|
26
27
|
# Plugins
|
27
28
|
|
@@ -148,6 +149,59 @@ Sequel.migration do
|
|
148
149
|
end
|
149
150
|
```
|
150
151
|
|
152
|
+
## Deferrable Foreign Keys
|
153
|
+
|
154
|
+
Enable: `Sequel.extension(:deferrable_foreign_keys)`
|
155
|
+
|
156
|
+
Makes foreign keys constraints deferrable (`DEFERABLE INITIALLY DEFERRED`) by default.
|
157
|
+
|
158
|
+
Example:
|
159
|
+
|
160
|
+
```ruby
|
161
|
+
DB.create_table(:users) { primary_key :id }
|
162
|
+
DB.create_table(:items) do
|
163
|
+
primary_key :id
|
164
|
+
foreign_key :user_id, :users
|
165
|
+
end
|
166
|
+
```
|
167
|
+
```sql
|
168
|
+
CREATE TABLE users (
|
169
|
+
id integer NOT NULL
|
170
|
+
);
|
171
|
+
CREATE TABLE items (
|
172
|
+
id integer NOT NULL
|
173
|
+
);
|
174
|
+
|
175
|
+
-- without extension:
|
176
|
+
ALTER TABLE items ADD CONSTRAINT items_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id);
|
177
|
+
|
178
|
+
-- with extension:
|
179
|
+
ALTER TABLE items ADD CONSTRAINT items_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id) DEFERRABLE INITIALLY DEFERRED;
|
180
|
+
```
|
181
|
+
|
182
|
+
OR
|
183
|
+
|
184
|
+
```ruby
|
185
|
+
# wives attributes: id (pk), husband_id (fk)
|
186
|
+
# husbands attributes: id (pk), wife_id (fk)
|
187
|
+
|
188
|
+
Wife = Sequel::Model(:wives)
|
189
|
+
Husband = Sequel::Model(:husbands)
|
190
|
+
|
191
|
+
DB.transaction do
|
192
|
+
wife = Wife.create(id: 1, husband_id: 123456789)
|
193
|
+
husband = Husband.create(id: 1)
|
194
|
+
wife.update(husband_id: husband.id)
|
195
|
+
husband.update(wife_id: wife.id)
|
196
|
+
end
|
197
|
+
# assume there are no husband with id=123456789
|
198
|
+
# without extension:
|
199
|
+
# => Sequel::ForeignKeyConstraintViolation: Key (husband_id)=(123456789) is not present in table "husbands".
|
200
|
+
# with extension:
|
201
|
+
# => <Wife @attributes={id:1, husband_id: 1}>
|
202
|
+
# => <Husband @attributes={id:1, wife_id: 1}>
|
203
|
+
```
|
204
|
+
|
151
205
|
## Duplicate
|
152
206
|
|
153
207
|
Enable: `Sequel::Model.plugin :duplicate`
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sequel
|
4
|
+
module CreateTableDefaultDeferrable
|
5
|
+
def foreign_key(name, table = nil, opts = nil)
|
6
|
+
patch = { deferrable: true }
|
7
|
+
opts = opts.nil? ? patch : patch.merge(opts)
|
8
|
+
super(name, table, opts)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module AlterTableDefaultDeferrable
|
13
|
+
def add_foreign_key(name, table, opts = nil)
|
14
|
+
patch = { deferrable: true }
|
15
|
+
opts = opts.nil? ? patch : patch.merge(opts)
|
16
|
+
super(name, table, opts)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Sequel::Schema::CreateTableGenerator.prepend(Sequel::CreateTableDefaultDeferrable)
|
22
|
+
Sequel::Schema::AlterTableGenerator.prepend(Sequel::AlterTableDefaultDeferrable)
|
@@ -4,7 +4,7 @@ lib = File.expand_path("lib", __dir__)
|
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
gem_version = "0.
|
7
|
+
gem_version = "0.4.0"
|
8
8
|
release_version = ENV["TRAVIS"] ? "#{gem_version}.#{ENV["TRAVIS_BUILD_NUMBER"]}" : gem_version
|
9
9
|
|
10
10
|
spec.name = "umbrellio-sequel-plugins"
|
data/utils/database.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: umbrellio-sequel-plugins
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0.81
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nulldef
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|
@@ -170,6 +170,7 @@ files:
|
|
170
170
|
- bin/console
|
171
171
|
- bin/setup
|
172
172
|
- lib/sequel/extensions/currency_rates.rb
|
173
|
+
- lib/sequel/extensions/deferrable_foreign_keys.rb
|
173
174
|
- lib/sequel/extensions/methods_in_migrations.rb
|
174
175
|
- lib/sequel/extensions/pg_tools.rb
|
175
176
|
- lib/sequel/extensions/slave.rb
|
@@ -207,8 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
207
208
|
- !ruby/object:Gem::Version
|
208
209
|
version: '0'
|
209
210
|
requirements: []
|
210
|
-
|
211
|
-
rubygems_version: 2.7.7
|
211
|
+
rubygems_version: 3.0.3
|
212
212
|
signing_key:
|
213
213
|
specification_version: 4
|
214
214
|
summary: Sequel plugins
|