edb 0.6.1 → 0.7

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
  SHA1:
3
- metadata.gz: e17dd73f932110daaefd68f24eba4d82996d1bfe
4
- data.tar.gz: ed2f112288ebc8c6f2af8d419e68acfdf149ad3f
3
+ metadata.gz: 2426e583c0d94ddcc3c4fbf55620043de8c18969
4
+ data.tar.gz: 59808abd908171f56f439e0885dea15d99fc88f1
5
5
  SHA512:
6
- metadata.gz: 6117055df2f1cc9b1df10eee1c12feb4f5255efba51ac22a8be0645a188071a2c6aa1bc5648a6841f058f0268d122da22da76c019078bd730ff0b63779eec176
7
- data.tar.gz: 024d5044d2df77d90363b419468fe31c1a4a91cfe4352660168f83eff45073765eba607a5c5f800cdaedcb5440414e7a3c1ea2e8d2938d354e73f23fc50381f3
6
+ metadata.gz: 1f2806467e8187fcf5009f1e1e930b1177865199ecdcca96fc279d90164720a56c3fb8352516df3398e1d67e035414894a1feb2a1cda3cfacf9c1688a079c272
7
+ data.tar.gz: 8e57f560faa01069b81602fec1a4e7ec705bdd2655fa5d59a53202147e2f696b28a9270fd535feb60bc5633eb1d5381eca44c0a70e95789b79ac689c724c9207
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- edb (0.6.1)
4
+ edb (0.7)
5
5
  aws-sdk (= 1.59.1)
6
6
  fast_secure_compare (~> 1.0)
7
7
  ftp_sync (~> 0.4)
@@ -7,6 +7,10 @@
7
7
  :database: sample_database
8
8
  :host: localhost
9
9
  :port: 5432
10
+ :include_cluster: true
11
+ :only_tables: []
12
+ :exclude_tables: ['trash_table']
13
+ :run_sql_after_backup: ~/Documents/clear_tables.sql
10
14
 
11
15
  :MySQL:
12
16
  :binpath: /Applications/MAMP/Library/bin
@@ -29,17 +29,31 @@ module EDB
29
29
  def backup(dir_name)
30
30
  db = ::EDB.opts[:DBMS][:PostgreSQL]
31
31
  files = {
32
- dump: File.join(dir_name, "#{db[:database]}.sql"),
33
- cluster: File.join(dir_name, 'cluster.sql')
32
+ dump: File.join(dir_name, "#{db[:database]}.sql")
34
33
  }
35
34
 
36
35
  ::EDB::Logger.log(:info, "Dumping #{db[:database]}...")
36
+
37
+ only_tables = (db[:only_tables] || []).reject(&:empty?).map { |t| "-t #{t}" }.join(' ')
38
+ exclude_tables = (db[:exclude_tables] || []).reject(&:empty?).map { |t| "-T #{t}" }.join(' ')
39
+
37
40
  pg_dump = db[:binpath] && !db[:binpath].empty? ? File.join(db[:binpath], 'pg_dump') : 'pg_dump'
38
- Kernel.system "PGPASSWORD='#{db[:password]}' #{pg_dump} -h #{db[:host]} -p #{db[:port]} -U #{db[:username]} -F c -b -f '#{files[:dump]}' #{db[:database]}"
41
+ Kernel.system "PGPASSWORD='#{db[:password]}' #{pg_dump} -h #{db[:host]} -p #{db[:port]} -U #{db[:username]} -F c -b -f '#{files[:dump]}' #{only_tables} #{exclude_tables} #{db[:database]}"
42
+
43
+ if db[:include_cluster] == true
44
+ ::EDB::Logger.log(:info, 'Dumping the cluster...')
45
+
46
+ files[:cluster] = File.join(dir_name, 'cluster.sql')
47
+ pg_dumpall = db[:binpath] && !db[:binpath].empty? ? File.join(db[:binpath], 'pg_dumpall') : 'pg_dumpall'
48
+ Kernel.system "PGPASSWORD='#{db[:password]}' #{pg_dumpall} -h #{db[:host]} -p #{db[:port]} -U #{db[:username]} -f '#{files[:cluster]}'"
49
+ end
50
+
51
+ if db[:run_sql_after_backup] && File.exists?(db[:run_sql_after_backup])
52
+ ::EDB::Logger.log(:info, "Executing #{File.basename(db[:run_sql_after_backup])}...")
39
53
 
40
- ::EDB::Logger.log(:info, 'Dumping the cluster...')
41
- pg_dumpall = db[:binpath] && !db[:binpath].empty? ? File.join(db[:binpath], 'pg_dumpall') : 'pg_dumpall'
42
- Kernel.system "PGPASSWORD='#{db[:password]}' #{pg_dumpall} -h #{db[:host]} -p #{db[:port]} -U #{db[:username]} -f '#{files[:cluster]}'"
54
+ psql = db[:binpath] && !db[:binpath].empty? ? File.join(db[:binpath], 'psql') : 'psql'
55
+ Kernel.system "PGPASSWORD='#{db[:password]}' #{psql} -h #{db[:host]} -p #{db[:port]} -U #{db[:username]} -d #{db[:database]} -f #{db[:run_sql_after_backup]}"
56
+ end
43
57
 
44
58
  files.values
45
59
  end
@@ -23,5 +23,5 @@
23
23
  #++
24
24
 
25
25
  module EDB
26
- VERSION = '0.6.1'
26
+ VERSION = '0.7'
27
27
  end
@@ -2,22 +2,38 @@ require_relative '../spec_helper'
2
2
 
3
3
  describe EDB::DBMS::PostgreSQL do
4
4
  describe '#backup' do
5
- let(:dump) { "PGPASSWORD='password' /Applications/Postgres.app/Contents/Versions/9.3/bin/pg_dump -h localhost -p 5432 -U username -F c -b -f './sample_database.sql' sample_database" }
6
- let(:cluster) { "PGPASSWORD='password' /Applications/Postgres.app/Contents/Versions/9.3/bin/pg_dumpall -h localhost -p 5432 -U username -f './cluster.sql'" }
5
+ let(:dump) { "PGPASSWORD='password' /Applications/Postgres.app/Contents/Versions/9.3/bin/pg_dump -h localhost -p 5432 -U username -F c -b -f './sample_database.sql' -T trash_table sample_database" }
6
+ let(:cluster) { "PGPASSWORD='password' /Applications/Postgres.app/Contents/Versions/9.3/bin/pg_dumpall -h localhost -p 5432 -U username -f './cluster.sql'" }
7
+ let(:after_sql) { "PGPASSWORD='password' /Applications/Postgres.app/Contents/Versions/9.3/bin/psql -h localhost -p 5432 -U username -d sample_database -f ~/Documents/clear_tables.sql" }
7
8
 
8
9
  it 'calls pg_dump correctly' do
9
10
  allow(Kernel).to receive(:system).and_wrap_original do |m, *args|
10
- expect(args[0]).to satisfy { |c| [dump, cluster].include?(c) }
11
+ expect(args[0]).to satisfy { |c| [dump, cluster, after_sql].include?(c) }
11
12
  end
12
13
 
13
14
  EDB::DBMS::PostgreSQL.backup('.')
14
15
  end
15
16
 
16
- it 'returns the the files that have been created' do
17
- allow(Kernel).to receive(:system).and_wrap_original {}
17
+ context 'include_cluster is true' do
18
+ it 'returns the files that have been created' do
19
+ allow(Kernel).to receive(:system).and_wrap_original {}
18
20
 
19
- results = EDB::DBMS::PostgreSQL.backup('.')
20
- expect(results).to eq ['./sample_database.sql', './cluster.sql']
21
+ results = EDB::DBMS::PostgreSQL.backup('.')
22
+ expect(results).to eq ['./sample_database.sql', './cluster.sql']
23
+ end
24
+ end
25
+
26
+ context 'include_cluster is false' do
27
+ before :each do
28
+ EDB.opts[:DBMS][:PostgreSQL][:include_cluster] = false
29
+ end
30
+
31
+ it 'returns the files that have been created' do
32
+ allow(Kernel).to receive(:system).and_wrap_original {}
33
+
34
+ results = EDB::DBMS::PostgreSQL.backup('.')
35
+ expect(results).to eq ['./sample_database.sql']
36
+ end
21
37
  end
22
38
  end
23
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: edb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: '0.7'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Giovanni Capuano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-17 00:00:00.000000000 Z
11
+ date: 2015-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk