uff_db_loader 2.1.0 → 3.0.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/.github/workflows/test.yml +1 -1
- data/.standard.yml +1 -1
- data/README.md +1 -0
- data/lib/configuration.rb +12 -1
- data/lib/uff_db_loader/mysql.rb +1 -1
- data/lib/uff_db_loader/postgresql.rb +1 -1
- data/lib/uff_db_loader/tasks/uff_db_loader.rake +7 -4
- data/lib/uff_db_loader/templates/uff_db_loader_initializer.erb +1 -0
- data/lib/uff_db_loader/version.rb +1 -1
- data/lib/uff_db_loader.rb +13 -5
- data/uff_db_loader.gemspec +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68a5cb60e3cf41f8a59e5ff1f0c08c6d186473633adbf8976f9ffc8b23f86af2
|
4
|
+
data.tar.gz: 44dda910a3252b9f5c2b2d9b6c3b82c60a78e4d07855f774cab8b7676db2ef28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8550673f5245e23f16d92fbf89f231db925f4827c9ba3ee35bfc2bcd94d8cf32a5b138a9012eeb957fe87f6b83dbf20a3a051801ddee54e4e40f28a587edc80e
|
7
|
+
data.tar.gz: 450d57b8b60f9d5d0c847d67b18144ae5ec5a8c415fd1b5f2fa5a90039f61190db61484f0e7a4092cfc14ca0e8ccd0542c3deed6a7e9ead3b8636c9f2d0b1928
|
data/.github/workflows/test.yml
CHANGED
data/.standard.yml
CHANGED
data/README.md
CHANGED
@@ -37,6 +37,7 @@ UffDbLoader.configure do |config|
|
|
37
37
|
config.app_name = 'my_app' # Defaults to the Rails app name
|
38
38
|
config.dumps_directory = '/path/to/dumps' # Defaults to Rails.root.join('dumps')
|
39
39
|
config.database_config_file = 'path/to/database.yml' # Defaults to Rails.root.join('config', 'database.yml')
|
40
|
+
config.container_name = ->(app_name, environment) { "#{app_name}_#{environment}_custom_suffix" } # Defaults to "#{app_name}_#{environment}_db". It accepts a static string too.
|
40
41
|
end
|
41
42
|
```
|
42
43
|
For example in a file like `config/initializers/uff_db_loader.rb`.
|
data/lib/configuration.rb
CHANGED
@@ -5,7 +5,17 @@ require "uff_db_loader/mysql"
|
|
5
5
|
|
6
6
|
module UffDbLoader
|
7
7
|
class Configuration
|
8
|
-
attr_accessor
|
8
|
+
attr_accessor(
|
9
|
+
:environments,
|
10
|
+
:ssh_host,
|
11
|
+
:ssh_user,
|
12
|
+
:db_name,
|
13
|
+
:db_system,
|
14
|
+
:app_name,
|
15
|
+
:dumps_directory,
|
16
|
+
:database_config_file,
|
17
|
+
:container_name
|
18
|
+
)
|
9
19
|
|
10
20
|
def initialize
|
11
21
|
@environments = nil
|
@@ -16,6 +26,7 @@ module UffDbLoader
|
|
16
26
|
@app_name = Dir.pwd.split("/").last
|
17
27
|
@dumps_directory = File.join(Dir.pwd, "dumps")
|
18
28
|
@database_config_file = File.join(Dir.pwd, "config", "database.yml")
|
29
|
+
@container_name = nil
|
19
30
|
end
|
20
31
|
|
21
32
|
def database
|
data/lib/uff_db_loader/mysql.rb
CHANGED
@@ -7,7 +7,7 @@ module UffDbLoader
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def self.dump_command_template
|
10
|
-
"ssh %user%@%host% \"docker exec -i %
|
10
|
+
"ssh %user%@%host% \"docker exec -i %container_name% sh -c 'exec mysqldump --opt --no-tablespaces -uroot -p\"\\$MYSQL_ROOT_PASSWORD\" %database%'\" > %target%"
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.restore_command(database_name, result_file_path)
|
@@ -7,7 +7,7 @@ module UffDbLoader
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def self.dump_command_template
|
10
|
-
"ssh %user%@%host% \"docker exec -i %
|
10
|
+
"ssh %user%@%host% \"docker exec -i %container_name% sh -c 'exec pg_dump --username \\$POSTGRES_USER --clean --no-owner --no-acl --format=c %database%'\" > %target%"
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.restore_command(database_name, result_file_path)
|
@@ -29,6 +29,11 @@ namespace :uff_db_loader do
|
|
29
29
|
task restore: :environment do
|
30
30
|
UffDbLoader.ensure_installation!
|
31
31
|
|
32
|
+
# switch to default db so we can restore the currently connected database
|
33
|
+
UffDbLoader.remember_database_name("")
|
34
|
+
ActiveRecord::Base.remove_connection
|
35
|
+
ActiveRecord::Base.establish_connection(Rails.configuration.database_configuration["development"])
|
36
|
+
|
32
37
|
prompt = TTY::Prompt.new
|
33
38
|
existing_dumps = Dir.glob("#{UffDbLoader.config.dumps_directory}/#{UffDbLoader.config.app_name}*").map { |f| File.basename(f, ".*") }
|
34
39
|
database_name = prompt.select("Which dump should be restored?", existing_dumps)
|
@@ -67,11 +72,9 @@ namespace :uff_db_loader do
|
|
67
72
|
|
68
73
|
desc "Delete all downloaded db dumps and removes all databases created by UffDbLoader"
|
69
74
|
task prune: :environment do
|
70
|
-
# switch to default db so we can also drop the currently connected database
|
71
|
-
UffDbLoader.remember_database_name("")
|
72
|
-
ActiveRecord::Base.connection.reconnect!
|
73
|
-
|
74
75
|
UffDbLoader.databases.each do |database_name|
|
76
|
+
next if database_name == ActiveRecord::Base.connection.current_database
|
77
|
+
|
75
78
|
puts "Dropping #{database_name}"
|
76
79
|
UffDbLoader.drop_database(database_name)
|
77
80
|
end
|
@@ -14,5 +14,6 @@ if defined?(UffDbLoader)
|
|
14
14
|
# config.app_name = 'my_app' # Defaults to the Rails app name
|
15
15
|
# config.dumps_directory = '/path/to/dumps' # Defaults to Rails.root.join('dumps')
|
16
16
|
# config.database_config_file = 'path/to/database.yml' # Defaults to Rails.root.join('config', 'database.yml')
|
17
|
+
# config.container_name = ->(app_name, environment) { "#{app_name}_#{environment}_custom_suffix" } # Defaults to "#{app_name}_#{environment}_db". It accepts a static string too.
|
17
18
|
end
|
18
19
|
end
|
data/lib/uff_db_loader.rb
CHANGED
@@ -45,7 +45,9 @@ module UffDbLoader
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def prune_dump_directory
|
48
|
-
FileUtils.
|
48
|
+
FileUtils.rm_f(
|
49
|
+
FileList["#{config.dumps_directory}/*"].exclude(dump_file_path(current_database_name)).to_a
|
50
|
+
)
|
49
51
|
end
|
50
52
|
|
51
53
|
def create_database(database_name)
|
@@ -74,8 +76,8 @@ module UffDbLoader
|
|
74
76
|
|
75
77
|
def current_database_name
|
76
78
|
File.read(database_name_file).strip.presence
|
77
|
-
rescue IOError, Errno::ENOENT
|
78
|
-
|
79
|
+
rescue IOError, Errno::ENOENT
|
80
|
+
# We expect this file to be missing in non-dev environments.
|
79
81
|
end
|
80
82
|
|
81
83
|
def remember_database_name(database_name)
|
@@ -125,6 +127,13 @@ module UffDbLoader
|
|
125
127
|
|
126
128
|
private
|
127
129
|
|
130
|
+
def container_name(environment)
|
131
|
+
return "#{config.app_name}_#{environment}_db" if config.container_name.blank?
|
132
|
+
return config.container_name unless config.container_name.respond_to? :call
|
133
|
+
|
134
|
+
config.container_name.call(config.app_name, environment)
|
135
|
+
end
|
136
|
+
|
128
137
|
def initializer_template_path
|
129
138
|
File.join(__dir__, "uff_db_loader", "templates", "uff_db_loader_initializer.erb")
|
130
139
|
end
|
@@ -144,12 +153,11 @@ module UffDbLoader
|
|
144
153
|
config
|
145
154
|
.database_system
|
146
155
|
.dump_command_template
|
147
|
-
.gsub("%environment%", environment)
|
148
156
|
.gsub("%host%", config.ssh_host)
|
149
157
|
.gsub("%user%", config.ssh_user)
|
150
158
|
.gsub("%database%", config.database)
|
151
159
|
.gsub("%target%", target)
|
152
|
-
.gsub("%
|
160
|
+
.gsub("%container_name%", container_name(environment))
|
153
161
|
end
|
154
162
|
|
155
163
|
def restore_command(database_name, result_file_path)
|
data/uff_db_loader.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.post_install_message = "Please run `bin/rails uff_db_loader:install` to complete the installation."
|
12
12
|
spec.homepage = "https://github.com/rmehner/uff_db_loader"
|
13
13
|
spec.license = "MIT"
|
14
|
-
spec.required_ruby_version = Gem::Requirement.new(">=
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0")
|
15
15
|
|
16
16
|
spec.metadata = {
|
17
17
|
"bug_tracker_uri" => "#{spec.homepage}/issues",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uff_db_loader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andreas Hellwig
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2023-04-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: tty-prompt
|
@@ -88,9 +88,9 @@ licenses:
|
|
88
88
|
- MIT
|
89
89
|
metadata:
|
90
90
|
bug_tracker_uri: https://github.com/rmehner/uff_db_loader/issues
|
91
|
-
changelog_uri: https://github.com/rmehner/uff_db_loader/releases/tag/
|
91
|
+
changelog_uri: https://github.com/rmehner/uff_db_loader/releases/tag/3.0.0
|
92
92
|
homepage_uri: https://github.com/rmehner/uff_db_loader
|
93
|
-
source_code_uri: https://github.com/rmehner/uff_db_loader/tree/
|
93
|
+
source_code_uri: https://github.com/rmehner/uff_db_loader/tree/3.0.0
|
94
94
|
post_install_message: Please run `bin/rails uff_db_loader:install` to complete the
|
95
95
|
installation.
|
96
96
|
rdoc_options: []
|
@@ -100,14 +100,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
103
|
+
version: 3.0.0
|
104
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
105
|
requirements:
|
106
106
|
- - ">="
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
version: '0'
|
109
109
|
requirements: []
|
110
|
-
rubygems_version: 3.
|
110
|
+
rubygems_version: 3.4.6
|
111
111
|
signing_key:
|
112
112
|
specification_version: 4
|
113
113
|
summary: Allows to dump, download and restore databases from docker servers.
|