pgsync 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of pgsync might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 58a427f20bdf42cd97ca4101964a571ab7f5da76
4
- data.tar.gz: 13da001cf27f6ddda55a96b5f9ec3a8e27577eb5
3
+ metadata.gz: 6bb82b59d50e88dd20c969af273b2a0caeee6764
4
+ data.tar.gz: 291db7c3a69dcb341c9079f13635bbd057d5ea06
5
5
  SHA512:
6
- metadata.gz: 7399365349da94533619effdeee4c80d05817384b75377af12c4d2f05d1cc2af6b9681dcc0e9b5d4cf8c3616e9f7f048b6b3fd7ca765d74b97437f29a503e04c
7
- data.tar.gz: 15abafa358b77760f493d28f7c20ad8c44cf2e5a6e3ed7f5432f2b2b50c0aa67c465219026f705e1e37da4830c6881fc579ccb756ea694a05429c92c4f270112
6
+ metadata.gz: bd3ad5d52e94b6ed1466ee49ebb843ea74cc9ec1397d56587972c4d1388b707bb98d1921ee26f96393a27cd6b254973cf804770ab4514a325b8621797c58ff36
7
+ data.tar.gz: 06ab1eab6b466d21f9d641b3aaeb5134caaa372db806efcd860dd3cf6a28cf4b22c7a417d88af8bc2463e2fee1f2a83dd447711547298e0fe29aa7a45ff92f31
@@ -0,0 +1,8 @@
1
+ # 0.1.1
2
+
3
+ - Better support for multiple databases
4
+ - Search parent directories for config file
5
+
6
+ # 0.1.0
7
+
8
+ - First release
data/README.md CHANGED
@@ -14,7 +14,7 @@ And in your project directory, run:
14
14
  pgsync setup
15
15
  ```
16
16
 
17
- This creates a `.pgsync.yml` for you to customize. We recommend checking this into your version control (assuming it doesn’t contain sensitive information).
17
+ This creates `.pgsync.yml` for you to customize. We recommend checking this into your version control (assuming it doesn’t contain sensitive information).
18
18
 
19
19
  ## How to Use
20
20
 
@@ -91,7 +91,7 @@ And run:
91
91
  pgsync groups group1,group2
92
92
  ```
93
93
 
94
- ## Senstive Information
94
+ ## Sensitive Information
95
95
 
96
96
  Prevent sensitive information - like passwords and email addresses - from leaving the remote server.
97
97
 
@@ -125,6 +125,20 @@ Options for replacement are:
125
125
  - random_ip
126
126
  - untouched
127
127
 
128
+ ## Multiple Databases
129
+
130
+ To use with multiple databases, run:
131
+
132
+ ```sh
133
+ pgsync setup db2
134
+ ```
135
+
136
+ This creates `.pgsync-db2.yml` for you to edit. Specify a database in commands with:
137
+
138
+ ```sh
139
+ pgsync --db db2
140
+ ```
141
+
128
142
  ## Safety
129
143
 
130
144
  To keep you from accidentally overwriting production, the destination is limited to `localhost` or `127.0.0.1` by default.
@@ -13,10 +13,19 @@ module PgSync
13
13
  class Rollback < StandardError; end
14
14
 
15
15
  class Client
16
+ attr_reader :config_file
17
+
16
18
  def initialize(args)
17
19
  $stdout.sync = true
18
20
  @arguments, @options = parse_args(args)
19
- @config_file = @options[:config]
21
+ @config_file =
22
+ if @options[:db]
23
+ db_config_file(@options[:db])
24
+ else
25
+ @options[:config] || ".pgsync.yml"
26
+ end
27
+ @config_file = search_tree(@config_file)
28
+ abort "Config not found" unless @config_file
20
29
  @mutex = MultiProcessing::Mutex.new
21
30
  end
22
31
 
@@ -31,7 +40,7 @@ module PgSync
31
40
  command = args[0]
32
41
 
33
42
  if command == "setup"
34
- setup
43
+ setup(db_config_file(args[1]) || config_file)
35
44
  else
36
45
  source = parse_source(opts[:from])
37
46
  abort "No source" unless source
@@ -186,7 +195,8 @@ module PgSync
186
195
  o.string "--to", "destination"
187
196
  o.string "--where", "where"
188
197
  o.string "--exclude", "exclude tables"
189
- o.string "--config", "config file", default: ".pgsync.yml"
198
+ o.string "--config", "config file"
199
+ o.string "--db", "database"
190
200
  # TODO much better name for this option
191
201
  o.boolean "--to-safe", "accept danger", default: false
192
202
  o.on "-v", "--version", "print the version" do
@@ -203,37 +213,39 @@ module PgSync
203
213
  abort e.message
204
214
  end
205
215
 
206
- # TODO look down path
207
216
  def config
208
217
  @config ||= begin
209
- if File.exist?(@config_file)
210
- begin
211
- YAML.load_file(@config_file) || {}
212
- rescue Psych::SyntaxError => e
213
- raise PgSync::Error, e.message
214
- end
215
- else
216
- {}
218
+ begin
219
+ YAML.load_file(config_file) || {}
220
+ rescue Psych::SyntaxError => e
221
+ raise PgSync::Error, e.message
217
222
  end
218
223
  end
219
224
  end
220
225
 
221
226
  def parse_source(source)
222
227
  if source && source[0..1] == "$(" && source[-1] == ")"
223
- source = `#{source[2..-2]}`.chomp
228
+ command = source[2..-2]
229
+ # puts "Running #{command}"
230
+ source = `#{command}`.chomp
224
231
  end
225
232
  source
226
233
  end
227
234
 
228
- def setup
229
- if File.exist?(@config_file)
230
- abort "#{@config_file} exists."
235
+ def setup(config_file)
236
+ if File.exist?(config_file)
237
+ abort "#{config_file} exists."
231
238
  else
232
- FileUtils.cp(File.dirname(__FILE__) + "/../config.yml", @config_file)
233
- puts "#{@config_file} created. Add your database credentials."
239
+ FileUtils.cp(File.dirname(__FILE__) + "/../config.yml", config_file)
240
+ puts "#{config_file} created. Add your database credentials."
234
241
  end
235
242
  end
236
243
 
244
+ def db_config_file(db)
245
+ return unless db
246
+ ".pgsync-#{db}.yml"
247
+ end
248
+
237
249
  def with_connection(uri, timeout: 0)
238
250
  conn =
239
251
  PG::Connection.new(
@@ -355,6 +367,19 @@ module PgSync
355
367
  uri.to_s
356
368
  end
357
369
 
370
+ def search_tree(file)
371
+ path = Dir.pwd
372
+ # prevent infinite loop
373
+ 20.times do
374
+ absolute_file = File.join(path, file)
375
+ if File.exist?(absolute_file)
376
+ break absolute_file
377
+ end
378
+ path = File.dirname(path)
379
+ break if path == "/"
380
+ end
381
+ end
382
+
358
383
  def abort(message)
359
384
  raise PgSync::Error, message
360
385
  end
@@ -1,3 +1,3 @@
1
1
  module PgSync
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pgsync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-08 00:00:00.000000000 Z
11
+ date: 2016-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slop
@@ -117,6 +117,7 @@ extensions: []
117
117
  extra_rdoc_files: []
118
118
  files:
119
119
  - ".gitignore"
120
+ - CHANGELOG.md
120
121
  - Gemfile
121
122
  - LICENSE.txt
122
123
  - README.md
@@ -146,9 +147,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
147
  version: '0'
147
148
  requirements: []
148
149
  rubyforge_project:
149
- rubygems_version: 2.4.5
150
+ rubygems_version: 2.4.5.1
150
151
  signing_key:
151
152
  specification_version: 4
152
153
  summary: Quickly and securely sync data between environments
153
154
  test_files: []
154
- has_rdoc: