uff_db_loader 3.2.0 → 4.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/.github/workflows/test.yml +11 -11
- data/README.md +8 -3
- data/lib/configuration.rb +3 -5
- data/lib/uff_db_loader/mysql.rb +6 -2
- data/lib/uff_db_loader/postgresql.rb +7 -3
- data/lib/uff_db_loader/tasks/uff_db_loader.rake +11 -0
- data/lib/uff_db_loader/templates/uff_db_loader_initializer.erb +4 -1
- data/lib/uff_db_loader/version.rb +1 -1
- data/lib/uff_db_loader.rb +32 -6
- metadata +5 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 35997f212e0fe2b696781f3092c23fdaa6e11c0158c0053c8250422d553dcf3d
|
|
4
|
+
data.tar.gz: f4442306686b14c31606c740c9b83692825ca28cd7cf1564e35cc5b2aa746c53
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dac31add2ebbb9beb4d5734aeb7e4c3a249d2eefcbecf6a547a664b83670bab9a39069bb4d87385aeebaeb8f59cf9511321655cf3104407182b9ff0d84a3de4d
|
|
7
|
+
data.tar.gz: 6298da746d92328491e89ff84983cb39c2bc6a32c309fa4cda6915d210e9a3d30851ade48101741d6a6279fcf87a73f32d971050804bb22f26153ac21d07e671
|
data/.github/workflows/test.yml
CHANGED
|
@@ -2,9 +2,9 @@ name: Test
|
|
|
2
2
|
|
|
3
3
|
on:
|
|
4
4
|
push:
|
|
5
|
-
branches: [
|
|
5
|
+
branches: ["main"]
|
|
6
6
|
pull_request:
|
|
7
|
-
branches: [
|
|
7
|
+
branches: ["main"]
|
|
8
8
|
|
|
9
9
|
permissions:
|
|
10
10
|
contents: read
|
|
@@ -14,14 +14,14 @@ jobs:
|
|
|
14
14
|
runs-on: ubuntu-latest
|
|
15
15
|
strategy:
|
|
16
16
|
matrix:
|
|
17
|
-
ruby-version: [
|
|
17
|
+
ruby-version: ["3.0", "3.1", "3.2", "3.3", "3.4", "4.0"]
|
|
18
18
|
|
|
19
19
|
steps:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
- uses: actions/checkout@v6
|
|
21
|
+
- name: Set up Ruby
|
|
22
|
+
uses: ruby/setup-ruby@v1
|
|
23
|
+
with:
|
|
24
|
+
ruby-version: ${{ matrix.ruby-version }}
|
|
25
|
+
bundler-cache: true
|
|
26
|
+
- name: Run tests
|
|
27
|
+
run: bundle exec rake
|
data/README.md
CHANGED
|
@@ -27,19 +27,23 @@ Run the installation script:
|
|
|
27
27
|
## Configuration
|
|
28
28
|
|
|
29
29
|
You can configure the gem by running the following during the initialization of the Rails app:
|
|
30
|
+
|
|
30
31
|
```ruby
|
|
31
32
|
UffDbLoader.configure do |config|
|
|
32
33
|
config.environments = ['staging', 'production']
|
|
33
|
-
config.ssh_user = 'Francina'
|
|
34
|
-
config.ssh_host =
|
|
35
|
-
config.db_name =
|
|
34
|
+
config.ssh_user = ->(_app_name, environment) { environment == 'production' ? 'Francina' : 'FrancinaStaging' } # It accepts a static string too.
|
|
35
|
+
config.ssh_host = ->(_app_name, environment) { "#{environment}.host.of.yoursite" } # It accepts a static string too.
|
|
36
|
+
config.db_name = ->(app_name, environment) { "#{app_name}_#{environment}" } # Defaults to ssh_user. It accepts a static string too.
|
|
36
37
|
config.db_system = :postgresql # Possible values are 'postgresql' and 'mysql'.
|
|
37
38
|
config.app_name = 'my_app' # Defaults to the Rails app name
|
|
38
39
|
config.dumps_directory = '/path/to/dumps' # Defaults to Rails.root.join('dumps')
|
|
39
40
|
config.database_config_file = 'path/to/database.yml' # Defaults to Rails.root.join('config', 'database.yml')
|
|
40
41
|
config.container_name = ->(app_name, environment) { "#{app_name}_#{environment}_custom_suffix" } # Defaults to "#{app_name}_#{environment}_db". It accepts a static string too.
|
|
42
|
+
config.local_restore_command_path = '' # Sets the path to the db-cli (pg_restore, mysql). Defaults to nil so it's using the default binary (mysql, pg_dump) in $PATH.
|
|
43
|
+
config.restore_command_template = '%command% --jobs=4 --dbname %database% %file%' # Customize the restore command. Available placeholders: %command% (e.g. `pg_restore`), %database%, %file%. Defaults to the database system's template.
|
|
41
44
|
end
|
|
42
45
|
```
|
|
46
|
+
|
|
43
47
|
For example in a file like `config/initializers/uff_db_loader.rb`.
|
|
44
48
|
|
|
45
49
|
Make sure the app's database user has the superuser role. Otherwise the app will crash on startup due to missing permissions.
|
|
@@ -54,6 +58,7 @@ Make sure the app's database user has the superuser role. Otherwise the app will
|
|
|
54
58
|
- `switch_to_default`: Switches database back to the default development database
|
|
55
59
|
- `load`: Dumps a remote database from a selected environment and downloads it then restores and selects the database
|
|
56
60
|
- `prune`: Delete all downloaded db dumps and removes all databases created by UffDbLoader
|
|
61
|
+
- `current`: Shows the currently connected database and the one UffDbLoader has selected
|
|
57
62
|
|
|
58
63
|
## Development
|
|
59
64
|
|
data/lib/configuration.rb
CHANGED
|
@@ -15,7 +15,8 @@ module UffDbLoader
|
|
|
15
15
|
:dumps_directory,
|
|
16
16
|
:database_config_file,
|
|
17
17
|
:container_name,
|
|
18
|
-
:local_restore_command_path
|
|
18
|
+
:local_restore_command_path,
|
|
19
|
+
:restore_command_template
|
|
19
20
|
)
|
|
20
21
|
|
|
21
22
|
def initialize
|
|
@@ -29,10 +30,7 @@ module UffDbLoader
|
|
|
29
30
|
@database_config_file = File.join(Dir.pwd, "config", "database.yml")
|
|
30
31
|
@container_name = nil
|
|
31
32
|
@local_restore_command_path = nil
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
def database
|
|
35
|
-
db_name || ssh_user
|
|
33
|
+
@restore_command_template = nil
|
|
36
34
|
end
|
|
37
35
|
|
|
38
36
|
def database_system
|
data/lib/uff_db_loader/mysql.rb
CHANGED
|
@@ -10,8 +10,12 @@ module UffDbLoader
|
|
|
10
10
|
"ssh %user%@%host% \"docker exec -i %container_name% sh -c 'exec mysqldump --opt --single-transaction --routines --triggers --events --no-tablespaces -uroot -p\"\\$MYSQL_ROOT_PASSWORD\" %database%'\" > %target%"
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
def self.
|
|
14
|
-
"
|
|
13
|
+
def self.restore_command_template
|
|
14
|
+
"%command% -uroot %database% < %file%"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.default_restore_command
|
|
18
|
+
"mysql"
|
|
15
19
|
end
|
|
16
20
|
|
|
17
21
|
def self.list_databases
|
|
@@ -7,11 +7,15 @@ module UffDbLoader
|
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
def self.dump_command_template
|
|
10
|
-
"ssh %user%@%host% \"docker exec -i %container_name% sh -c 'exec pg_dump --username \\$POSTGRES_USER --
|
|
10
|
+
"ssh %user%@%host% \"docker exec -i %container_name% sh -c 'exec pg_dump --username \\$POSTGRES_USER --no-owner --no-acl --format=c %database%'\" > %target%"
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
def self.
|
|
14
|
-
"
|
|
13
|
+
def self.restore_command_template
|
|
14
|
+
"%command% --username postgres --no-owner --no-acl --dbname %database% %file%"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.default_restore_command
|
|
18
|
+
"pg_restore"
|
|
15
19
|
end
|
|
16
20
|
|
|
17
21
|
def self.list_databases
|
|
@@ -89,4 +89,15 @@ namespace :uff_db_loader do
|
|
|
89
89
|
|
|
90
90
|
UffDbLoader.log "♻️ Restarted rails server with default database."
|
|
91
91
|
end
|
|
92
|
+
|
|
93
|
+
desc "Shows the currently selected and connected database"
|
|
94
|
+
task current: :environment do
|
|
95
|
+
UffDbLoader.ensure_installation!
|
|
96
|
+
selected_database = UffDbLoader.current_database_name
|
|
97
|
+
|
|
98
|
+
UffDbLoader.log "Active Record connected to: #{ActiveRecord::Base.connection.current_database}"
|
|
99
|
+
unless selected_database.nil?
|
|
100
|
+
UffDbLoader.log "Selected database: #{selected_database}"
|
|
101
|
+
end
|
|
102
|
+
end
|
|
92
103
|
end
|
|
@@ -14,7 +14,10 @@ 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.db_name = ->(app_name, environment) { "#{app_name}_#{environment}" } # Defaults to ssh_user. It accepts a static string too.
|
|
18
|
+
# config.ssh_user = ->(_app_name, environment) { "my-user-for-#{environment}" } # It accepts a static string too.
|
|
19
|
+
# config.ssh_host = ->(_app_name, environment) { "#{environment}.host.of.yoursite" } # It accepts a static string too.
|
|
17
20
|
# config.container_name = ->(app_name, environment) { "#{app_name}_#{environment}_custom_suffix" } # Defaults to "#{app_name}_#{environment}_db". It accepts a static string too.
|
|
18
|
-
# config.local_restore_command_path = '' # Sets the path to the db-cli (pg_restore, mysql). Defaults to nil so it
|
|
21
|
+
# config.local_restore_command_path = '' # Sets the path to the db-cli (pg_restore, mysql). Defaults to nil so it's using the default binary (mysql, pg_dump) in $PATH.
|
|
19
22
|
end
|
|
20
23
|
end
|
data/lib/uff_db_loader.rb
CHANGED
|
@@ -145,9 +145,29 @@ module UffDbLoader
|
|
|
145
145
|
|
|
146
146
|
def container_name(environment)
|
|
147
147
|
return "#{config.app_name}_#{environment}_db" if config.container_name.blank?
|
|
148
|
-
return config.container_name unless config.container_name.respond_to? :call
|
|
149
148
|
|
|
150
|
-
config.container_name
|
|
149
|
+
resolve_dynamic_setting(config.container_name, environment)
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def ssh_user(environment)
|
|
153
|
+
resolve_dynamic_setting(config.ssh_user, environment)
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def ssh_host(environment)
|
|
157
|
+
resolve_dynamic_setting(config.ssh_host, environment)
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def database_name(environment)
|
|
161
|
+
database_name = resolve_dynamic_setting(config.db_name, environment)
|
|
162
|
+
return database_name if database_name.present?
|
|
163
|
+
|
|
164
|
+
ssh_user(environment)
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
def resolve_dynamic_setting(setting, environment)
|
|
168
|
+
return setting unless setting.respond_to? :call
|
|
169
|
+
|
|
170
|
+
setting.call(config.app_name, environment)
|
|
151
171
|
end
|
|
152
172
|
|
|
153
173
|
def initializer_template_path
|
|
@@ -169,15 +189,21 @@ module UffDbLoader
|
|
|
169
189
|
config
|
|
170
190
|
.database_system
|
|
171
191
|
.dump_command_template
|
|
172
|
-
.gsub("%host%",
|
|
173
|
-
.gsub("%user%",
|
|
174
|
-
.gsub("%database%",
|
|
192
|
+
.gsub("%host%", ssh_host(environment))
|
|
193
|
+
.gsub("%user%", ssh_user(environment))
|
|
194
|
+
.gsub("%database%", database_name(environment))
|
|
175
195
|
.gsub("%target%", target)
|
|
176
196
|
.gsub("%container_name%", container_name(environment))
|
|
177
197
|
end
|
|
178
198
|
|
|
179
199
|
def restore_command(database_name, result_file_path)
|
|
180
|
-
config.
|
|
200
|
+
template = config.restore_command_template || config.database_system.restore_command_template
|
|
201
|
+
command = config.local_restore_command_path || config.database_system.default_restore_command
|
|
202
|
+
|
|
203
|
+
template
|
|
204
|
+
.gsub("%command%", command)
|
|
205
|
+
.gsub("%database%", database_name)
|
|
206
|
+
.gsub("%file%", result_file_path)
|
|
181
207
|
end
|
|
182
208
|
|
|
183
209
|
def database_name_template(old_database_name)
|
metadata
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: uff_db_loader
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 4.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andreas Hellwig
|
|
8
8
|
- Fynn Heintz
|
|
9
9
|
- Robin Mehner
|
|
10
|
-
autorequire:
|
|
11
10
|
bindir: exe
|
|
12
11
|
cert_chain: []
|
|
13
|
-
date:
|
|
12
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
14
13
|
dependencies:
|
|
15
14
|
- !ruby/object:Gem::Dependency
|
|
16
15
|
name: tty-prompt
|
|
@@ -88,9 +87,9 @@ licenses:
|
|
|
88
87
|
- MIT
|
|
89
88
|
metadata:
|
|
90
89
|
bug_tracker_uri: https://github.com/rmehner/uff_db_loader/issues
|
|
91
|
-
changelog_uri: https://github.com/rmehner/uff_db_loader/releases/tag/
|
|
90
|
+
changelog_uri: https://github.com/rmehner/uff_db_loader/releases/tag/4.1.0
|
|
92
91
|
homepage_uri: https://github.com/rmehner/uff_db_loader
|
|
93
|
-
source_code_uri: https://github.com/rmehner/uff_db_loader/tree/
|
|
92
|
+
source_code_uri: https://github.com/rmehner/uff_db_loader/tree/4.1.0
|
|
94
93
|
post_install_message: Please run `bin/rails uff_db_loader:install` to complete the
|
|
95
94
|
installation.
|
|
96
95
|
rdoc_options: []
|
|
@@ -107,8 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
107
106
|
- !ruby/object:Gem::Version
|
|
108
107
|
version: '0'
|
|
109
108
|
requirements: []
|
|
110
|
-
rubygems_version:
|
|
111
|
-
signing_key:
|
|
109
|
+
rubygems_version: 4.0.6
|
|
112
110
|
specification_version: 4
|
|
113
111
|
summary: Allows to dump, download and restore databases from docker servers.
|
|
114
112
|
test_files: []
|