data_keeper 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/data_keeper.rb +11 -7
- data/lib/data_keeper/definition.rb +7 -9
- data/lib/data_keeper/dumper.rb +2 -2
- data/lib/data_keeper/loader.rb +3 -3
- data/lib/data_keeper/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 246804bd313245cf8d56ab51d8784545efa1985af2303ec3827a7db48a0b8401
|
4
|
+
data.tar.gz: 1833267238192680890e3f021fc6cfc67a0677567df97517eb65a59680bb38e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb3182638b4eb1713a6d567051e6c66f90aa0c25c247d8e5e6250525525721a893f74838ed8754b34d3bf957a47d22678e067992157e731bb7b68e74e6bdbb75
|
7
|
+
data.tar.gz: 26a5cadb9d451db4af9069167b9fb605f6dbbc545e623d5d3eeb42d3360120688d9f6767332e93df2b5cb0fc343e105b4209e899ff2bbd91037330790b8782ab
|
data/README.md
CHANGED
@@ -46,6 +46,9 @@ DataKeeper.storage = DataKeeper::LocalStorage.new(
|
|
46
46
|
There's also support for storing the dumps in s3, using `DataKeeper::S3Storage` like in this example:
|
47
47
|
|
48
48
|
```ruby
|
49
|
+
# Explicit require is necessary
|
50
|
+
require 'data_keeper/s3_storage'
|
51
|
+
|
49
52
|
DataKeeper.storage = DataKeeper::S3Storage.new(
|
50
53
|
bucket: 'bucket-name',
|
51
54
|
store_dir: 'dumps/',
|
data/lib/data_keeper.rb
CHANGED
@@ -15,18 +15,20 @@ module DataKeeper
|
|
15
15
|
DumpDoesNotExist = Class.new(Error)
|
16
16
|
NoStorageDefined = Class.new(Error)
|
17
17
|
|
18
|
-
@
|
18
|
+
@dump_definition_builders = {}
|
19
19
|
@storage = nil
|
20
20
|
|
21
21
|
def self.define_dump(name, type = :partial, &block)
|
22
|
-
@
|
22
|
+
@dump_definition_builders[name.to_sym] = DefinitionBuilder.new(type, block)
|
23
23
|
end
|
24
24
|
|
25
25
|
def self.create_dump!(name)
|
26
26
|
raise DumpDoesNotExist unless dump?(name)
|
27
27
|
raise NoStorageDefined if @storage.nil?
|
28
28
|
|
29
|
-
|
29
|
+
definition = @dump_definition_builders[name.to_sym].evaluate!
|
30
|
+
|
31
|
+
Dumper.new(name, definition).run! do |file, filename|
|
30
32
|
@storage.save(file, filename, name)
|
31
33
|
end
|
32
34
|
end
|
@@ -34,9 +36,10 @@ module DataKeeper
|
|
34
36
|
def self.fetch_and_load_dump!(name)
|
35
37
|
raise DumpDoesNotExist unless dump?(name)
|
36
38
|
raise NoStorageDefined if @storage.nil?
|
39
|
+
definition = @dump_definition_builders[name.to_sym].evaluate!
|
37
40
|
|
38
41
|
@storage.retrieve(name) do |file|
|
39
|
-
Loader.new(
|
42
|
+
Loader.new(definition, file).load!
|
40
43
|
end
|
41
44
|
end
|
42
45
|
|
@@ -44,11 +47,12 @@ module DataKeeper
|
|
44
47
|
raise DumpDoesNotExist unless File.file?(path)
|
45
48
|
raise NoStorageDefined if @storage.nil?
|
46
49
|
|
47
|
-
|
50
|
+
definition = @dump_definition_builders[name.to_sym].evaluate!
|
51
|
+
Loader.new(definition, File.open(path)).load!
|
48
52
|
end
|
49
53
|
|
50
54
|
def self.dump?(name)
|
51
|
-
@
|
55
|
+
@dump_definition_builders.key?(name.to_sym)
|
52
56
|
end
|
53
57
|
|
54
58
|
def self.storage=(value)
|
@@ -56,6 +60,6 @@ module DataKeeper
|
|
56
60
|
end
|
57
61
|
|
58
62
|
def self.clear_dumps!
|
59
|
-
@
|
63
|
+
@dump_definition_builders = {}
|
60
64
|
end
|
61
65
|
end
|
@@ -26,21 +26,19 @@ module DataKeeper
|
|
26
26
|
end
|
27
27
|
|
28
28
|
class DefinitionBuilder
|
29
|
-
|
29
|
+
def initialize(type, definition_block)
|
30
|
+
raise InvalidDumpType, "Invalid type! use :partial or :full" unless [:partial, :full].include?(type)
|
30
31
|
|
31
|
-
|
32
|
+
@type = type
|
32
33
|
@tables = []
|
33
34
|
@raw_sqls = {}
|
34
|
-
|
35
|
+
@definition_block = definition_block
|
35
36
|
end
|
36
37
|
|
37
|
-
def
|
38
|
-
|
39
|
-
raise InvalidDumpType, "Invalid type! use :partial or :full" unless [:partial, :full].include?(type)
|
40
|
-
|
41
|
-
builder = new(block)
|
38
|
+
def evaluate!
|
39
|
+
instance_eval(&@definition_block) if @definition_block
|
42
40
|
|
43
|
-
Definition.new(type,
|
41
|
+
Definition.new(@type, @tables, @raw_sqls, @on_after_load_block)
|
44
42
|
end
|
45
43
|
|
46
44
|
def table(name)
|
data/lib/data_keeper/dumper.rb
CHANGED
@@ -35,7 +35,7 @@ module DataKeeper
|
|
35
35
|
output_path: file.path
|
36
36
|
)
|
37
37
|
|
38
|
-
yield file, "#{filename}.dump"
|
38
|
+
yield File.open(file.path), "#{filename}.dump"
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -51,7 +51,7 @@ module DataKeeper
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
yield file, "#{filename}.tar.gz"
|
54
|
+
yield File.open(file.path), "#{filename}.tar.gz"
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
data/lib/data_keeper/loader.rb
CHANGED
@@ -54,7 +54,7 @@ module DataKeeper
|
|
54
54
|
inflate(@file.path) do |schema_path, tables_path, sql_files|
|
55
55
|
pg_restore = Terrapin::CommandLine.new(
|
56
56
|
'pg_restore',
|
57
|
-
"#{connection_args} -j 4 --no-owner --dbname
|
57
|
+
"#{connection_args} -j 4 --no-owner --dbname :database #{schema_path} 2>/dev/null",
|
58
58
|
environment: psql_env
|
59
59
|
)
|
60
60
|
|
@@ -66,7 +66,7 @@ module DataKeeper
|
|
66
66
|
|
67
67
|
pg_restore = Terrapin::CommandLine.new(
|
68
68
|
'pg_restore',
|
69
|
-
"#{connection_args} -
|
69
|
+
"#{connection_args} --data-only -j 4 --no-owner --disable-triggers --dbname :database #{tables_path} 2>/dev/null",
|
70
70
|
environment: psql_env
|
71
71
|
)
|
72
72
|
|
@@ -88,7 +88,7 @@ module DataKeeper
|
|
88
88
|
host: host,
|
89
89
|
port: port,
|
90
90
|
csv_path: csv_path,
|
91
|
-
command: "COPY #{table} FROM stdin DELIMITER ',' CSV HEADER"
|
91
|
+
command: "ALTER TABLE #{table} DISABLE TRIGGER all; COPY #{table} FROM stdin DELIMITER ',' CSV HEADER"
|
92
92
|
)
|
93
93
|
end
|
94
94
|
|
data/lib/data_keeper/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_keeper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roger Campos
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-07-
|
11
|
+
date: 2021-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|