data_keeper 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +1 -0
- data/lib/data_keeper/database_config.rb +1 -1
- data/lib/data_keeper/definition.rb +1 -0
- data/lib/data_keeper/loader.rb +36 -18
- data/lib/data_keeper/version.rb +1 -1
- data/lib/data_keeper.rb +9 -0
- 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: 281f71c099696e1d51c88dd57e2cd0edf5f028bbbf4340c4457923e3a17b553a
|
4
|
+
data.tar.gz: 1592db229f9407735630803bff1a97bd85ed051ec30b878029952ffcfb272759
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf10459525a1cd3f210c6ef926b2b6d87a217505c8d8c8c155e99021d7a8837312fbf0038302987a683bf2a66f335d7507071451eff213ce004536ea42d26ca9
|
7
|
+
data.tar.gz: 30ff5218bb48851d938b96afba015e9076226b25342171e35ac47b5d78ecc8d8c3308afc2ffd6a94ded725495303da9a65f4394530a63cb193fcf005a90d4952
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/lib/data_keeper/loader.rb
CHANGED
@@ -20,48 +20,66 @@ module DataKeeper
|
|
20
20
|
end
|
21
21
|
|
22
22
|
if @dump.on_after_load_block
|
23
|
+
ActiveRecord::Base.establish_connection
|
23
24
|
@dump.on_after_load_block.call
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
27
28
|
private
|
28
29
|
|
29
|
-
def
|
30
|
-
|
30
|
+
def log_redirect
|
31
|
+
if Terrapin::CommandLine.logger
|
32
|
+
""
|
33
|
+
else
|
34
|
+
" 2>/dev/null"
|
35
|
+
end
|
36
|
+
end
|
31
37
|
|
32
|
-
|
33
|
-
|
34
|
-
|
38
|
+
def set_ar_internal_metadata!
|
39
|
+
cmd = Terrapin::CommandLine.new(
|
40
|
+
'psql',
|
41
|
+
"#{connection_args} -d :database -c :sql",
|
35
42
|
environment: psql_env
|
36
43
|
)
|
37
44
|
|
38
|
-
|
45
|
+
cmd.run(
|
39
46
|
database: database,
|
40
47
|
host: host,
|
41
|
-
port: port
|
48
|
+
port: port,
|
49
|
+
sql: "DELETE from ar_internal_metadata"
|
42
50
|
)
|
43
51
|
|
44
|
-
cmd
|
45
|
-
|
46
|
-
|
52
|
+
cmd.run(
|
53
|
+
database: database,
|
54
|
+
host: host,
|
55
|
+
port: port,
|
56
|
+
sql: "INSERT into ar_internal_metadata (key, value, created_at, updated_at) VALUES ('environment', 'development', '2020-04-03 12:25:54.094209', '2020-04-03 12:25:54.094209')"
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
def load_full_database!
|
61
|
+
ensure_schema_compatibility!
|
62
|
+
|
63
|
+
pg_restore = Terrapin::CommandLine.new(
|
64
|
+
'pg_restore',
|
65
|
+
"#{connection_args} -j 4 --no-owner --dbname #{database} #{@file.path}#{log_redirect}",
|
47
66
|
environment: psql_env
|
48
67
|
)
|
49
68
|
|
50
|
-
|
69
|
+
pg_restore.run(
|
51
70
|
database: database,
|
52
71
|
host: host,
|
53
|
-
port: port
|
54
|
-
sql: "UPDATE ar_internal_metadata SET value = 'development'"
|
72
|
+
port: port
|
55
73
|
)
|
74
|
+
|
75
|
+
set_ar_internal_metadata!
|
56
76
|
end
|
57
77
|
|
58
78
|
def load_partial_database!
|
59
79
|
inflate(@file.path) do |schema_path, tables_path, sql_files|
|
60
|
-
ensure_schema_compatibility!
|
61
|
-
|
62
80
|
pg_restore = Terrapin::CommandLine.new(
|
63
81
|
'pg_restore',
|
64
|
-
"#{connection_args} -j 4 --no-owner --dbname :database #{schema_path}
|
82
|
+
"#{connection_args} -j 4 --no-owner -s --dbname :database #{schema_path}#{log_redirect}",
|
65
83
|
environment: psql_env
|
66
84
|
)
|
67
85
|
|
@@ -73,7 +91,7 @@ module DataKeeper
|
|
73
91
|
|
74
92
|
pg_restore = Terrapin::CommandLine.new(
|
75
93
|
'pg_restore',
|
76
|
-
"#{connection_args} --data-only -j 4 --no-owner --disable-triggers --dbname :database #{tables_path}
|
94
|
+
"#{connection_args} --data-only -j 4 --no-owner --disable-triggers --dbname :database #{tables_path}#{log_redirect}",
|
77
95
|
environment: psql_env
|
78
96
|
)
|
79
97
|
|
@@ -99,7 +117,7 @@ module DataKeeper
|
|
99
117
|
)
|
100
118
|
end
|
101
119
|
|
102
|
-
|
120
|
+
set_ar_internal_metadata!
|
103
121
|
end
|
104
122
|
end
|
105
123
|
|
data/lib/data_keeper/version.rb
CHANGED
data/lib/data_keeper.rb
CHANGED
@@ -17,6 +17,7 @@ module DataKeeper
|
|
17
17
|
|
18
18
|
@dump_definition_builders = {}
|
19
19
|
@storage = nil
|
20
|
+
@database_config = -> { Rails.configuration.database_configuration[Rails.env] }
|
20
21
|
|
21
22
|
def self.define_dump(name, type = :partial, &block)
|
22
23
|
@dump_definition_builders[name.to_sym] = DefinitionBuilder.new(type, block)
|
@@ -59,6 +60,14 @@ module DataKeeper
|
|
59
60
|
@storage = value
|
60
61
|
end
|
61
62
|
|
63
|
+
def self.database_config=(value)
|
64
|
+
@database_config = value
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.database_config
|
68
|
+
@database_config
|
69
|
+
end
|
70
|
+
|
62
71
|
def self.clear_dumps!
|
63
72
|
@dump_definition_builders = {}
|
64
73
|
end
|
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.6
|
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-09-
|
11
|
+
date: 2021-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|