remote_database_importer 0.1.3 → 0.1.4

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: cbe347c485be41742ebab8205d5d803b12cace72407f351c6e05ba9988fb8a80
4
- data.tar.gz: 21ab68290d08a418b5921ec81ef46e927c41e3ffe7e99c2916acb27561cd9d30
3
+ metadata.gz: 28a65a635e4ee78fdbce0dfce253b88a44fa190a887a8d68f928f5193d298fec
4
+ data.tar.gz: c23343009f9e8cf5d819fdf4a2dae6e88e380d30ef7591382fc900bcb1f40e04
5
5
  SHA512:
6
- metadata.gz: facbe97e036a224e1fa47fabe1e1774147d88154e1f77ff299dde2df89a7e8780c65bf7d5706b78e84d0928f01aebbf59add7f301ae2feb8022c50f6b64a6755
7
- data.tar.gz: a3c042ad221b0b3273b8fe6b202bf724f9abecabe0fdea6a10acdbb848964426bb4c68d97cdb7b25bd90929155c2d44a0137f065e6943a8428077a8a48af7d0a
6
+ metadata.gz: 7b7bd6d20734483e93dcefec67a7890300f6946047003de8a12915a982063d0de086f0b372f188271b6f3c0c51b22bb6b5baac50f25034e7bb548bee5a19817e
7
+ data.tar.gz: 7cc6a60c1141353e8cdf2d910fcab0d0f9c991e56c7cc0fbda513f3461fbaa6ba1abe16f0bcb07f13a99717fed81c519b01455da6b257fa0852cede0366d9e03
data/CHANGELOG.md CHANGED
@@ -1,11 +1,19 @@
1
1
  # Changelog
2
2
 
3
- ## [0.1.2] - 2022-10-29
3
+ ## 0.1.4 (2022-11-17)
4
+ - Remove colorize as a dependency
5
+ - Code refactoring
6
+
7
+ ## 0.1.3 (2022-11-06)
8
+ - Remove Thor as a dependency
9
+ - Add custom commands that run after the successful import of the remote database
10
+
11
+ ## 0.1.2 (2022-10-29)
4
12
 
5
13
  - Terminate current DB sessions after dump remote database. So the chance of an open session is smaller
6
14
  - Print out where the config was saved
7
15
  - Print how long the import went
8
16
 
9
- ## [0.1.0] - 2022-10-24
17
+ ## 0.1.0 (2022-10-24)
10
18
 
11
19
  - Initial release
data/Gemfile.lock CHANGED
@@ -1,8 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- remote_database_importer (0.1.3)
5
- colorize (~> 0.8)
4
+ remote_database_importer (0.1.4)
6
5
  tty-config (~> 0.6)
7
6
  tty-spinner (~> 0.9)
8
7
 
@@ -10,7 +9,6 @@ GEM
10
9
  remote: https://rubygems.org/
11
10
  specs:
12
11
  ast (2.4.2)
13
- colorize (0.8.1)
14
12
  diff-lcs (1.5.0)
15
13
  json (2.6.2)
16
14
  parallel (1.22.1)
@@ -0,0 +1,13 @@
1
+ class Colorize
2
+ def self.red(text)
3
+ "\033[31m#{text}\033[0m"
4
+ end
5
+
6
+ def self.green(text)
7
+ "\e[32m#{text}\e[0m"
8
+ end
9
+
10
+ def self.blue(text)
11
+ "\e[94m#{text}\e[0m"
12
+ end
13
+ end
@@ -1,32 +1,35 @@
1
1
  module RemoteDatabaseImporter
2
2
  class Config
3
3
  require "tty/config"
4
- require "colorize"
4
+ require_relative "colorize"
5
5
 
6
+ attr_accessor :config
7
+
6
8
  def initialize
7
9
  @config = TTY::Config.new
8
- @config.filename = "remote_database_importer"
9
- @config.extname = ".yml"
10
- @config.append_path Dir.pwd
10
+
11
+ config.filename = "remote_database_importer"
12
+ config.extname = ".yml"
13
+ config.append_path Dir.pwd
11
14
  end
12
15
 
13
16
  def read_or_create_configfile
14
- unless @config.exist?
15
- puts "===========================================================".colorize(:green)
17
+ unless config.exist?
18
+ puts Colorize.green("===========================================================")
16
19
  puts "Hi there! There is no config file yet, lets create one! 😄"
17
20
  create_default_config
18
- config_location = [@config.filename, @config.extname].join
21
+ config_location = [config.filename, config.extname].join
19
22
  puts "Created config file: #{config_location}"
20
- puts "===========================================================".colorize(:green)
23
+ puts Colorize.green("===========================================================")
21
24
  end
22
- @config.read
25
+ config.read
23
26
  end
24
27
 
25
28
  def ask(question, default: nil, options: nil)
26
29
  question += " (#{options.join(" / ")})" if options.present?
27
30
  question += " [#{default}]" if default.present?
28
31
 
29
- puts question.colorize(:light_blue)
32
+ puts Colorize.blue(question)
30
33
  answer = $stdin.gets.chomp
31
34
  answer.present? ? answer : default
32
35
  end
@@ -36,20 +39,20 @@ module RemoteDatabaseImporter
36
39
  environment_count = 1
37
40
 
38
41
  local_db_name = ask("Whats the name of the local database you wanna import to?", default: "myawesomeapp_development")
39
- @config.set(:local_db_name, value: local_db_name)
42
+ config.set(:local_db_name, value: local_db_name)
40
43
  puts
41
44
 
42
45
  while enter_new_environments
43
- puts "#{environment_count}. Environment".colorize(:green)
46
+ puts Colorize.green("#{environment_count}. Environment")
44
47
  env = ask("Whats the name of the #{environment_count}. environment you wanna add?", default: "staging")
45
48
  puts
46
49
 
47
- puts "Database settings:".colorize(:green)
50
+ puts Colorize.green("Database settings:")
48
51
  db_name = ask("Enter the DB name for the #{env} environment:", default: "myawesomeapp_#{env}")
49
52
  db_user = ask("Enter the DB user for the #{env} environment:", default: "deployer")
50
53
  puts
51
54
 
52
- puts "Connection settings:".colorize(:green)
55
+ puts Colorize.green("Connection settings:")
53
56
  host = ask("Enter the IP or hostname of the DB server:", default: "myawesomeapp.com")
54
57
  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"])
55
58
 
@@ -77,7 +80,7 @@ module RemoteDatabaseImporter
77
80
  }
78
81
  }
79
82
  }
80
- @config.append(env_config, to: :environments)
83
+ config.append(env_config, to: :environments)
81
84
 
82
85
  continue = ask("Do you wanna add another environment? (anything other than 'yes' will exit)")
83
86
  if continue&.downcase == "yes"
@@ -87,12 +90,12 @@ module RemoteDatabaseImporter
87
90
  end
88
91
  end
89
92
 
90
- puts "Define custom commands that run after successful import:".colorize(:green)
93
+ puts Colorize.green("Define custom commands that run after successful import:")
91
94
  custom_commands = ask("Enter semicolon separated commands that should run after importing the DB:", default: "rake db:migrate; echo 'All Done'")
92
95
  puts
93
96
 
94
- @config.set(:custom_commands, value: custom_commands)
95
- @config.write
97
+ config.set(:custom_commands, value: custom_commands)
98
+ config.write
96
99
  end
97
100
  end
98
101
  end
@@ -3,15 +3,17 @@ module RemoteDatabaseImporter
3
3
  require "remote_database_importer/config"
4
4
  require "tty/spinner/multi"
5
5
 
6
+ attr_accessor :config
7
+ attr_accessor :current_environment
8
+
6
9
  LOG_FILE = "tmp/remote_database_importer.log"
7
10
 
8
11
  def initialize
9
- config_handler = RemoteDatabaseImporter::Config.new
10
- @config = config_handler.read_or_create_configfile
12
+ @config = RemoteDatabaseImporter::Config.new.read_or_create_configfile
11
13
  end
12
14
 
13
15
  def environments
14
- @config.fetch("environments")
16
+ config.fetch("environments")
15
17
  end
16
18
 
17
19
  def select_environment
@@ -66,18 +68,17 @@ module RemoteDatabaseImporter
66
68
 
67
69
  # terminate local db sessions, otherwise the db can't be dropped
68
70
  def terminate_current_db_sessions
69
- "psql -d #{@config.fetch("local_db_name")} -c 'SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE datname = current_database() AND pid <> pg_backend_pid();' > #{LOG_FILE}"
71
+ "psql -d #{config.fetch("local_db_name")} -c 'SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE datname = current_database() AND pid <> pg_backend_pid();' > #{LOG_FILE}"
70
72
  end
71
73
 
72
74
  def dump_remote_db
73
- env = @current_environment
74
- host = env["connection"]["host"]
75
- db_name = env["database"]["name"]
76
- db_user = env["database"]["user"]
77
- dump_type = env["connection"]["dump_type"]
78
- ssh_user = env["connection"]["ssh_user"]
79
- ssh_port = env["connection"]["ssh_port"]
80
- postgres_port = env["connection"]["postgres_port"]
75
+ host = current_environment["connection"]["host"]
76
+ db_name = current_environment["database"]["name"]
77
+ db_user = current_environment["database"]["user"]
78
+ dump_type = current_environment["connection"]["dump_type"]
79
+ ssh_user = current_environment["connection"]["ssh_user"]
80
+ ssh_port = current_environment["connection"]["ssh_port"]
81
+ postgres_port = current_environment["connection"]["postgres_port"]
81
82
 
82
83
  if dump_type == "ssh_tunnel"
83
84
  "ssh #{ssh_user}@#{host} -p #{ssh_port} 'pg_dump -Fc -U #{db_user} -d #{db_name} -h localhost -C' > #{db_dump_location}"
@@ -91,7 +92,7 @@ module RemoteDatabaseImporter
91
92
  end
92
93
 
93
94
  def restore_db
94
- "pg_restore --jobs 8 --no-privileges --no-owner --dbname #{@config.fetch("local_db_name")} #{db_dump_location}"
95
+ "pg_restore --jobs 8 --no-privileges --no-owner --dbname #{config.fetch("local_db_name")} #{db_dump_location}"
95
96
  end
96
97
 
97
98
  def remove_logfile
@@ -103,11 +104,11 @@ module RemoteDatabaseImporter
103
104
  end
104
105
 
105
106
  def custom_commands
106
- @config.fetch("custom_commands")
107
+ config.fetch("custom_commands")
107
108
  end
108
109
 
109
110
  def db_dump_location
110
- "tmp/#{@current_environment["database"]["name"]}.dump"
111
+ "tmp/#{current_environment["database"]["name"]}.dump"
111
112
  end
112
113
 
113
114
  def seconds_to_human_readable_time(secs)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RemoteDatabaseImporter
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
@@ -1,7 +1,6 @@
1
1
  namespace :remote_database do
2
2
  desc "Pulls a database to your filesystem"
3
3
  task import: :environment do
4
- importer = RemoteDatabaseImporter::Operation.new
5
- importer.import
4
+ RemoteDatabaseImporter::Operation.new.import
6
5
  end
7
6
  end
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.3
4
+ version: 0.1.4
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-11-06 00:00:00.000000000 Z
11
+ date: 2022-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tty-config
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.9'
41
- - !ruby/object:Gem::Dependency
42
- name: colorize
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '0.8'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '0.8'
55
41
  description: Dump remote databases and import it locally. At the moment only Postgres
56
42
  databases are supported
57
43
  email:
@@ -70,6 +56,7 @@ files:
70
56
  - Rakefile
71
57
  - lib/railtie.rb
72
58
  - lib/remote_database_importer.rb
59
+ - lib/remote_database_importer/colorize.rb
73
60
  - lib/remote_database_importer/config.rb
74
61
  - lib/remote_database_importer/operation.rb
75
62
  - lib/remote_database_importer/version.rb