sequel-pg_schema_data 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4414e3f58905b21d69846a1c29776398356715ec
4
+ data.tar.gz: 9e3ef00642babb22f340299cbd58b683f00dbcdc
5
+ SHA512:
6
+ metadata.gz: f8d206e51d9178d1b8459c1e12490108dd5168f0b0f844922ee3a8bf0371a8dfc2094061a65c14f0b37183ac1c47cbf07cf60976087d61087df3fff3fb98215a
7
+ data.tar.gz: ad498ee16f4dcf2628c41ab493477475e7f7033685c62e2ea6e8526a3804ac1c6d49d1e6fe8f48cfdd4b265b1d7050fa7c3c740ccfc716b338608e480d37a792
data/.gitignore ADDED
@@ -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
data/LICENSE.txt ADDED
@@ -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.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Sequel::Postgres::SchemaData
2
+
3
+ Dump and load data from specific schema in CSV format
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'sequel-pg_schema_data'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install sequel-pg_schema_data
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ db = Sequel.connect ...
25
+
26
+ db.extension :pg_schema_data
27
+
28
+ db.dump_schema_data :public, 'path/to/data', ignore: [:table_name]
29
+
30
+ db.load_schema_data :public, 'path/to/data'
31
+ ```
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/gabynaiman/sequel-pg_schema_data.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,35 @@
1
+ module Sequel
2
+ module Postgres
3
+ module SchemaDataMethods
4
+
5
+ def dump_schema_data(schema, path, options={})
6
+ FileUtils.rm_rf path
7
+ FileUtils.mkpath path
8
+
9
+ tables = self.from(Sequel[:information_schema][:tables])
10
+ .where(table_schema: schema.to_s, table_type: 'BASE TABLE')
11
+ .select_map(:table_name)
12
+ .map(&:to_sym)
13
+
14
+ tables = tables - options.fetch(:ignore, [])
15
+
16
+ tables.each do |table|
17
+ File.write File.join(path, "#{table}.csv"), copy_table(Sequel.qualify(schema, table), format: :csv)
18
+ end
19
+ end
20
+
21
+ def load_schema_data(schema, path)
22
+ transaction do
23
+ Dir[File.join(path, '*.csv')].each do |filename|
24
+ table = File.basename filename, '.csv'
25
+ copy_into Sequel.qualify(schema, table), data: File.read(filename), format: :csv
26
+ end
27
+ end
28
+ end
29
+
30
+ end
31
+
32
+ Database.register_extension(:pg_schema_data, Postgres::SchemaDataMethods)
33
+
34
+ end
35
+ 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_schema_data'
7
+ spec.version = '0.0.1'
8
+ spec.authors = ['Gabriel Naiman']
9
+ spec.email = ['gabynaiman@gmail.com']
10
+ spec.summary = 'Dump and load data from specific schema in CSV format'
11
+ spec.description = 'Dump and load data from specific schema in CSV format'
12
+ spec.homepage = 'https://github.com/gabynaiman/sequel-pg_schema_data'
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_schema_data
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: Dump and load data from specific schema in CSV format
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_schema_data.rb
40
+ - sequel-pg_schema_data.gemspec
41
+ homepage: https://github.com/gabynaiman/sequel-pg_schema_data
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: Dump and load data from specific schema in CSV format
65
+ test_files: []