sequel-pg_defer_constraints 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c9c60a6db2b4ee66abe96418eddc7984d85c09f7
4
+ data.tar.gz: e134632718afd33ffd74e2915fc95ed943531ff5
5
+ SHA512:
6
+ metadata.gz: 164c3836168ad8ef98261e17c85d9d0319ad25cc20df98ee24f9db6c3e78ad35f49fefd7ef5469c37aa1cd32bd45cbd3f98ccf9073aa3992805d8a59f94b8141
7
+ data.tar.gz: a92883af1a9722ec6505e94082bd77f7c254a866e0f49a0b9b3f1e27323c2340261cbe83e702dbe77cf56ca4f572c170fe202ba1cd298af62b5ae9984c7794f9
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sequel-pg_schema_data.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Gabriel Naiman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ # Sequel::Postgres::DeferConstraints
2
+
3
+ Disable and enable PG constraints
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'sequel-pg_defer_constraints'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install sequel-pg_defer_constraints
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ db = Sequel.connect ...
25
+
26
+ db.extension :pg_defer_constraints
27
+
28
+ db.defer_constraints :public, :custom_schema do
29
+ ...
30
+ end
31
+ ```
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/gabynaiman/sequel-pg_defer_constraints.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,31 @@
1
+ module Sequel
2
+ module Postgres
3
+ module DeferConstraintsMethods
4
+
5
+ def defer_constraints(*schemas)
6
+ schemas = ['public'] if schemas.empty?
7
+
8
+ tables_by_schema = schemas.each_with_object({}) do |schema, h|
9
+ h[schema] = self.from(Sequel[:information_schema][:tables])
10
+ .where(table_schema: schema, table_type: 'BASE TABLE')
11
+ .select_map(:table_name)
12
+ end
13
+
14
+ tables_by_schema.each do |schema, tables|
15
+ tables.each { |t| run "ALTER TABLE \"#{schema}\".\"#{t}\" DISABLE TRIGGER ALL" }
16
+ end
17
+
18
+ yield
19
+
20
+ ensure
21
+ tables_by_schema.each do |schema, tables|
22
+ tables.each { |t| run "ALTER TABLE \"#{schema}\".\"#{t}\" ENABLE TRIGGER ALL" }
23
+ end
24
+ end
25
+
26
+ end
27
+
28
+ Database.register_extension(:pg_defer_constraints, Postgres::DeferConstraintsMethods)
29
+
30
+ end
31
+ end
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'sequel-pg_defer_constraints'
7
+ spec.version = '0.0.1'
8
+ spec.authors = ['Gabriel Naiman']
9
+ spec.email = ['gabynaiman@gmail.com']
10
+ spec.summary = 'Disable and enable PG constraints'
11
+ spec.description = 'Disable and enable PG constraints'
12
+ spec.homepage = 'https://github.com/gabynaiman/sequel-pg_defer_constraints'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_runtime_dependency 'sequel', '>= 5'
21
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sequel-pg_defer_constraints
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gabriel Naiman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sequel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '5'
27
+ description: Disable and enable PG constraints
28
+ email:
29
+ - gabynaiman@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - Gemfile
36
+ - LICENSE.txt
37
+ - README.md
38
+ - Rakefile
39
+ - lib/sequel/extensions/pg_defer_constraints.rb
40
+ - sequel-pg_defer_constraints.gemspec
41
+ homepage: https://github.com/gabynaiman/sequel-pg_defer_constraints
42
+ licenses:
43
+ - MIT
44
+ metadata: {}
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 2.6.8
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: Disable and enable PG constraints
65
+ test_files: []