pg_upgrade
Upgrade PostgreSQL database versions safely for Heroku apps. Plan migration paths, verify compatibility, and execute controlled upgrades with confirmation protection to ensure a secure transition.
Instructions
Upgrade PostgreSQL database version. Use this tool when you need to: 1) Migrate to a newer PostgreSQL version, 2) Plan version upgrade paths, 3) Execute controlled version migrations, 4) Verify upgrade compatibility. The tool manages safe database version upgrades with confirmation protection.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| app | Yes | The name of the Heroku app whose database to upgrade. | |
| confirm | No | Confirmation string required for this potentially destructive operation. | |
| database | No | Config var containing the connection string, unique name, ID, or alias of the database. To access another app's database, prepend the app name to the config var or alias with `APP_NAME::`. If omitted, DATABASE_URL is used. | |
| version | No | PostgreSQL version to upgrade to |
Implementation Reference
- src/tools/data.ts:397-409 (handler)The async handler function for the 'pg_upgrade' tool. It builds a CommandBuilder for 'pg:upgrade', adds flags for app, version, confirm, positional database, executes via herokuRepl, and returns handled CLI output.async (options: PgUpgradeOptions): Promise<McpToolResponse> => { const command = new CommandBuilder(TOOL_COMMAND_MAP.PG_UPGRADE) .addFlags({ app: options.app, version: options.version, confirm: options.confirm }) .addPositionalArguments({ database: options.database }) .build(); const output = await herokuRepl.executeCommand(command); return handleCliOutput(output); }
- src/tools/data.ts:138-148 (schema)Zod schema pgUpgradeOptionsSchema defining input parameters for the pg_upgrade tool (app, optional version, confirm, database) and the inferred PgUpgradeOptions type.export const pgUpgradeOptionsSchema = z.object({ app: z.string().describe('Target app name'), version: z.string().optional().describe('PostgreSQL version target'), confirm: z.string().optional().describe('Confirmation for destructive operation'), database: z .string() .optional() .describe('Database identifier. Format: APP_NAME::DB for other apps. Default: DATABASE_URL') }); export type PgUpgradeOptions = z.infer<typeof pgUpgradeOptionsSchema>;
- src/tools/data.ts:392-411 (registration)The registerPgUpgradeTool function that registers the 'pg_upgrade' tool on the MCP server with name, description, input schema shape, and handler function.export const registerPgUpgradeTool = (server: McpServer, herokuRepl: HerokuREPL): void => { server.tool( 'pg_upgrade', 'Upgrade PostgreSQL: version migration, compatibility, safety', pgUpgradeOptionsSchema.shape, async (options: PgUpgradeOptions): Promise<McpToolResponse> => { const command = new CommandBuilder(TOOL_COMMAND_MAP.PG_UPGRADE) .addFlags({ app: options.app, version: options.version, confirm: options.confirm }) .addPositionalArguments({ database: options.database }) .build(); const output = await herokuRepl.executeCommand(command); return handleCliOutput(output); } ); };
- src/utils/tool-commands.ts:40-40 (helper)TOOL_COMMAND_MAP.PG_UPGRADE constant providing the Heroku CLI command string 'pg:upgrade' used by the handler's CommandBuilder.PG_UPGRADE: 'pg:upgrade',
- src/index.ts:85-85 (registration)Call to registerPgUpgradeTool during MCP server initialization to add the pg_upgrade tool.data.registerPgUpgradeTool(server, herokuRepl);