aptible-cli 0.16.1 → 0.16.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/CODEOWNERS +1 -0
- data/README.md +2 -4
- data/lib/aptible/cli/subcommands/db.rb +8 -2
- data/lib/aptible/cli/version.rb +1 -1
- data/spec/aptible/cli/subcommands/db_spec.rb +133 -23
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c50391308952a422d84f497808c25fbaf4c405730497266a299e69b632f37887
|
4
|
+
data.tar.gz: 6146d0c3dc58d7ef9786f95a341a22d500689c42f67ed48c0b824f62a2f250c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 156abd2537b61dd8416ce75f6b8389e807306869254bef47db51c80e081a433e3b802483327748c0bb18c9c5691dd537fc14f4f536c55505f01e8c7aa2a86849
|
7
|
+
data.tar.gz: eec30d958642888b92418343ded298ba9ddb49b370395795281e4390494c0a480c771b202b0e7845c1a953c43354cb9aa3404f31589146741fe6d6e2c91f1707
|
data/.github/CODEOWNERS
ADDED
@@ -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
|
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)
|
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',
|
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
|
-
|
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
|
|
data/lib/aptible/cli/version.rb
CHANGED
@@ -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 '
|
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
|
-
|
464
|
-
|
465
|
-
|
466
|
-
.to
|
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
|
-
|
470
|
-
|
471
|
-
|
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
|
-
|
474
|
-
|
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
|
-
|
486
|
+
expect(subject).to receive(:with_local_tunnel).with(cred)
|
487
|
+
.and_yield(socat_helper)
|
477
488
|
|
478
|
-
|
479
|
-
.with(/pg_dump #{local_url} > foobar.dump/)
|
489
|
+
subject.send('db:dump', handle)
|
480
490
|
|
481
|
-
|
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
|
-
|
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
|
-
|
492
|
-
|
493
|
-
|
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:
|
496
|
-
|
497
|
-
|
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:
|
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.
|
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:
|
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"
|