remote_database_importer 0.1.0 → 0.1.2

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: cc2634f7ebf5e2ab65295a75ce3a851bfdc12632be061376b921e20689a7e614
4
- data.tar.gz: 62e21889fbbc2ecff1ec1d9eae582a112bb8121509c31118558bab4ed947c190
3
+ metadata.gz: 78760d816e20de850e798b2246f3dd22d43fe2e4223ed305776e2bc0ff8e7ba9
4
+ data.tar.gz: 6aa3a9165a3fad0b3659a80bc389f907561c09c08477eb11460e9c3b05297712
5
5
  SHA512:
6
- metadata.gz: a2dab0f7513fba0965b73effd56c2aeeb96c24f85ace4fff2d97e40b0f13c960d517321e950381923c0534b565891c885c10e7ed36ebc0c51899cf0303c8bb4b
7
- data.tar.gz: ff8507cff4411cb07295a3faddb54df8d263573c15baff4ffcfb493f5379956cc969fb08ca3edf1fc8790ed26618539134e99323a2afa48d8ca9290bf477dc22
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)
@@ -11,17 +11,12 @@ GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
13
  ast (2.4.2)
14
- coderay (1.1.3)
15
14
  colorize (0.8.1)
16
15
  diff-lcs (1.5.0)
17
16
  json (2.6.2)
18
- method_source (1.0.0)
19
17
  parallel (1.22.1)
20
18
  parser (3.1.2.1)
21
19
  ast (~> 2.4.1)
22
- pry (0.14.1)
23
- coderay (~> 1.1)
24
- method_source (~> 1.0)
25
20
  rainbow (3.1.1)
26
21
  rake (13.0.6)
27
22
  regexp_parser (2.6.0)
@@ -66,11 +61,11 @@ GEM
66
61
  unicode-display_width (2.3.0)
67
62
 
68
63
  PLATFORMS
64
+ arm64-darwin-20
69
65
  arm64-darwin-21
70
66
  x86_64-linux
71
67
 
72
68
  DEPENDENCIES
73
- pry (~> 0.14)
74
69
  rake (~> 13.0)
75
70
  remote_database_importer!
76
71
  rspec (~> 3.0)
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
@@ -2,7 +2,6 @@ module RemoteDatabaseImporter
2
2
  class Operation
3
3
  require "remote_database_importer/config"
4
4
  require "tty/spinner/multi"
5
- require "pry"
6
5
 
7
6
  LOG_FILE = "tmp/remote_database_importer.log"
8
7
 
@@ -33,6 +32,7 @@ module RemoteDatabaseImporter
33
32
 
34
33
  def import
35
34
  select_environment
35
+ time_start = Time.now
36
36
  multi_spinner = TTY::Spinner::Multi.new("[:spinner] Import remote DB", format: :dots_3)
37
37
  tasks = create_tasks_and_spinners(multi_spinner)
38
38
 
@@ -43,14 +43,15 @@ module RemoteDatabaseImporter
43
43
  return "Can't continue, following task failed: #{task[:command]} - checkout the logfile: #{LOG_FILE}" unless task_execution_was_successful
44
44
  task[:spinner].stop("... Done!")
45
45
  end
46
+ puts seconds_to_human_readable_time(Time.now - time_start)
46
47
  end
47
48
 
48
49
  private
49
50
 
50
51
  def create_tasks_and_spinners(multi_spinner)
51
52
  tasks = [
52
- {name: "Terminate current DB sessions", command: terminate_current_db_sessions},
53
53
  {name: "Dump remote DB", command: dump_remote_db},
54
+ {name: "Terminate current DB sessions", command: terminate_current_db_sessions},
54
55
  {name: "Drop and create local DB", command: drop_and_create_local_db},
55
56
  {name: "Restore remote DB", command: restore_db},
56
57
  {name: "Run migrations", command: run_migrations},
@@ -78,7 +79,7 @@ module RemoteDatabaseImporter
78
79
  ssh_port = env["connection"]["ssh_port"]
79
80
  postgres_port = env["connection"]["postgres_port"]
80
81
 
81
- if dump_type == "ssh"
82
+ if dump_type == "ssh_tunnel"
82
83
  "ssh #{ssh_user}@#{host} -p #{ssh_port} 'pg_dump -Fc -U #{db_user} -d #{db_name} -h localhost -C' > #{db_dump_location}"
83
84
  else
84
85
  "pg_dump -Fc 'host=#{host} dbname=#{db_name} user=#{db_user} port=#{postgres_port}' > #{db_dump_location}"
@@ -108,5 +109,15 @@ module RemoteDatabaseImporter
108
109
  def db_dump_location
109
110
  "tmp/#{@current_environment["database"]["name"]}.dump"
110
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
111
122
  end
112
123
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RemoteDatabaseImporter
4
- VERSION = "0.1.0"
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.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
- - Leon
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
@@ -66,22 +66,8 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.8'
69
- - !ruby/object:Gem::Dependency
70
- name: pry
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '0.14'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '0.14'
83
- description: Dump remote database and import locally. Currently only postgres databases
84
- supported
69
+ description: Dump remote databases and import it locally. At the moment only Postgres
70
+ databases are supported
85
71
  email:
86
72
  - nonick@nonick.ch
87
73
  executables:
@@ -104,9 +90,9 @@ files:
104
90
  - lib/remote_database_importer/operation.rb
105
91
  - lib/remote_database_importer/version.rb
106
92
  - lib/tasks/remote_database_importer.rake
93
+ - readme_assets/config_sample.png
94
+ - readme_assets/import-job.gif
107
95
  - readme_images/.DS_Store
108
- - readme_images/config_sample.png
109
- - readme_images/import-job.gif
110
96
  - sig/remote_database_importer.rbs
111
97
  homepage: https://github.com/leon-vogt/remote_database_importer
112
98
  licenses:
@@ -133,5 +119,5 @@ requirements: []
133
119
  rubygems_version: 3.3.7
134
120
  signing_key:
135
121
  specification_version: 4
136
- summary: Dump remote database and import locally
122
+ summary: Dump remote databases and import it locally
137
123
  test_files: []
Binary file