uff_db_loader 2.0.1 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4014edf9331d8b25f433d0252b62008f78db0f0038fb8e1f7877319eacf45320
4
- data.tar.gz: 16d16a54291cbf8641fba3ef4fa6db469a72b4420577716139d90ba06470d298
3
+ metadata.gz: 1a2c7c42ed0513c36d938f46d9346c462ec22e978ed234f519d9825eb8701c8f
4
+ data.tar.gz: 6036d5f67b2447a2e747b6b242d4a69a96730c57f5ce45a01d618d4af91085a4
5
5
  SHA512:
6
- metadata.gz: 4ea14486da00fdf735bb1310c2f70d24b274a14007960a5306c2af2faa016ce933d22aaa844ef589a336a0e7af7738de9179027429f2b425378fbb064f789673
7
- data.tar.gz: c40219d3c1b3b256f324097ec25be27ee16934395e6f9bfd6362d29efbc1f796b3547dc1de388a6678464eb14578d3f82e135036889398bfdf363790c21a4913
6
+ metadata.gz: e843d03ce1e569f9bd03a84ec9f95321dd34f08f23ad3897392343cffb4779cc91c9d44bb6b1634c94ef6b763177cefe2489c64207bb31cbf20140e73610fa82
7
+ data.tar.gz: 25d012b2ba4e6bfbc066b074a95523f8782c9da9a345ad0326014c8b7da87f343452966bfa7a217c3e1783ace8c90a82e5a19777be87ce7b89b69f7fb79cd063
data/README.md CHANGED
@@ -20,7 +20,7 @@ Or install it yourself as:
20
20
 
21
21
  $ gem install uff_db_loader
22
22
 
23
- Run the installation script:
23
+ Run the installation script:
24
24
 
25
25
  $ bin/rails uff_db_loader:install
26
26
 
@@ -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`.
@@ -50,6 +51,7 @@ Make sure the app's database user has the superuser role. Otherwise the app will
50
51
  - `dump`: Dumps a remote database from a selected environment and downloads it
51
52
  - `restore`: Restores a downloaded dump into a local database
52
53
  - `switch`: Selects a restored local database to use
54
+ - `switch_to_default`: Switches database back to the default development database
53
55
  - `load`: Dumps a remote database from a selected environment and downloads it then restores and selects the database
54
56
  - `prune`: Delete all downloaded db dumps and removes all databases created by UffDbLoader
55
57
 
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 :environments, :ssh_host, :ssh_user, :db_name, :db_system, :app_name, :dumps_directory, :database_config_file
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
@@ -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 %app_name%_%environment%_db sh -c 'exec mysqldump --opt --no-tablespaces -uroot -p\"\\$MYSQL_ROOT_PASSWORD\" %database%'\" > %target%"
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 %app_name%_%environment%_db sh -c 'exec pg_dump --username \\$POSTGRES_USER --clean --no-owner --no-acl --format=c %database%'\" > %target%"
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)
@@ -79,4 +79,12 @@ namespace :uff_db_loader do
79
79
  puts "Removing dumps from #{UffDbLoader.config.dumps_directory}"
80
80
  UffDbLoader.prune_dump_directory
81
81
  end
82
+
83
+ desc "Switch back to default database"
84
+ task switch_to_default: :environment do
85
+ UffDbLoader.remember_database_name("")
86
+ UffDbLoader.restart_rails_server
87
+
88
+ puts "♻️ Restarted rails server with default database."
89
+ end
82
90
  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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UffDbLoader
4
- VERSION = "2.0.1"
4
+ VERSION = "2.2.0"
5
5
  end
data/lib/uff_db_loader.rb CHANGED
@@ -108,14 +108,14 @@ module UffDbLoader
108
108
  end
109
109
 
110
110
  def initializer_path
111
- File.join(__dir__, "uff_db_loader", "templates", "uff_db_loader_initializer.erb")
111
+ Rails.root.join("config", "initializers", "uff_db_loader.rb")
112
112
  end
113
113
 
114
114
  def create_initializer
115
- template = ERB.new(File.read(initializer_path))
115
+ template = ERB.new(File.read(initializer_template_path))
116
116
 
117
117
  File.write(
118
- Rails.root.join("config", "initializers", "uff_db_loader.rb"),
118
+ initializer_path,
119
119
  template.result_with_hash(
120
120
  used_database_system: used_database_system,
121
121
  environments: environments
@@ -125,6 +125,17 @@ module UffDbLoader
125
125
 
126
126
  private
127
127
 
128
+ def container_name(environment)
129
+ return "#{config.app_name}_#{environment}_db" if config.container_name.blank?
130
+ return config.container_name unless config.container_name.respond_to? :call
131
+
132
+ config.container_name.call(config.app_name, environment)
133
+ end
134
+
135
+ def initializer_template_path
136
+ File.join(__dir__, "uff_db_loader", "templates", "uff_db_loader_initializer.erb")
137
+ end
138
+
128
139
  def database_name_file
129
140
  Rails.root.join("tmp", "uff_db_loader_database_name")
130
141
  end
@@ -140,12 +151,11 @@ module UffDbLoader
140
151
  config
141
152
  .database_system
142
153
  .dump_command_template
143
- .gsub("%environment%", environment)
144
154
  .gsub("%host%", config.ssh_host)
145
155
  .gsub("%user%", config.ssh_user)
146
156
  .gsub("%database%", config.database)
147
157
  .gsub("%target%", target)
148
- .gsub("%app_name%", config.app_name)
158
+ .gsub("%container_name%", container_name(environment))
149
159
  end
150
160
 
151
161
  def restore_command(database_name, result_file_path)
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: 2.0.1
4
+ version: 2.2.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: 2022-10-04 00:00:00.000000000 Z
13
+ date: 2023-02-23 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/2.0.1
91
+ changelog_uri: https://github.com/rmehner/uff_db_loader/releases/tag/2.2.0
92
92
  homepage_uri: https://github.com/rmehner/uff_db_loader
93
- source_code_uri: https://github.com/rmehner/uff_db_loader/tree/2.0.1
93
+ source_code_uri: https://github.com/rmehner/uff_db_loader/tree/2.2.0
94
94
  post_install_message: Please run `bin/rails uff_db_loader:install` to complete the
95
95
  installation.
96
96
  rdoc_options: []
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  - !ruby/object:Gem::Version
108
108
  version: '0'
109
109
  requirements: []
110
- rubygems_version: 3.3.8
110
+ rubygems_version: 3.4.7
111
111
  signing_key:
112
112
  specification_version: 4
113
113
  summary: Allows to dump, download and restore databases from docker servers.