Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions packages/cli/src/commands/pg/upgrade/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import {nls} from '../../../nls'
export default class Upgrade extends Command {
static topic = 'pg';
static description = heredoc(`
Were deprecating this command. To upgrade your database's Postgres version, use the new ${color.cmd('pg:upgrade:*')} subcommands. See https://devcenter.heroku.com/changelog-items/3179.
We're deprecating this command. To upgrade your database's Postgres version, use the new ${color.cmd('pg:upgrade:*')} subcommands. See https://devcenter.heroku.com/changelog-items/3179.

For an Essential-* plan, this command upgrades the database's Postgres version. For a Standard-tier and higher plan, this command unfollows the leader database before upgrading the Postgres version.
For an Essential-tier plan, this command upgrades the database's Postgres version. For a Standard-tier and higher plan, this command unfollows the leader database before upgrading the Postgres version.
`)

static flags = {
Expand Down Expand Up @@ -46,25 +46,25 @@ export default class Upgrade extends Command {
const origin = databaseNameFromUrl(replica.following, configVars)

await confirmCommand(app, confirm, heredoc(`
Were deprecating this command. To upgrade your database's Postgres version, use the new ${color.cmd('pg:upgrade:*')} subcommands. See https://devcenter.heroku.com/changelog-items/3179.
We're deprecating this command. To upgrade your database's Postgres version, use the new ${color.cmd('pg:upgrade:*')} subcommands. See https://devcenter.heroku.com/changelog-items/3179.

Destructive action
You're upgrading ${color.addon(db.name)} to ${versionPhrase}. The database will stop following ${origin} and become writable.

This cannot be undone.
You can't undo this action.
`))
} else if (essentialNumPlan(db)) {
await confirmCommand(app, confirm, heredoc(`
Were deprecating this command. To upgrade your database's Postgres version, use the new ${color.cmd('pg:upgrade:*')} subcommands. See https://devcenter.heroku.com/changelog-items/3179.
We're deprecating this command. To upgrade your database's Postgres version, use the new ${color.cmd('pg:upgrade:*')} subcommands. See https://devcenter.heroku.com/changelog-items/3179.

Destructive action
You're upgrading ${color.addon(db.name)} to ${versionPhrase}.

This cannot be undone.
You can't undo this action.
`))
} else {
ux.warn(heredoc(`
Were deprecating this command. To upgrade your database's Postgres version, use the new ${color.cmd('pg:upgrade:*')} subcommands. See https://devcenter.heroku.com/changelog-items/3179.`,
We're deprecating this command. To upgrade your database's Postgres version, use the new ${color.cmd('pg:upgrade:*')} subcommands. See https://devcenter.heroku.com/changelog-items/3179.`,
))
ux.error(`You can only use ${color.cmd('heroku pg:upgrade')} on Essential-tier databases and follower databases on Standard-tier and higher plans.`)
}
Expand Down
101 changes: 101 additions & 0 deletions packages/cli/src/commands/pg/upgrade/run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import color from '@heroku-cli/color'
import {Command, flags} from '@heroku-cli/command'
import {Args, ux} from '@oclif/core'
import heredoc from 'tsheredoc'
import {getAddon} from '../../../lib/pg/fetcher'
import pgHost from '../../../lib/pg/host'
import {legacyEssentialPlan, databaseNameFromUrl, essentialNumPlan, formatResponseWithCommands} from '../../../lib/pg/util'
import {PgDatabase, PgUpgradeError, PgUpgradeResponse} from '../../../lib/pg/types'
import * as Heroku from '@heroku-cli/schema'
import confirmCommand from '../../../lib/confirmCommand'
import {nls} from '../../../nls'

export default class Upgrade extends Command {
static topic = 'pg';
static description = heredoc(`
On Essential-tier databases, this command upgrades the database's Postgres version.

On Standard-tier and higher leader databases, this command runs a previously scheduled Postgres version upgrade. You must run ${color.cmd('pg:upgrade:prepare')} before this command to schedule a version upgrade.

On follower databases, this command unfollows the leader database before upgrading the follower's Postgres version.
`)

static examples = [
heredoc`
# Upgrade an Essential-tier database to a specific version
$ heroku pg:upgrade:run postgresql-curved-12345 --version 14 --app myapp
`,
heredoc`
# Upgrade a Standard-tier follower database to the latest supported version
$ heroku pg:upgrade:run HEROKU_POSTGRESQL_BLUE_URL --app myapp
`,
heredoc`
# Run a previously scheduled upgrade on a Standard-tier leader database
$ heroku pg:upgrade:run DATABASE_URL --app myapp
`,
]

static flags = {
confirm: flags.string({char: 'c'}),
version: flags.string({char: 'v', description: 'Postgres version to upgrade to'}),
app: flags.app({required: true}),
remote: flags.remote({char: 'r'}),
}

static args = {
database: Args.string({description: `${nls('pg:database:arg:description')} ${nls('pg:database:arg:description:default:suffix')}`}),
}

public async run(): Promise<void> {
const {flags, args} = await this.parse(Upgrade)
const {app, version, confirm} = flags
const {database} = args

const db = await getAddon(this.heroku, app, database)
if (legacyEssentialPlan(db))
ux.error(`You can only use ${color.cmd('pg:upgrade:*')} commands on Essential-* and higher plans.`)

const versionPhrase = version ? heredoc(`Postgres version ${version}`) : heredoc('the latest supported Postgres version')
const {body: replica} = await this.heroku.get<PgDatabase>(`/client/v11/databases/${db.id}`, {hostname: pgHost()})

if (essentialNumPlan(db)) {
await confirmCommand(app, confirm, heredoc(`
Destructive action
You're upgrading ${color.addon(db.name)} to ${versionPhrase}.

You can't undo this action.
`))
} else if (replica.following) {
const {body: configVars} = await this.heroku.get<Heroku.ConfigVars>(`/apps/${app}/config-vars`)
const origin = databaseNameFromUrl(replica.following, configVars)

await confirmCommand(app, confirm, heredoc(`
Destructive action
You're upgrading ${color.addon(db.name)} to ${versionPhrase}. The database will stop following ${origin} and become writable.

You can't undo this action.
`))
} else {
await confirmCommand(app, confirm, heredoc(`
Destructive action
You're upgrading the Postgres version on ${color.addon(db.name)}. This action also upgrades any followers on the database.

You can't undo this action.
`))
}

try {
const data = {version}
ux.action.start(`Starting upgrade on ${color.addon(db.name)}`)
const response = await this.heroku.post<PgUpgradeResponse>(`/client/v11/databases/${db.id}/upgrade/run`, {hostname: pgHost(), body: data})
ux.action.stop(heredoc(`done\n${formatResponseWithCommands(response.body.message)}`))
} catch (error) {
if (error instanceof Error && 'body' in error) {
const response = error as PgUpgradeError
ux.error(heredoc(`${formatResponseWithCommands(response.body.message)}\n\nError ID: ${response.body.id}`))
} else {
throw error
}
}
}
}
1 change: 0 additions & 1 deletion packages/cli/src/lib/pg/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ export type PgUpgradeResponse = {
}

export type PgUpgradeError = {
status: number,
body: {
id: string,
message: string,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/test/acceptance/commands-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ pg:settings:log-min-duration-statement The duration of each completed st
pg:settings:log-statement log_statement controls which SQL statements are logged.
pg:settings:track-functions track_functions controls tracking of function call counts and time used. Default is none.
pg:unfollow stop a replica from following and make it a writeable database
pg:upgrade Were deprecating this command. To upgrade your database's Postgres version, use the new pg:upgrade:* subcommands. See https://devcenter.heroku.com/changelog-items/3179.
pg:upgrade We're deprecating this command. To upgrade your database's Postgres version, use the new pg:upgrade:* subcommands. See https://devcenter.heroku.com/changelog-items/3179.
pg:vacuum-stats show dead rows and whether an automatic vacuum is expected to be triggered
pg:wait blocks until database is available
pipelines list pipelines you have access to
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/test/unit/commands/pg/upgrade/index.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ describe('pg:upgrade', function () {
.reply(200, {message: 'Upgrading'})

const message = heredoc(`
Were deprecating this command. To upgrade your database's Postgres version, use the new pg:upgrade:* subcommands. See https://devcenter.heroku.com/changelog-items/3179.
We're deprecating this command. To upgrade your database's Postgres version, use the new pg:upgrade:* subcommands. See https://devcenter.heroku.com/changelog-items/3179.

Destructive action
You're upgrading ${addon.name} to Postgres version 15. The database will stop following DATABASE and become writable.

This cannot be undone.
You can't undo this action.
`)

await runCommand(Cmd, [
Expand Down Expand Up @@ -126,12 +126,12 @@ describe('pg:upgrade', function () {
.reply(200, {message: 'Upgrading'})

const message = heredoc(`
Were deprecating this command. To upgrade your database's Postgres version, use the new pg:upgrade:* subcommands. See https://devcenter.heroku.com/changelog-items/3179.
We're deprecating this command. To upgrade your database's Postgres version, use the new pg:upgrade:* subcommands. See https://devcenter.heroku.com/changelog-items/3179.

Destructive action
You're upgrading ${addon.name} to the latest supported Postgres version. The database will stop following DATABASE and become writable.

This cannot be undone.
You can't undo this action.
`)

await runCommand(Cmd, [
Expand Down Expand Up @@ -167,12 +167,12 @@ describe('pg:upgrade', function () {
.reply(200, {message: 'Upgrading'})

const message = heredoc(`
Were deprecating this command. To upgrade your database's Postgres version, use the new pg:upgrade:* subcommands. See https://devcenter.heroku.com/changelog-items/3179.
We're deprecating this command. To upgrade your database's Postgres version, use the new pg:upgrade:* subcommands. See https://devcenter.heroku.com/changelog-items/3179.

Destructive action
You're upgrading ${essentialAddon.name} to the latest supported Postgres version.

This cannot be undone.
You can't undo this action.
`)

await runCommand(Cmd, [
Expand Down
Loading
Loading