pgsync 0.3.2 → 0.3.3
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 +6 -0
- data/lib/pgsync.rb +22 -12
- data/lib/pgsync/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be53714690e45e12a419c524673bddecbb151fa1
|
4
|
+
data.tar.gz: 6c4a70c4296a2bc96121fbfc7b0512dc9e47ab1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13542ba5e8ac5f81be20154f51ba9ea45fd9fc2bfb8d9e3abcbd32eee620f4a3fbb1c71493909ef44664982240ea59e05f0ed829032d8c6ec06f0a4c4b53cf7c
|
7
|
+
data.tar.gz: fe69eac5b5acdfa879664ed5bc88ae99abe853f5cbf4af093b43849be98315acb2695f2fd92ca49b883322a03d541f2da7e79c7914040bbf4ab0943ff68db5c5
|
data/CHANGELOG.md
CHANGED
data/lib/pgsync.rb
CHANGED
@@ -93,8 +93,10 @@ module PgSync
|
|
93
93
|
if opts[:schema_only]
|
94
94
|
log "* Dumping schema"
|
95
95
|
tables = tables.keys.map { |t| "-t #{t}" }.join(" ")
|
96
|
-
|
97
|
-
|
96
|
+
psql_version = Gem::Version.new(`psql --version`.split(" ").last)
|
97
|
+
if_exists = psql_version >= Gem::Version.new("9.4.0")
|
98
|
+
dump_command = "pg_dump -Fc --verbose --schema-only --no-owner --no-acl #{tables} #{to_url(source_uri)}"
|
99
|
+
restore_command = "pg_restore --verbose --no-owner --no-acl --clean #{if_exists ? "--if-exists" : nil} -d #{to_url(destination_uri)}"
|
98
100
|
system("#{dump_command} | #{restore_command}")
|
99
101
|
|
100
102
|
log_completed(start_time)
|
@@ -245,13 +247,13 @@ module PgSync
|
|
245
247
|
Options:}
|
246
248
|
o.string "-t", "--tables", "tables"
|
247
249
|
o.string "-g", "--groups", "groups"
|
250
|
+
o.string "-d", "--db", "database"
|
248
251
|
o.string "--from", "source"
|
249
252
|
o.string "--to", "destination"
|
250
253
|
o.string "--where", "where", help: false
|
251
254
|
o.integer "--limit", "limit", help: false
|
252
255
|
o.string "--exclude", "exclude tables"
|
253
256
|
o.string "--config", "config file"
|
254
|
-
o.string "--db", "database"
|
255
257
|
# TODO much better name for this option
|
256
258
|
o.boolean "--to-safe", "accept danger", default: false
|
257
259
|
o.boolean "--debug", "debug", default: false
|
@@ -516,19 +518,27 @@ Options:}
|
|
516
518
|
end
|
517
519
|
end
|
518
520
|
|
519
|
-
def add_tables(tables, t, id, boom)
|
521
|
+
def add_tables(tables, t, id, boom, from_uri)
|
520
522
|
t.each do |table|
|
521
523
|
sql = nil
|
522
524
|
if table.is_a?(Array)
|
523
525
|
table, sql = table
|
524
526
|
end
|
525
|
-
add_table(tables, table, id, boom || sql)
|
527
|
+
add_table(tables, table, id, boom || sql, from_uri)
|
526
528
|
end
|
527
529
|
end
|
528
530
|
|
529
|
-
def add_table(tables, table, id, boom)
|
530
|
-
|
531
|
-
|
531
|
+
def add_table(tables, table, id, boom, from_uri, wildcard = false)
|
532
|
+
if table.include?("*") && !wildcard
|
533
|
+
regex = Regexp.new('\A' + Regexp.escape(table).gsub('\*','[^\.]*') + '\z')
|
534
|
+
t2 = with_connection(from_uri) { |conn| self.tables(conn, "public") }.select { |t| regex.match(t) }
|
535
|
+
t2.each do |table|
|
536
|
+
add_table(tables, table, id, boom, from_uri, true)
|
537
|
+
end
|
538
|
+
else
|
539
|
+
tables[table] = {}
|
540
|
+
tables[table][:sql] = boom.gsub("{id}", cast(id)).gsub("{1}", cast(id)) if boom
|
541
|
+
end
|
532
542
|
end
|
533
543
|
|
534
544
|
def table_list(args, opts, from_uri)
|
@@ -540,7 +550,7 @@ Options:}
|
|
540
550
|
specified_groups.map do |tag|
|
541
551
|
group, id = tag.split(":", 2)
|
542
552
|
if (t = (config["groups"] || {})[group])
|
543
|
-
add_tables(tables, t, id, args[1])
|
553
|
+
add_tables(tables, t, id, args[1], from_uri)
|
544
554
|
else
|
545
555
|
abort "Group not found: #{group}"
|
546
556
|
end
|
@@ -551,7 +561,7 @@ Options:}
|
|
551
561
|
tables ||= Hash.new { |hash, key| hash[key] = {} }
|
552
562
|
to_arr(opts[:tables]).each do |tag|
|
553
563
|
table, id = tag.split(":", 2)
|
554
|
-
add_table(tables, table, id, args[1])
|
564
|
+
add_table(tables, table, id, args[1], from_uri)
|
555
565
|
end
|
556
566
|
end
|
557
567
|
|
@@ -562,9 +572,9 @@ Options:}
|
|
562
572
|
specified_groups.map do |tag|
|
563
573
|
group, id = tag.split(":", 2)
|
564
574
|
if (t = (config["groups"] || {})[group])
|
565
|
-
add_tables(tables, t, id, args[1])
|
575
|
+
add_tables(tables, t, id, args[1], from_uri)
|
566
576
|
else
|
567
|
-
add_table(tables, group, id, args[1])
|
577
|
+
add_table(tables, group, id, args[1], from_uri)
|
568
578
|
end
|
569
579
|
end
|
570
580
|
end
|
data/lib/pgsync/version.rb
CHANGED
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.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: slop
|