pgsync 0.3.0 → 0.3.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: 06dcfff629b2d6d8e5fb56719c8527b908aa41d8
4
- data.tar.gz: c3afdf8c5ac9b352c38169c65fe59ff1d55e61a5
3
+ metadata.gz: d12ffec2fc5681c48eb5f13eafca045330d3615f
4
+ data.tar.gz: f8ed258ee86c6cc099299b1e962856500431d6ac
5
5
  SHA512:
6
- metadata.gz: fb13e085bd8bb12d027166481a64cf28d6c7dda07aee78996d65dcf8f8beba91af9850d6ebf544d0cd937abfed07f4c209147c08b010306f3ef4223b49591718
7
- data.tar.gz: 2019ba48fac3b89f17d0c70069f1c975f1c052bed67bd2f8c63b7d8eaca5b396c2dbafe434dd7f0887a2b062a154210ce41bf76fd5067e190f2121209e7d6312
6
+ metadata.gz: f19de0157cf9e4ccadea5e787c6413995cfbcb9bd086750512c3392be495df3b7bc1868bd55fdc27d0e65c7a81adefbda6c9118dd9cf4f17b9102b2cc0628994
7
+ data.tar.gz: 1248be9efc810bf5eb14685696e0b5214740549af940aa67cb9f6484651b72bed4ed8ca82d85a4ea26b840f69208606064c6eb9935f027ce64079c02b95f2baa
@@ -1,3 +1,8 @@
1
+ # 0.3.1
2
+
3
+ - Added `-t` or `--tables`, `-g` or `--groups` options
4
+ - Deprecated `tables`, `groups`, and `setup` commands
5
+
1
6
  # 0.3.0
2
7
 
3
8
  - More powerful groups
data/README.md CHANGED
@@ -20,19 +20,19 @@ This creates `.pgsync.yml` for you to customize. We recommend checking this into
20
20
 
21
21
  ## How to Use
22
22
 
23
- Fetch all tables
23
+ Sync all tables
24
24
 
25
25
  ```sh
26
26
  pgsync
27
27
  ```
28
28
 
29
- Fetch specific tables
29
+ Sync specific tables
30
30
 
31
31
  ```sh
32
32
  pgsync table1,table2
33
33
  ```
34
34
 
35
- Fetch specific rows
35
+ Sync specific rows
36
36
 
37
37
  ```sh
38
38
  pgsync products "WHERE id < 1000"
@@ -76,7 +76,9 @@ And run:
76
76
  pgsync group1
77
77
  ```
78
78
 
79
- You can also sync specific rows:
79
+ You can also use groups to sync a specific record and associated records in other tables.
80
+
81
+ To get user `123` and his or her orders, use:
80
82
 
81
83
  ```yml
82
84
  groups:
@@ -91,11 +93,9 @@ And run:
91
93
  pgsync user:123
92
94
  ```
93
95
 
94
- to get rows associated with user `123`.
95
-
96
96
  ### Schema
97
97
 
98
- Fetch schema
98
+ Sync schema
99
99
 
100
100
  ```sh
101
101
  pgsync --schema-only
@@ -40,13 +40,23 @@ module PgSync
40
40
  end
41
41
  command = args[0]
42
42
 
43
- # setup hack
44
- if opts[:setup]
45
- command = "setup"
46
- args[1] = args[0]
43
+ case command
44
+ when "setup"
45
+ args.shift
46
+ opts[:setup] = true
47
+ deprecated "Use `psync --setup` instead"
48
+ when "tables"
49
+ args.shift
50
+ opts[:tables] = args.shift
51
+ deprecated "Use `pgsync #{opts[:tables]}` instead"
52
+ when "groups"
53
+ args.shift
54
+ opts[:groups] = args.shift
55
+ deprecated "Use `pgsync #{opts[:groups]}` instead"
47
56
  end
48
- if command == "setup"
49
- setup(db_config_file(args[1]) || config_file || ".pgsync.yml")
57
+
58
+ if opts[:setup]
59
+ setup(db_config_file(args[0]) || config_file || ".pgsync.yml")
50
60
  else
51
61
  source = parse_source(opts[:from])
52
62
  abort "No source" unless source
@@ -229,15 +239,11 @@ module PgSync
229
239
  def parse_args(args)
230
240
  opts = Slop.parse(args) do |o|
231
241
  o.banner = %{Usage:
232
- pgsync [command] [options]
233
-
234
- Commands:
235
- tables
236
- groups
237
- schema
238
- setup
242
+ pgsync [options]
239
243
 
240
244
  Options:}
245
+ o.string "-t", "--tables", "tables"
246
+ o.string "-g", "--groups", "groups"
241
247
  o.string "--from", "source"
242
248
  o.string "--to", "destination"
243
249
  o.string "--where", "where"
@@ -508,45 +514,50 @@ Options:}
508
514
  end
509
515
  end
510
516
 
517
+ def add_tables(tables, t, id, boom)
518
+ t.each do |table|
519
+ sql = nil
520
+ if table.is_a?(Array)
521
+ table, sql = table
522
+ end
523
+ tables[table] = {}
524
+ tables[table][:sql] = (boom || sql).to_s.gsub("{id}", cast(id)) if boom || sql
525
+ end
526
+ end
527
+
511
528
  def table_list(args, opts, from_uri)
512
529
  tables = nil
513
530
 
514
- if args[0] == "groups"
515
- tables = Hash.new { |hash, key| hash[key] = {} }
516
- specified_groups = to_arr(args[1])
531
+ if opts[:groups]
532
+ tables ||= Hash.new { |hash, key| hash[key] = {} }
533
+ specified_groups = to_arr(opts[:groups])
517
534
  specified_groups.map do |tag|
518
535
  group, id = tag.split(":", 2)
519
- if (t = config["goups"][group])
520
- t.each do |table|
521
- tables[table] = {}
522
- tables[table][:sql] = args[2].to_s.gsub("{id}", cast(id)) if args[2]
523
- end
536
+ if (t = (config["groups"] || {})[group])
537
+ add_tables(tables, t, id, args[1])
524
538
  else
525
539
  abort "Group not found: #{group}"
526
540
  end
527
541
  end
528
- elsif args[0] == "tables"
529
- tables = Hash.new { |hash, key| hash[key] = {} }
530
- to_arr(args[1]).each do |tag|
542
+ end
543
+
544
+ if opts[:tables]
545
+ tables ||= Hash.new { |hash, key| hash[key] = {} }
546
+ to_arr(opts[:tables]).each do |tag|
531
547
  table, id = tag.split(":", 2)
532
548
  tables[table] = {}
533
- tables[table][:sql] = args[2].to_s.gsub("{id}", cast(id)) if args[2]
549
+ tables[table][:sql] = args[1].to_s.gsub("{id}", cast(id)) if args[1]
534
550
  end
535
- elsif args[0]
551
+ end
552
+
553
+ if args[0]
536
554
  # could be a group, table, or mix
537
- tables = Hash.new { |hash, key| hash[key] = {} }
555
+ tables ||= Hash.new { |hash, key| hash[key] = {} }
538
556
  specified_groups = to_arr(args[0])
539
557
  specified_groups.map do |tag|
540
558
  group, id = tag.split(":", 2)
541
- if (t = config["groups"][group])
542
- t.each do |table|
543
- sql = nil
544
- if table.is_a?(Array)
545
- table, sql = table
546
- end
547
- tables[table] = {}
548
- tables[table][:sql] = (args[1] || sql).to_s.gsub("{id}", cast(id)) if args[1] || sql
549
- end
559
+ if (t = (config["groups"] || {})[group])
560
+ add_tables(tables, t, id, args[1])
550
561
  else
551
562
  tables[group] = {}
552
563
  tables[group][:sql] = args[1].to_s.gsub("{id}", cast(id)) if args[1]
@@ -570,5 +581,9 @@ Options:}
570
581
  def cast(value)
571
582
  value.to_s
572
583
  end
584
+
585
+ def deprecated(message)
586
+ log "[DEPRECATED] #{message}"
587
+ end
573
588
  end
574
589
  end
@@ -1,3 +1,3 @@
1
1
  module PgSync
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pgsync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane