remote_database_importer 0.1.2 → 0.1.3

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: 78760d816e20de850e798b2246f3dd22d43fe2e4223ed305776e2bc0ff8e7ba9
4
- data.tar.gz: 6aa3a9165a3fad0b3659a80bc389f907561c09c08477eb11460e9c3b05297712
3
+ metadata.gz: cbe347c485be41742ebab8205d5d803b12cace72407f351c6e05ba9988fb8a80
4
+ data.tar.gz: 21ab68290d08a418b5921ec81ef46e927c41e3ffe7e99c2916acb27561cd9d30
5
5
  SHA512:
6
- metadata.gz: ac6d8f895e5ba3ad931b1767ae5e01082b280931917290df70eb2d5f4fbe49861ee62195f3e216d42b25b635b8a7a5da827f8991775ad7724cbdcaf7c1aa0c19
7
- data.tar.gz: 4c6498283f68c0dbc26d5c1b3b6eae4c7af12c01e4d13cc4b876d05ba07dc0d6ac6641d310955510eed1805787bcac9a3e1a201f011a22e8e5ab0b8ef74cd3f6
6
+ metadata.gz: facbe97e036a224e1fa47fabe1e1774147d88154e1f77ff299dde2df89a7e8780c65bf7d5706b78e84d0928f01aebbf59add7f301ae2feb8022c50f6b64a6755
7
+ data.tar.gz: a3c042ad221b0b3273b8fe6b202bf724f9abecabe0fdea6a10acdbb848964426bb4c68d97cdb7b25bd90929155c2d44a0137f065e6943a8428077a8a48af7d0a
data/Gemfile.lock CHANGED
@@ -1,9 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- remote_database_importer (0.1.2)
4
+ remote_database_importer (0.1.3)
5
5
  colorize (~> 0.8)
6
- thor (~> 1.2)
7
6
  tty-config (~> 0.6)
8
7
  tty-spinner (~> 0.9)
9
8
 
@@ -53,7 +52,6 @@ GEM
53
52
  standard (1.16.1)
54
53
  rubocop (= 1.35.1)
55
54
  rubocop-performance (= 1.14.3)
56
- thor (1.2.1)
57
55
  tty-config (0.6.0)
58
56
  tty-cursor (0.7.1)
59
57
  tty-spinner (0.9.3)
data/README.md CHANGED
@@ -7,6 +7,7 @@ Its well possible that unexpected errors can occur.
7
7
  ## Features
8
8
  - Define multiple environments (such as staging, production etc.)
9
9
  - Rails intergration via rake task
10
+ - Define custom commands that should run after successful import
10
11
  - Decide for yourself if the dump should be done over ssh or if pg_dump should connect to the DB port directly
11
12
  - It can therefore be used for almost all hosting providers (Heroku, Kubernetes, self-hosted, etc.)
12
13
 
@@ -43,8 +44,10 @@ When you first run the rake task, it will dynamically create this file for you.
43
44
  ![Config sample](readme_assets/config_sample.png)
44
45
 
45
46
  ### DB Access
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.
47
- Otherwise during the rake task execution a password entry is required.
47
+ The dump of the remote database happens with the tool: [pg_dump](https://www.postgresql.org/docs/current/app-pgdump.html).
48
+ There are two opions for connecting to the remote databse:
49
+ - pg_dump connects directly to the databse
50
+ - pg_dump connects through a shh tunnel to the databse
48
51
 
49
52
  The effective dump call is as follows:
50
53
  ```ruby
@@ -53,9 +56,14 @@ or
53
56
  "pg_dump -Fc 'host=HOST dbname=DB_NAME user=DB_USER port=POSTGRES_PORT' > DB_DUMP_LOCATION"
54
57
  ```
55
58
 
59
+ ### Password Input
60
+ Because this gem doesn't store passwords you will have to enter the passwords manually during the rake task.
61
+ Depending on the choosen connection model the password prompt will be for the ssh connection or the DB access.
62
+ If you choose to dump the databse over an ssh_tunnel, the easiest way will be to exchange your ssh-key with the server beforehand, so you don't have to enter a password.
63
+
56
64
  ## Limitations
57
65
  - At the moment only Postgres databases are supported
58
- - It has to run inside a Rails app. There is a CLI command `remote_database_importer import` as an alternative to the rake task, but there are still some Rails commands like `rails db:drop db:create - rails db:migrate`, which makes it currently not possible to use the gem outside of Rails
66
+ - It has to run inside a Rails app.
59
67
  - Not suitable for very large databases, you could run into SSH timeouts
60
68
 
61
69
  ## Contributing
@@ -87,6 +87,11 @@ module RemoteDatabaseImporter
87
87
  end
88
88
  end
89
89
 
90
+ puts "Define custom commands that run after successful import:".colorize(:green)
91
+ custom_commands = ask("Enter semicolon separated commands that should run after importing the DB:", default: "rake db:migrate; echo 'All Done'")
92
+ puts
93
+
94
+ @config.set(:custom_commands, value: custom_commands)
90
95
  @config.write
91
96
  end
92
97
  end
@@ -54,9 +54,9 @@ module RemoteDatabaseImporter
54
54
  {name: "Terminate current DB sessions", command: terminate_current_db_sessions},
55
55
  {name: "Drop and create local DB", command: drop_and_create_local_db},
56
56
  {name: "Restore remote DB", command: restore_db},
57
- {name: "Run migrations", command: run_migrations},
58
57
  {name: "Remove logfile", command: remove_logfile},
59
- {name: "Remove dumpfile", command: remove_dumpfile}
58
+ {name: "Remove dumpfile", command: remove_dumpfile},
59
+ {name: "Custom commands", command: custom_commands}
60
60
  ]
61
61
  tasks.each.with_index(1) do |task, index|
62
62
  task[:spinner] = multi_spinner.register "#{index}/#{tasks.length} :spinner #{task[:name]}"
@@ -94,10 +94,6 @@ module RemoteDatabaseImporter
94
94
  "pg_restore --jobs 8 --no-privileges --no-owner --dbname #{@config.fetch("local_db_name")} #{db_dump_location}"
95
95
  end
96
96
 
97
- def run_migrations
98
- "rake db:migrate > #{LOG_FILE}"
99
- end
100
-
101
97
  def remove_logfile
102
98
  "rm #{LOG_FILE}"
103
99
  end
@@ -106,6 +102,10 @@ module RemoteDatabaseImporter
106
102
  "rm #{db_dump_location}"
107
103
  end
108
104
 
105
+ def custom_commands
106
+ @config.fetch("custom_commands")
107
+ end
108
+
109
109
  def db_dump_location
110
110
  "tmp/#{@current_environment["database"]["name"]}.dump"
111
111
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RemoteDatabaseImporter
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.3"
5
5
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remote_database_importer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
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-29 00:00:00.000000000 Z
11
+ date: 2022-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: thor
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.2'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.2'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: tty-config
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -70,8 +56,7 @@ description: Dump remote databases and import it locally. At the moment only Pos
70
56
  databases are supported
71
57
  email:
72
58
  - nonick@nonick.ch
73
- executables:
74
- - remote_database_importer
59
+ executables: []
75
60
  extensions: []
76
61
  extra_rdoc_files: []
77
62
  files:
@@ -83,7 +68,6 @@ files:
83
68
  - LICENSE.txt
84
69
  - README.md
85
70
  - Rakefile
86
- - bin/remote_database_importer
87
71
  - lib/railtie.rb
88
72
  - lib/remote_database_importer.rb
89
73
  - lib/remote_database_importer/config.rb
@@ -92,7 +76,6 @@ files:
92
76
  - lib/tasks/remote_database_importer.rake
93
77
  - readme_assets/config_sample.png
94
78
  - readme_assets/import-job.gif
95
- - readme_images/.DS_Store
96
79
  - sig/remote_database_importer.rbs
97
80
  homepage: https://github.com/leon-vogt/remote_database_importer
98
81
  licenses:
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'thor'
4
- require_relative '../lib/remote_database_importer/operation'
5
-
6
- class RemoteDatabaseImporterCLI < Thor
7
- desc "Restore remote database and import it locally", "asdf"
8
- def import
9
- importer = RemoteDatabaseImporter::Operation.new
10
- importer.import
11
- end
12
- end
13
-
14
- RemoteDatabaseImporterCLI.start
Binary file