uff_db_loader 1.1.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/uff_db_loader/tasks/remote_database.rake +6 -31
- data/lib/uff_db_loader/tasks/uff_db_loader.rake +76 -0
- data/lib/uff_db_loader/version.rb +1 -1
- data/lib/uff_db_loader.rb +62 -0
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b64fcfeeeda9c2895262cabcf104828511ae1a17abe6c906c040f5b132c48bc3
|
4
|
+
data.tar.gz: 166953900412522babe8958ddbadef253b8e3558c487d67c53962679252dbd29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf80b9b22d70bf31fe2b8f2d4c9d2f84e9b23a5448e2a94fcdbfe43fdd5a4155a06da935846f3df41cf34528b1e71a17dcc697bce68a5263e09becad424ae31c
|
7
|
+
data.tar.gz: 74b533e7f45a5b5292d74c7660709f14b60f2a3c8dfa61f390314c4145f7cdcc00f079cd3c253f24f44599518b16eb00ea6edcb37640139f2e1ae9b214b64c19
|
data/README.md
CHANGED
@@ -43,7 +43,7 @@ Make sure the app's database user has the superuser role. Otherwise the app will
|
|
43
43
|
|
44
44
|
## Usage
|
45
45
|
|
46
|
-
`uff_db_loader` provides `rails
|
46
|
+
`uff_db_loader` provides `rails uff_db_loader:dump` and `rails uff_db_loader:load` which will prompt for a configured environment.
|
47
47
|
`dump` will only create and download a current database dump, while `load`, will do the same and restore the database content into a new database and gives instructions on how to use it in development.
|
48
48
|
|
49
49
|
|
@@ -5,44 +5,19 @@ require "tty-prompt"
|
|
5
5
|
namespace :remote_database do
|
6
6
|
desc "Dumps a remote database to #{UffDbLoader.config.dumps_directory}"
|
7
7
|
task dump: :environment do
|
8
|
-
|
9
|
-
|
10
|
-
UffDbLoader.ensure_valid_environment!(environment)
|
11
|
-
UffDbLoader.dump_from(environment)
|
8
|
+
puts "🧐 Please note this task is called 'uff_db_loader:dump' now."
|
9
|
+
Rake::Task["uff_db_loader:dump"].invoke
|
12
10
|
end
|
13
11
|
|
14
12
|
desc "Gets a dump from remote and loads it into the local database"
|
15
13
|
task load: :environment do
|
16
|
-
|
17
|
-
|
18
|
-
UffDbLoader.ensure_valid_environment!(environment)
|
19
|
-
result_file_path = UffDbLoader.dump_from(environment)
|
20
|
-
|
21
|
-
puts "🤓 Reading from to #{result_file_path}"
|
22
|
-
|
23
|
-
database_name = File.basename(result_file_path, ".*")
|
24
|
-
UffDbLoader.create_database(database_name)
|
25
|
-
|
26
|
-
puts "🗂 Created database #{database_name}"
|
27
|
-
|
28
|
-
command_successful = system(UffDbLoader.restore_command(database_name, result_file_path))
|
29
|
-
raise "Command did not run succesful: #{UffDbLoader.restore_command(database_name, result_file_path)}" unless command_successful
|
30
|
-
|
31
|
-
puts "✅ Succesfully loaded #{result_file_path} into #{database_name}"
|
32
|
-
|
33
|
-
puts "💩 Because YAML is a wonderful format, you need to adapt your config file by hand."
|
34
|
-
puts "🆗 Go to #{UffDbLoader.config.database_config_file} and change the development database value to: #{database_name}"
|
35
|
-
puts "🧑🏾🏫 Don't forgot to restart the Rails server after changing the database config (`rails restart`)"
|
14
|
+
puts "🧐 Please note this task is called 'uff_db_loader:load' now."
|
15
|
+
Rake::Task["uff_db_loader:load"].invoke
|
36
16
|
end
|
37
17
|
|
38
18
|
desc "Delete all downloaded db dumps and emove all databases created by UffDbLoader"
|
39
19
|
task prune: :environment do
|
40
|
-
|
41
|
-
|
42
|
-
UffDbLoader.drop_database(database_name)
|
43
|
-
end
|
44
|
-
|
45
|
-
puts "Removing dumps from #{UffDbLoader.config.dumps_directory}"
|
46
|
-
UffDbLoader.prune_dump_directory
|
20
|
+
puts "🧐 Please note this task is called 'uff_db_loader:prune' now."
|
21
|
+
Rake::Task["uff_db_loader:prune"].invoke
|
47
22
|
end
|
48
23
|
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "tty-prompt"
|
4
|
+
|
5
|
+
namespace :uff_db_loader do
|
6
|
+
desc "Install uff_db_loader"
|
7
|
+
task install: :environment do
|
8
|
+
UffDbLoader.remember_database_name("") # ensure database file exists
|
9
|
+
|
10
|
+
if UffDbLoader.setup_dynamic_database_name_in_config
|
11
|
+
puts "🤖 Updated #{UffDbLoader.config.database_config_file}. Happy hacking, beep boop!"
|
12
|
+
else
|
13
|
+
puts "💩 Because YAML is a wonderful format, you need to adapt your config file by hand."
|
14
|
+
puts "🆗 Go to #{UffDbLoader.config.database_config_file} and change the development database value to: #{UffDbLoader.database_name_template("default_database_name")}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "Dumps a remote database to #{UffDbLoader.config.dumps_directory}"
|
19
|
+
task dump: :environment do
|
20
|
+
prompt = TTY::Prompt.new
|
21
|
+
environment = prompt.select("Which environment should we get the dump from?", UffDbLoader.config.environments)
|
22
|
+
UffDbLoader.ensure_valid_environment!(environment)
|
23
|
+
UffDbLoader.dump_from(environment)
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "Gets a dump from remote and loads it into the local database"
|
27
|
+
task load: :environment do
|
28
|
+
UffDbLoader.ensure_installation!
|
29
|
+
|
30
|
+
prompt = TTY::Prompt.new
|
31
|
+
environment = prompt.select("Which environment should we get the dump from?", UffDbLoader.config.environments)
|
32
|
+
UffDbLoader.ensure_valid_environment!(environment)
|
33
|
+
result_file_path = UffDbLoader.dump_from(environment)
|
34
|
+
|
35
|
+
puts "🤓 Reading from to #{result_file_path}"
|
36
|
+
|
37
|
+
database_name = File.basename(result_file_path, ".*")
|
38
|
+
UffDbLoader.load_dump_into_database(database_name)
|
39
|
+
end
|
40
|
+
|
41
|
+
desc "Loads an existing dump into the local database"
|
42
|
+
task restore: :environment do
|
43
|
+
UffDbLoader.ensure_installation!
|
44
|
+
|
45
|
+
prompt = TTY::Prompt.new
|
46
|
+
existing_dumps = Dir.glob("#{UffDbLoader.config.dumps_directory}/#{UffDbLoader.config.app_name}*").map { |f| File.basename(f, ".*") }
|
47
|
+
database_name = prompt.select("Which dump should be restored?", existing_dumps)
|
48
|
+
|
49
|
+
UffDbLoader.load_dump_into_database(database_name)
|
50
|
+
end
|
51
|
+
|
52
|
+
desc "Switches to an existing database"
|
53
|
+
task switch: :environment do
|
54
|
+
UffDbLoader.ensure_installation!
|
55
|
+
|
56
|
+
prompt = TTY::Prompt.new
|
57
|
+
databases = UffDbLoader.databases
|
58
|
+
new_database = prompt.select("Which database do you want to switch to?", databases)
|
59
|
+
|
60
|
+
UffDbLoader.remember_database_name(new_database)
|
61
|
+
system("bin/rails restart")
|
62
|
+
|
63
|
+
puts "♻️ Restarted rails server with new database."
|
64
|
+
end
|
65
|
+
|
66
|
+
desc "Delete all downloaded db dumps and remove all databases created by UffDbLoader"
|
67
|
+
task prune: :environment do
|
68
|
+
UffDbLoader.databases.each do |database_name|
|
69
|
+
puts "Dropping #{database_name}"
|
70
|
+
UffDbLoader.drop_database(database_name)
|
71
|
+
end
|
72
|
+
|
73
|
+
puts "Removing dumps from #{UffDbLoader.config.dumps_directory}"
|
74
|
+
UffDbLoader.prune_dump_directory
|
75
|
+
end
|
76
|
+
end
|
data/lib/uff_db_loader.rb
CHANGED
@@ -10,6 +10,10 @@ module UffDbLoader
|
|
10
10
|
@configuration ||= Configuration.new
|
11
11
|
end
|
12
12
|
|
13
|
+
def self.database_name_file
|
14
|
+
Rails.root.join("tmp", "uff_db_loader_database_name")
|
15
|
+
end
|
16
|
+
|
13
17
|
def self.reset
|
14
18
|
@configuration = Configuration.new
|
15
19
|
end
|
@@ -80,7 +84,65 @@ module UffDbLoader
|
|
80
84
|
end
|
81
85
|
end
|
82
86
|
|
87
|
+
def self.database_name_template(old_database_name)
|
88
|
+
"<%= UffDbLoader.current_database_name || '#{old_database_name}' %>"
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.setup_dynamic_database_name_in_config
|
92
|
+
old_database_name = Rails.configuration.database_configuration["development"]["database"]
|
93
|
+
|
94
|
+
return false if old_database_name.nil?
|
95
|
+
|
96
|
+
old_config = File.read(UffDbLoader.config.database_config_file)
|
97
|
+
new_config = old_config.sub(old_database_name, database_name_template(old_database_name))
|
98
|
+
File.write(UffDbLoader.config.database_config_file, new_config)
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.current_database_name
|
102
|
+
File.read(database_name_file).strip.presence
|
103
|
+
rescue IOError, Errno::ENOENT => e
|
104
|
+
puts "Could not read #{database_name_file}. #{e.message}"
|
105
|
+
end
|
106
|
+
|
107
|
+
def self.remember_database_name(database_name)
|
108
|
+
File.write(database_name_file, database_name)
|
109
|
+
end
|
110
|
+
|
111
|
+
def self.ensure_installation!
|
112
|
+
unless File.read(UffDbLoader.config.database_config_file).include?("UffDbLoader.current_database_name")
|
113
|
+
raise InstallationDidNotRunError, "Please run bin/rails uff_db_loader:install"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.dump_file_path(database_name)
|
118
|
+
File.join(
|
119
|
+
config.dumps_directory,
|
120
|
+
"#{database_name}.#{config.database_system.dump_extension}"
|
121
|
+
)
|
122
|
+
end
|
123
|
+
|
124
|
+
def self.load_dump_into_database(database_name)
|
125
|
+
UffDbLoader.drop_database(database_name)
|
126
|
+
UffDbLoader.create_database(database_name)
|
127
|
+
|
128
|
+
puts "🗂 Created database #{database_name}"
|
129
|
+
|
130
|
+
dump_file_path = dump_file_path(database_name)
|
131
|
+
|
132
|
+
command_successful = system(restore_command(database_name, dump_file_path))
|
133
|
+
raise "Command did not run succesful: #{restore_command(database_name, dump_file_path)}" unless command_successful
|
134
|
+
|
135
|
+
puts "✅ Succesfully loaded #{dump_file_path} into #{database_name}"
|
136
|
+
|
137
|
+
remember_database_name(database_name)
|
138
|
+
system("bin/rails restart")
|
139
|
+
|
140
|
+
puts "♻️ Restarted rails server with new database."
|
141
|
+
end
|
142
|
+
|
83
143
|
class ForbiddenEnvironmentError < StandardError; end
|
84
144
|
|
85
145
|
class UnknownDatabaseSystem < StandardError; end
|
146
|
+
|
147
|
+
class InstallationDidNotRunError < StandardError; end
|
86
148
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uff_db_loader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andreas Hellwig
|
8
8
|
- Fynn Heintz
|
9
9
|
- Robin Mehner
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
13
|
date: 2022-08-25 00:00:00.000000000 Z
|
@@ -80,6 +80,7 @@ files:
|
|
80
80
|
- lib/uff_db_loader/mysql.rb
|
81
81
|
- lib/uff_db_loader/postgresql.rb
|
82
82
|
- lib/uff_db_loader/tasks/remote_database.rake
|
83
|
+
- lib/uff_db_loader/tasks/uff_db_loader.rake
|
83
84
|
- lib/uff_db_loader/version.rb
|
84
85
|
- uff_db_loader.gemspec
|
85
86
|
homepage: https://github.com/rmehner/uff_db_loader
|
@@ -87,10 +88,10 @@ licenses:
|
|
87
88
|
- MIT
|
88
89
|
metadata:
|
89
90
|
bug_tracker_uri: https://github.com/rmehner/uff_db_loader/issues
|
90
|
-
changelog_uri: https://github.com/rmehner/uff_db_loader/releases/tag/1.
|
91
|
+
changelog_uri: https://github.com/rmehner/uff_db_loader/releases/tag/1.4.0
|
91
92
|
homepage_uri: https://github.com/rmehner/uff_db_loader
|
92
|
-
source_code_uri: https://github.com/rmehner/uff_db_loader/tree/1.
|
93
|
-
post_install_message:
|
93
|
+
source_code_uri: https://github.com/rmehner/uff_db_loader/tree/1.4.0
|
94
|
+
post_install_message:
|
94
95
|
rdoc_options: []
|
95
96
|
require_paths:
|
96
97
|
- lib
|
@@ -105,8 +106,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
106
|
- !ruby/object:Gem::Version
|
106
107
|
version: '0'
|
107
108
|
requirements: []
|
108
|
-
rubygems_version: 3.3
|
109
|
-
signing_key:
|
109
|
+
rubygems_version: 3.0.3
|
110
|
+
signing_key:
|
110
111
|
specification_version: 4
|
111
112
|
summary: Allows to dump, download and restore databases from docker servers.
|
112
113
|
test_files: []
|