-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
84 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import color from '@heroku-cli/color' | ||
import {Command, flags} from '@heroku-cli/command' | ||
import {Args, ux} from '@oclif/core' | ||
import * as Heroku from '@heroku-cli/schema' | ||
import {getAddon} from '../../lib/pg/fetcher' | ||
import pgHost from '../../lib/pg/host' | ||
import {databaseNameFromUrl} from '../../lib/pg/util' | ||
import confirmCommand from '../../lib/confirmCommand' | ||
import {PgDatabase} from '../../lib/pg/types' | ||
import heredoc from 'tsheredoc' | ||
|
||
export default class Unfollow extends Command { | ||
static topic = 'pg'; | ||
static description = 'stop a replica from following and make it a writeable database'; | ||
static flags = { | ||
confirm: flags.string({char: 'c'}), | ||
app: flags.app({required: true}), | ||
remote: flags.remote(), | ||
} | ||
|
||
static args = { | ||
database: Args.string({required: true}), | ||
} | ||
|
||
public async run(): Promise<void> { | ||
const {flags, args} = await this.parse(Unfollow) | ||
const {app, confirm} = flags | ||
const db = await getAddon(this.heroku, app, args.database) | ||
const {body: replica} = await this.heroku.get<PgDatabase>(`/client/v11/databases/${db.id}`, {hostname: pgHost()}) | ||
if (!replica.following) | ||
ux.error(`${color.addon(db.name)} is not a follower`) | ||
const {body: configVars} = await this.heroku.get<Heroku.ConfigVars>(`/apps/${app}/config-vars`) | ||
const origin = databaseNameFromUrl(replica.following as string, configVars) | ||
await confirmCommand(app, confirm, heredoc(` | ||
Destructive action | ||
${color.addon(db.name)} will become writeable and no longer follow ${origin}. This cannot be undone. | ||
`)) | ||
ux.action.start(`${color.addon(db.name)} unfollowing`) | ||
await this.heroku.put(`/client/v11/databases/${db.id}/unfollow`, {hostname: pgHost()}) | ||
ux.action.stop() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import {stderr} from 'stdout-stderr' | ||
import * as nock from 'nock' | ||
import Cmd from '../../../../src/commands/pg/unfollow' | ||
import runCommand from '../../../helpers/runCommand' | ||
import expectOutput from '../../../helpers/utils/expectOutput' | ||
import heredoc from 'tsheredoc' | ||
import * as fixtures from '../../../fixtures/addons/fixtures' | ||
|
||
describe('pg:unfollow', () => { | ||
const addon = fixtures.addons['dwh-db'] | ||
const appName = 'myapp' | ||
|
||
afterEach(() => { | ||
nock.cleanAll() | ||
}) | ||
|
||
it('unfollows db', async () => { | ||
nock('https://api.heroku.com') | ||
.post('/actions/addon-attachments/resolve') | ||
.reply(200, [{addon}]) | ||
nock('https://api.heroku.com') | ||
.get(`/apps/${appName}/config-vars`) | ||
.reply(200, {DATABASE_URL: 'postgres://db1'}) | ||
nock('https://api.data.heroku.com') | ||
.get(`/client/v11/databases/${addon.id}`) | ||
.reply(200, {following: 'postgres://db1'}) | ||
.put(`/client/v11/databases/${addon.id}/unfollow`) | ||
.reply(200) | ||
|
||
await runCommand(Cmd, [ | ||
'--app', | ||
appName, | ||
'--confirm', | ||
appName, | ||
'DATABASE', | ||
]) | ||
expectOutput(stderr.output, heredoc(` | ||
${addon.name} unfollowing... | ||
${addon.name} unfollowing... done | ||
`)) | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.