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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +7 -7
- data/lib/pgsync.rb +51 -36
- data/lib/pgsync/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d12ffec2fc5681c48eb5f13eafca045330d3615f
|
4
|
+
data.tar.gz: f8ed258ee86c6cc099299b1e962856500431d6ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f19de0157cf9e4ccadea5e787c6413995cfbcb9bd086750512c3392be495df3b7bc1868bd55fdc27d0e65c7a81adefbda6c9118dd9cf4f17b9102b2cc0628994
|
7
|
+
data.tar.gz: 1248be9efc810bf5eb14685696e0b5214740549af940aa67cb9f6484651b72bed4ed8ca82d85a4ea26b840f69208606064c6eb9935f027ce64079c02b95f2baa
|
data/CHANGELOG.md
CHANGED
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
|
-
|
23
|
+
Sync all tables
|
24
24
|
|
25
25
|
```sh
|
26
26
|
pgsync
|
27
27
|
```
|
28
28
|
|
29
|
-
|
29
|
+
Sync specific tables
|
30
30
|
|
31
31
|
```sh
|
32
32
|
pgsync table1,table2
|
33
33
|
```
|
34
34
|
|
35
|
-
|
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
|
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
|
-
|
98
|
+
Sync schema
|
99
99
|
|
100
100
|
```sh
|
101
101
|
pgsync --schema-only
|
data/lib/pgsync.rb
CHANGED
@@ -40,13 +40,23 @@ module PgSync
|
|
40
40
|
end
|
41
41
|
command = args[0]
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
49
|
-
|
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 [
|
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
|
515
|
-
tables
|
516
|
-
specified_groups = to_arr(
|
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["
|
520
|
-
t
|
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
|
-
|
529
|
-
|
530
|
-
|
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[
|
549
|
+
tables[table][:sql] = args[1].to_s.gsub("{id}", cast(id)) if args[1]
|
534
550
|
end
|
535
|
-
|
551
|
+
end
|
552
|
+
|
553
|
+
if args[0]
|
536
554
|
# could be a group, table, or mix
|
537
|
-
tables
|
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
|
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
|
data/lib/pgsync/version.rb
CHANGED