aptible-cli 0.16.1 → 0.16.2

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
  SHA256:
3
- metadata.gz: d7a82ca8dc7db1d4eb55e92d7a78f8dda19f3b0e868d913695f9a974079cdf45
4
- data.tar.gz: b043caa7662d1406a445e53e02daecdeb08e17a2fadeb448f94155091ac8c6d8
3
+ metadata.gz: c50391308952a422d84f497808c25fbaf4c405730497266a299e69b632f37887
4
+ data.tar.gz: 6146d0c3dc58d7ef9786f95a341a22d500689c42f67ed48c0b824f62a2f250c6
5
5
  SHA512:
6
- metadata.gz: 1d70a4ebaf642e840db0ec5bdfc287a5ca692cf4113173251e6480818b29ad70ee83792672f601a41495b8c55312196835a3e7b12b9364290f95191fae1c2f7c
7
- data.tar.gz: f3c1b30a29637d5f872349e45d54d8ce0856a2a467039483bb4cfac872204c15cb2d249650acb5debb7274584aa176459750473ca5cc2d6dc01e63435ce6042b
6
+ metadata.gz: 156abd2537b61dd8416ce75f6b8389e807306869254bef47db51c80e081a433e3b802483327748c0bb18c9c5691dd537fc14f4f536c55505f01e8c7aa2a86849
7
+ data.tar.gz: eec30d958642888b92418343ded298ba9ddb49b370395795281e4390494c0a480c771b202b0e7845c1a953c43354cb9aa3404f31589146741fe6d6e2c91f1707
@@ -0,0 +1 @@
1
+ * @usernotfound
data/README.md CHANGED
@@ -45,7 +45,7 @@ Commands:
45
45
  aptible db:create HANDLE [--type TYPE] [--version VERSION] [--container-size SIZE_MB] [--size SIZE_GB] # Create a new database
46
46
  aptible db:deprovision HANDLE # Deprovision a database
47
47
  aptible db:dump HANDLE [pg_dump options] # Dump a remote database to file
48
- aptible db:execute HANDLE SQL_FILE # Executes sql against a database
48
+ aptible db:execute HANDLE SQL_FILE [--on-error-stop] # Executes sql against a database
49
49
  aptible db:list # List all databases
50
50
  aptible db:reload HANDLE # Reload a database
51
51
  aptible db:restart HANDLE [--container-size SIZE_MB] [--size SIZE_GB] # Restart a database
@@ -108,6 +108,4 @@ The default format is `text`.
108
108
 
109
109
  MIT License, see [LICENSE](LICENSE.md) for details.
110
110
 
111
- Copyright (c) 2016 [Aptible](https://www.aptible.com) and contributors.
112
-
113
- [<img src="https://s.gravatar.com/avatar/f7790b867ae619ae0496460aa28c5861?s=60" style="border-radius: 50%;" alt="@fancyremarker" />](https://github.com/fancyremarker)
111
+ Copyright (c) 2019 [Aptible](https://www.aptible.com) and contributors.
@@ -1,5 +1,6 @@
1
1
  require 'term/ansicolor'
2
2
  require 'uri'
3
+ require 'English'
3
4
 
4
5
  module Aptible
5
6
  module CLI
@@ -122,16 +123,21 @@ module Aptible
122
123
  filename = "#{handle}.dump"
123
124
  CLI.logger.info "Dumping to #{filename}"
124
125
  `pg_dump #{url} #{dump_options.shelljoin} > #{filename}`
126
+ exit $CHILD_STATUS.exitstatus unless $CHILD_STATUS.success?
125
127
  end
126
128
  end
127
129
 
128
- desc 'db:execute HANDLE SQL_FILE', 'Executes sql against a database'
130
+ desc 'db:execute HANDLE SQL_FILE [--on-error-stop]',
131
+ 'Executes sql against a database'
129
132
  option :environment
133
+ option :on_error_stop, type: :boolean
130
134
  define_method 'db:execute' do |handle, sql_path|
131
135
  database = ensure_database(options.merge(db: handle))
132
136
  with_postgres_tunnel(database) do |url|
133
137
  CLI.logger.info "Executing #{sql_path} against #{handle}"
134
- `psql #{url} < #{sql_path}`
138
+ args = options[:on_error_stop] ? '-v ON_ERROR_STOP=true ' : ''
139
+ `psql #{args}#{url} < #{sql_path}`
140
+ exit $CHILD_STATUS.exitstatus unless $CHILD_STATUS.success?
135
141
  end
136
142
  end
137
143
 
@@ -1,5 +1,5 @@
1
1
  module Aptible
2
2
  module CLI
3
- VERSION = '0.16.1'.freeze
3
+ VERSION = '0.16.2'.freeze
4
4
  end
5
5
  end
@@ -450,59 +450,169 @@ describe Aptible::CLI::Agent do
450
450
  context 'valid database' do
451
451
  before do
452
452
  allow(Aptible::Api::Database).to receive(:all) { [database] }
453
- allow(subject).to receive(:`).with(/pg_dump .*/)
454
453
  end
455
454
 
456
- it 'prints a message indicating the dump is happening' do
455
+ it 'exits with the same code as pg_dump' do
456
+ exit_status = 123
457
457
  cred = Fabricate(:database_credential, default: true, type: 'foo',
458
458
  database: database)
459
459
 
460
+ allow(subject).to receive(:`).with(/pg_dump/) do
461
+ `exit #{exit_status}`
462
+ end
463
+
460
464
  expect(subject).to receive(:with_local_tunnel).with(cred)
461
465
  .and_yield(socat_helper)
462
466
 
463
- subject.send('db:dump', handle)
464
-
465
- expect(captured_logs)
466
- .to match(/Dumping to foobar.dump/i)
467
+ expect do
468
+ subject.send('db:dump', handle)
469
+ end.to raise_error { |error|
470
+ expect(error).to be_a SystemExit
471
+ expect(error.status).to eq exit_status
472
+ }
467
473
  end
468
474
 
469
- it 'invokes pg_dump with the tunnel url' do
470
- cred = Fabricate(:database_credential, default: true, type: 'foo',
471
- database: database)
475
+ context 'successful dump' do
476
+ before do
477
+ allow(subject).to receive(:`).with(/pg_dump .*/) do
478
+ `exit 0`
479
+ end
480
+ end
472
481
 
473
- expect(subject).to receive(:with_local_tunnel).with(cred)
474
- .and_yield(socat_helper)
482
+ it 'prints a message indicating the dump is happening' do
483
+ cred = Fabricate(:database_credential, default: true, type: 'foo',
484
+ database: database)
475
485
 
476
- local_url = 'postgresql://aptible:password@localhost.aptible.in:4242/db'
486
+ expect(subject).to receive(:with_local_tunnel).with(cred)
487
+ .and_yield(socat_helper)
477
488
 
478
- expect(subject).to receive(:`)
479
- .with(/pg_dump #{local_url} > foobar.dump/)
489
+ subject.send('db:dump', handle)
480
490
 
481
- subject.send('db:dump', handle)
491
+ expect(captured_logs)
492
+ .to match(/Dumping to foobar.dump/i)
493
+ end
494
+
495
+ it 'invokes pg_dump with the tunnel url' do
496
+ cred = Fabricate(:database_credential, default: true, type: 'foo',
497
+ database: database)
498
+
499
+ expect(subject).to receive(:with_local_tunnel).with(cred)
500
+ .and_yield(socat_helper)
501
+
502
+ local_url = 'postgresql://aptible:password@localhost.aptible.in:4242'\
503
+ '/db'
504
+
505
+ expect(subject).to receive(:`)
506
+ .with(/pg_dump #{local_url} > foobar.dump/)
507
+
508
+ subject.send('db:dump', handle)
509
+ end
510
+
511
+ it 'sends extra options if given' do
512
+ cred = Fabricate(:database_credential, default: true, type: 'foo',
513
+ database: database)
514
+
515
+ expect(subject).to receive(:with_local_tunnel).with(cred)
516
+ .and_yield(socat_helper)
517
+
518
+ pg_dump_options = '--exclude-table-data=events ' \
519
+ '--exclude-table-data=versions'
520
+ allow(subject).to receive(:`).with(/pg_dump .* #{pg_dump_options} .*/)
521
+
522
+ subject.send('db:dump', handle,
523
+ '--exclude-table-data=events',
524
+ '--exclude-table-data=versions')
525
+ end
526
+
527
+ it 'fails when the database is not provisioned' do
528
+ allow(database).to receive(:status) { 'pending' }
529
+
530
+ expect { subject.send('db:dump', handle) }
531
+ .to raise_error(/foobar is not provisioned/im)
532
+ end
482
533
  end
534
+ end
535
+ end
536
+
537
+ describe '#db:execute' do
538
+ sql_path = 'file.sql'
539
+ it 'should fail if database is non-existent' do
540
+ allow(Aptible::Api::Database).to receive(:all) { [] }
541
+ expect do
542
+ subject.send('db:execute', handle, sql_path)
543
+ end.to raise_error("Could not find database #{handle}")
544
+ end
483
545
 
484
- it 'sends extra options if given' do
546
+ context 'valid database' do
547
+ before do
548
+ allow(Aptible::Api::Database).to receive(:all) { [database] }
549
+ allow(subject).to receive(:`).with(/psql .*/) { `exit 0` }
550
+ end
551
+
552
+ it 'executes the file against the URL' do
485
553
  cred = Fabricate(:database_credential, default: true, type: 'foo',
486
554
  database: database)
487
555
 
488
556
  expect(subject).to receive(:with_local_tunnel).with(cred)
489
557
  .and_yield(socat_helper)
490
558
 
491
- pg_dump_options = '--exclude-table-data=events ' \
492
- '--exclude-table-data=versions'
493
- allow(subject).to receive(:`).with(/pg_dump .* #{pg_dump_options} .*/)
559
+ local_url = 'postgresql://aptible:password@localhost.aptible.in:4242/db'
560
+
561
+ expect(subject).to receive(:`).with(/psql #{local_url} < #{sql_path}/)
494
562
 
495
- subject.send('db:dump', handle,
496
- '--exclude-table-data=events',
497
- '--exclude-table-data=versions')
563
+ subject.send('db:execute', handle, sql_path)
564
+
565
+ expect(captured_logs)
566
+ .to match(/Executing #{sql_path} against #{handle}/)
498
567
  end
499
568
 
500
569
  it 'fails when the database is not provisioned' do
501
570
  allow(database).to receive(:status) { 'pending' }
502
571
 
503
- expect { subject.send('db:dump', handle) }
572
+ expect { subject.send('db:execute', handle, sql_path) }
504
573
  .to raise_error(/foobar is not provisioned/im)
505
574
  end
575
+
576
+ context 'on error stop' do
577
+ before do
578
+ subject.options = { on_error_stop: true }
579
+ end
580
+
581
+ it 'adds the ON_ERROR_STOP argument' do
582
+ cred = Fabricate(:database_credential, default: true, type: 'foo',
583
+ database: database)
584
+
585
+ expect(subject).to receive(:with_local_tunnel).with(cred)
586
+ .and_yield(socat_helper)
587
+
588
+ local_url = 'postgresql://aptible:password@localhost.aptible.in:4242'\
589
+ '/db'
590
+
591
+ expect(subject).to receive(:`)
592
+ .with(/psql -v ON_ERROR_STOP=true #{local_url} < #{sql_path}/)
593
+
594
+ subject.send('db:execute', handle, sql_path)
595
+ end
596
+
597
+ it 'exits with the same code as psql' do
598
+ exit_status = 123
599
+ allow(subject).to receive(:`).with(/psql .*/) {
600
+ `exit #{exit_status}`
601
+ }
602
+ cred = Fabricate(:database_credential, default: true, type: 'foo',
603
+ database: database)
604
+
605
+ expect(subject).to receive(:with_local_tunnel).with(cred)
606
+ .and_yield(socat_helper)
607
+
608
+ expect do
609
+ subject.send('db:execute', handle, sql_path)
610
+ end.to raise_error { |error|
611
+ expect(error).to be_a SystemExit
612
+ expect(error.status).to eq exit_status
613
+ }
614
+ end
615
+ end
506
616
  end
507
617
  end
508
618
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aptible-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.1
4
+ version: 0.16.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Macreery
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-31 00:00:00.000000000 Z
11
+ date: 2019-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aptible-resource
@@ -248,6 +248,7 @@ executables:
248
248
  extensions: []
249
249
  extra_rdoc_files: []
250
250
  files:
251
+ - ".github/CODEOWNERS"
251
252
  - ".gitignore"
252
253
  - ".rspec"
253
254
  - ".travis.yml"