pg_tasks 1.0.1 → 1.1.0
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/Rakefile +0 -2
- data/lib/pg_tasks/railtie.rb +2 -2
- data/lib/pg_tasks/version.rb +3 -3
- data/lib/pg_tasks.rb +23 -23
- data/lib/tasks/pg_tasks.rake +2 -10
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc265a9b51988c66412de5651644fe6427761bd0
|
4
|
+
data.tar.gz: 7326fe644b0d418c17707e6f80600c3554ba9c61
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b005994e668eb75f856f12ad35b17d671cea87a31779ee6bd519a7035147b01dd478f95d150f800e0b4faee7920858e50dd1289403c08ea21c4e0d7e99a826a7
|
7
|
+
data.tar.gz: 5bfd6120421f4f5606a274e7840c23c474846eaed9150d04e60b898c594d068f9bcb02b1d0415c959e504c84a5df5317d8e709f5ccb68f50ce19b36b4c974462
|
data/Rakefile
CHANGED
data/lib/pg_tasks/railtie.rb
CHANGED
data/lib/pg_tasks/version.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
#--
|
2
2
|
# Copyright (c) 2015 Thomas Schank
|
3
3
|
#
|
4
|
-
# Released to the public under the terms of the MIT license.
|
5
|
-
# See MIT-LICENSE.
|
4
|
+
# Released to the public under the terms of the MIT license.
|
5
|
+
# See MIT-LICENSE.
|
6
6
|
#
|
7
7
|
#++
|
8
8
|
|
9
9
|
module PgTasks
|
10
|
-
VERSION =
|
10
|
+
VERSION = '1.1.0'
|
11
11
|
end
|
data/lib/pg_tasks.rb
CHANGED
@@ -1,23 +1,21 @@
|
|
1
1
|
#--
|
2
2
|
# Copyright (c) 2015 Thomas Schank
|
3
3
|
#
|
4
|
-
# Released to the public under the terms of the MIT license.
|
5
|
-
# See MIT-LICENSE.
|
4
|
+
# Released to the public under the terms of the MIT license.
|
5
|
+
# See MIT-LICENSE.
|
6
6
|
#
|
7
7
|
#++
|
8
|
-
|
8
|
+
|
9
9
|
require 'active_record/tasks/database_tasks'
|
10
10
|
require 'active_record/tasks/postgresql_database_tasks'
|
11
11
|
|
12
12
|
module PgTasks
|
13
|
-
|
14
13
|
require 'pg_tasks/railtie' if defined?(Rails)
|
15
14
|
|
16
15
|
DEFAULT_BINARY_DATA_FILE_NAME = 'data.pgbin'
|
17
16
|
DEFAULT_BINARY_STRUCTURE_AND_DATA_FILE_NAME = 'structure_and_data.pgbin'
|
18
17
|
|
19
18
|
class << self
|
20
|
-
|
21
19
|
%w(data_dump data_restore).each do |method_name|
|
22
20
|
define_method method_name do |filename = nil|
|
23
21
|
ActiveRecord::Tasks::DatabaseTasks \
|
@@ -29,17 +27,17 @@ module PgTasks
|
|
29
27
|
|
30
28
|
%w(structure_and_data_dump structure_and_data_restore).each do |method_name|
|
31
29
|
define_method method_name do |filename = nil|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
30
|
+
ActiveRecord::Tasks::DatabaseTasks \
|
31
|
+
.perform_pg_db_task_for_config_and_filename \
|
32
|
+
method_name, current_config,
|
33
|
+
filename_or_default_binary_structure_and_data_file(filename)
|
36
34
|
end
|
37
35
|
end
|
38
36
|
|
39
37
|
def truncate_tables
|
40
38
|
ActiveRecord::Base.connection.tap do |connection|
|
41
39
|
connection.tables.reject { |tn| tn == 'schema_migrations' }
|
42
|
-
|
40
|
+
.join(', ').tap do |tables|
|
43
41
|
connection.execute " TRUNCATE TABLE #{tables} CASCADE; "
|
44
42
|
end
|
45
43
|
end
|
@@ -62,32 +60,37 @@ module PgTasks
|
|
62
60
|
File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir,
|
63
61
|
DEFAULT_BINARY_STRUCTURE_AND_DATA_FILE_NAME)
|
64
62
|
end
|
65
|
-
|
66
63
|
end
|
67
64
|
end
|
68
65
|
|
69
66
|
module ActiveRecord
|
70
67
|
module Tasks
|
71
68
|
class PostgreSQLDatabaseTasks
|
72
|
-
|
73
69
|
def data_dump(filename)
|
74
70
|
set_psql_env
|
75
71
|
command = 'pg_dump -F c -a -T schema_migrations -x -O -f ' \
|
76
72
|
"#{Shellwords.escape(filename)} " \
|
77
73
|
"#{Shellwords.escape(configuration['database'])}"
|
78
|
-
|
79
|
-
|
80
|
-
|
74
|
+
unless Kernel.system(command)
|
75
|
+
raise 'Error during data_dump'
|
76
|
+
else
|
77
|
+
$stdout.puts "The data of '#{configuration['database']} " \
|
78
|
+
"has been dumped to '#{filename}'"
|
79
|
+
end
|
81
80
|
end
|
82
81
|
|
83
82
|
def data_restore(filename)
|
84
83
|
set_psql_env
|
85
|
-
command = 'pg_restore --disable-triggers
|
86
|
-
|
84
|
+
command = 'pg_restore --disable-triggers ' \
|
85
|
+
'--single-transaction -a -x -O ' \
|
86
|
+
"-d #{Shellwords.escape(configuration['database'])} " \
|
87
87
|
"#{Shellwords.escape(filename)}"
|
88
|
-
|
89
|
-
|
88
|
+
unless Kernel.system(command)
|
89
|
+
raise 'Error during data_restore '
|
90
|
+
else
|
91
|
+
$stdout.puts "Data from '#{filename}' has been restored to \
|
90
92
|
'#{configuration['database']}'"
|
93
|
+
end
|
91
94
|
end
|
92
95
|
|
93
96
|
def structure_and_data_dump(filename)
|
@@ -105,7 +108,7 @@ module ActiveRecord
|
|
105
108
|
|
106
109
|
def structure_and_data_restore(filename)
|
107
110
|
set_psql_env
|
108
|
-
command = 'pg_restore --disable-triggers -x -O -d ' \
|
111
|
+
command = 'pg_restore --disable-triggers --single-transaction -x -O -d ' \
|
109
112
|
"#{Shellwords.escape(configuration['database'])} " \
|
110
113
|
"#{Shellwords.escape(filename)}"
|
111
114
|
unless Kernel.system(command)
|
@@ -115,7 +118,6 @@ module ActiveRecord
|
|
115
118
|
"has been restored to '#{filename}'"
|
116
119
|
end
|
117
120
|
end
|
118
|
-
|
119
121
|
end
|
120
122
|
end
|
121
123
|
end
|
@@ -123,7 +125,6 @@ end
|
|
123
125
|
module ActiveRecord
|
124
126
|
module Tasks
|
125
127
|
module DatabaseTasks
|
126
|
-
|
127
128
|
def perform_pg_db_task_for_config_and_filename(task_name, *arguments)
|
128
129
|
configuration = arguments.first
|
129
130
|
filename = arguments.delete_at 1
|
@@ -134,7 +135,6 @@ module ActiveRecord
|
|
134
135
|
rescue Exception => error
|
135
136
|
$stderr.puts error, *(error.backtrace)
|
136
137
|
end
|
137
|
-
|
138
138
|
end
|
139
139
|
end
|
140
140
|
end
|
data/lib/tasks/pg_tasks.rake
CHANGED
@@ -1,23 +1,20 @@
|
|
1
1
|
#--
|
2
2
|
# Copyright (c) 2015 Thomas Schank
|
3
3
|
#
|
4
|
-
# Released to the public under the terms of the MIT license.
|
5
|
-
# See MIT-LICENSE.
|
4
|
+
# Released to the public under the terms of the MIT license.
|
5
|
+
# See MIT-LICENSE.
|
6
6
|
#
|
7
7
|
#++
|
8
8
|
|
9
9
|
require 'pg_tasks'
|
10
10
|
|
11
11
|
namespace :db do
|
12
|
-
|
13
12
|
namespace :pg do
|
14
|
-
|
15
13
|
task truncate_tables: [:environment, :load_config] do
|
16
14
|
PgTasks.truncate_tables
|
17
15
|
end
|
18
16
|
|
19
17
|
namespace :data do
|
20
|
-
|
21
18
|
task dump: [:environment, :load_config] do
|
22
19
|
PgTasks.data_dump ENV['FILE']
|
23
20
|
end
|
@@ -25,11 +22,9 @@ namespace :db do
|
|
25
22
|
task restore: [:environment, :load_config] do
|
26
23
|
PgTasks.data_restore ENV['FILE']
|
27
24
|
end
|
28
|
-
|
29
25
|
end
|
30
26
|
|
31
27
|
namespace :structure_and_data do
|
32
|
-
|
33
28
|
task dump: [:environment, :load_config] do
|
34
29
|
PgTasks.structure_and_data_dump ENV['FILE']
|
35
30
|
end
|
@@ -37,9 +32,6 @@ namespace :db do
|
|
37
32
|
task restore: [:environment, :load_config] do
|
38
33
|
PgTasks.structure_and_data_restore ENV['FILE']
|
39
34
|
end
|
40
|
-
|
41
35
|
end
|
42
|
-
|
43
36
|
end
|
44
|
-
|
45
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg_tasks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Schank
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -44,6 +44,20 @@ dependencies:
|
|
44
44
|
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rubocop
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
47
61
|
description:
|
48
62
|
email:
|
49
63
|
- DrTom@schank.ch
|