remote_database_importer 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 83f84dda973912024d022d895763155d64da66822f5d6f7e771cfcf54562dd71
4
- data.tar.gz: 9a2fb0fe981aef23c4778765cbf9f5e70e033c16d43c8d1a2a145b2abaf4f8ce
3
+ metadata.gz: 78760d816e20de850e798b2246f3dd22d43fe2e4223ed305776e2bc0ff8e7ba9
4
+ data.tar.gz: 6aa3a9165a3fad0b3659a80bc389f907561c09c08477eb11460e9c3b05297712
5
5
  SHA512:
6
- metadata.gz: 07be1da942f02d49869a62c64f3a1f4b5f81c23d624a604c42b1b0b844da94dcba18b86e824fd64cd147c7d4132f14832e0f23741e4470988c8f7fede720fcf0
7
- data.tar.gz: 87a22ec48fcf6efb7c85bad1f183a6e1b0e3a0f9226fdf0dd3289b12bd1bfbad197ab0fbed2cdc3aebfafc56a421b62edc61db5a2c4407a885098fb842437400
6
+ metadata.gz: ac6d8f895e5ba3ad931b1767ae5e01082b280931917290df70eb2d5f4fbe49861ee62195f3e216d42b25b635b8a7a5da827f8991775ad7724cbdcaf7c1aa0c19
7
+ data.tar.gz: 4c6498283f68c0dbc26d5c1b3b6eae4c7af12c01e4d13cc4b876d05ba07dc0d6ac6641d310955510eed1805787bcac9a3e1a201f011a22e8e5ab0b8ef74cd3f6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.1.2] - 2022-10-29
4
+
5
+ - Terminate current DB sessions after dump remote database. So the chance of an open session is smaller
6
+ - Print out where the config was saved
7
+ - Print how long the import went
8
+
3
9
  ## [0.1.0] - 2022-10-24
4
10
 
5
11
  - Initial release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- remote_database_importer (0.1.0)
4
+ remote_database_importer (0.1.2)
5
5
  colorize (~> 0.8)
6
6
  thor (~> 1.2)
7
7
  tty-config (~> 0.6)
data/README.md CHANGED
@@ -33,14 +33,14 @@ Whenever you want current live data, you can run the command:
33
33
  rake remote_database:import
34
34
  ```
35
35
 
36
- ![Import Job Demo](readme_images/import-job.gif)
36
+ ![Import-Job sample](readme_assets/import-job.gif)
37
37
 
38
38
  ### Config
39
39
  The settings for the different environments is stored in the `remote_database_importer.yml` file.
40
40
  When you first run the rake task, it will dynamically create this file for you.
41
41
 
42
42
 
43
- ![asdf](readme_images/config_sample.png)
43
+ ![Config sample](readme_assets/config_sample.png)
44
44
 
45
45
  ### DB Access
46
46
  The easiest and fastest way is to exchange your ssh-key with the server beforehand, so you don't have to enter a password.
@@ -15,6 +15,8 @@ module RemoteDatabaseImporter
15
15
  puts "===========================================================".colorize(:green)
16
16
  puts "Hi there! There is no config file yet, lets create one! 😄"
17
17
  create_default_config
18
+ config_location = [@config.filename, @config.extname].join
19
+ puts "Created config file: #{config_location}"
18
20
  puts "===========================================================".colorize(:green)
19
21
  end
20
22
  @config.read
@@ -49,10 +51,10 @@ module RemoteDatabaseImporter
49
51
 
50
52
  puts "Connection settings:".colorize(:green)
51
53
  host = ask("Enter the IP or hostname of the DB server:", default: "myawesomeapp.com")
52
- dump_type = ask("Should the dump happen over a ssh connection or can pg_dump access the DB port directly? (if the DB lives on a seperat server pg_dump the way to go)", default: "pg_dump", options: ["ssh", "pg_dump"])
54
+ dump_type = ask("Should the DB dump happen over a ssh tunnel or can pg_dump connect to the DB port directly?", default: "pg_dump", options: ["ssh_tunnel", "pg_dump"])
53
55
 
54
56
  ssh_user, ssh_port, postgres_port = nil
55
- if dump_type == "ssh"
57
+ if dump_type == "ssh_tunnel"
56
58
  ssh_user = ask("Enter the username for the SSH connection:", default: "deployer")
57
59
  ssh_port = ask("Enter the port for the SSH connection:", default: "22")
58
60
  else
@@ -87,13 +89,5 @@ module RemoteDatabaseImporter
87
89
 
88
90
  @config.write
89
91
  end
90
-
91
- # TODO: validate user input
92
- # private
93
- # def validate_config(config)
94
- # config.each do |key, value|
95
- #
96
- # end
97
- # end
98
92
  end
99
93
  end
@@ -32,6 +32,7 @@ module RemoteDatabaseImporter
32
32
 
33
33
  def import
34
34
  select_environment
35
+ time_start = Time.now
35
36
  multi_spinner = TTY::Spinner::Multi.new("[:spinner] Import remote DB", format: :dots_3)
36
37
  tasks = create_tasks_and_spinners(multi_spinner)
37
38
 
@@ -42,14 +43,15 @@ module RemoteDatabaseImporter
42
43
  return "Can't continue, following task failed: #{task[:command]} - checkout the logfile: #{LOG_FILE}" unless task_execution_was_successful
43
44
  task[:spinner].stop("... Done!")
44
45
  end
46
+ puts seconds_to_human_readable_time(Time.now - time_start)
45
47
  end
46
48
 
47
49
  private
48
50
 
49
51
  def create_tasks_and_spinners(multi_spinner)
50
52
  tasks = [
51
- {name: "Terminate current DB sessions", command: terminate_current_db_sessions},
52
53
  {name: "Dump remote DB", command: dump_remote_db},
54
+ {name: "Terminate current DB sessions", command: terminate_current_db_sessions},
53
55
  {name: "Drop and create local DB", command: drop_and_create_local_db},
54
56
  {name: "Restore remote DB", command: restore_db},
55
57
  {name: "Run migrations", command: run_migrations},
@@ -77,7 +79,7 @@ module RemoteDatabaseImporter
77
79
  ssh_port = env["connection"]["ssh_port"]
78
80
  postgres_port = env["connection"]["postgres_port"]
79
81
 
80
- if dump_type == "ssh"
82
+ if dump_type == "ssh_tunnel"
81
83
  "ssh #{ssh_user}@#{host} -p #{ssh_port} 'pg_dump -Fc -U #{db_user} -d #{db_name} -h localhost -C' > #{db_dump_location}"
82
84
  else
83
85
  "pg_dump -Fc 'host=#{host} dbname=#{db_name} user=#{db_user} port=#{postgres_port}' > #{db_dump_location}"
@@ -107,5 +109,15 @@ module RemoteDatabaseImporter
107
109
  def db_dump_location
108
110
  "tmp/#{@current_environment["database"]["name"]}.dump"
109
111
  end
112
+
113
+ def seconds_to_human_readable_time(secs)
114
+ [[60, :seconds], [60, :minutes], [24, :hours], [Float::INFINITY, :days]].map { |count, name|
115
+ if secs > 0
116
+ secs, n = secs.divmod(count)
117
+
118
+ "#{n.to_i} #{name}" unless n.to_i == 0
119
+ end
120
+ }.compact.reverse.join(" ")
121
+ end
110
122
  end
111
123
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RemoteDatabaseImporter
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
Binary file
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remote_database_importer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leon Vogt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-24 00:00:00.000000000 Z
11
+ date: 2022-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -90,9 +90,9 @@ files:
90
90
  - lib/remote_database_importer/operation.rb
91
91
  - lib/remote_database_importer/version.rb
92
92
  - lib/tasks/remote_database_importer.rake
93
+ - readme_assets/config_sample.png
94
+ - readme_assets/import-job.gif
93
95
  - readme_images/.DS_Store
94
- - readme_images/config_sample.png
95
- - readme_images/import-job.gif
96
96
  - sig/remote_database_importer.rbs
97
97
  homepage: https://github.com/leon-vogt/remote_database_importer
98
98
  licenses:
Binary file