apply_migration
Apply a specific migration file to update or modify the schema structure in PocketBase databases. Requires the migration file name to execute.
Instructions
Apply a specific migration file.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| migrationFile | Yes | Name of the migration file to apply. |
Implementation Reference
- src/tools/migration-tools.ts:268-282 (handler)The handler function for the 'apply_migration' tool. Validates input, calls the underlying applyMigration function, and returns the result.async function handleApplyMigration(args: ApplyMigrationArgs, pb: PocketBase): Promise<ToolResult> { if (!args.migrationFile) { throw invalidParamsError("Missing required argument: migrationFile"); } try { // Use the current migrations directory const result = await applyMigration(args.migrationFile, pb); return { content: [{ type: 'text', text: result }], }; } catch (error: any) { throw new Error(`Failed to apply migration: ${error.message}`); } }
- src/tools/migration-tools.ts:38-40 (schema)TypeScript interface defining the input arguments for the apply_migration tool.interface ApplyMigrationArgs { migrationFile: string; }
- src/tools/migration-tools.ts:123-132 (registration)Tool registration object in migrationToolInfo array, including name, description, and JSON input schema.name: 'apply_migration', description: 'Apply a specific migration file.', inputSchema: { type: 'object', properties: { migrationFile: { type: 'string', description: 'Name of the migration file to apply.' }, }, required: ['migrationFile'], }, },
- src/tools/index.ts:15-25 (registration)Central tool registration function that includes migration tools via listMigrationTools().export function registerTools(): { tools: ToolInfo[] } { // Use ToolInfo[] const tools: ToolInfo[] = [ // Use ToolInfo[] ...listRecordTools(), ...listCollectionTools(), ...listFileTools(), ...listMigrationTools(), // Uncommented ...listLogTools(), // Add log tools ...listCronTools(), // Add cron tools ]; return { tools }; }
- src/migrations/execution.ts:55-77 (helper)Core helper function that loads the migration file, executes its 'up' migration, and handles errors.export async function applyMigration( migrationFile: string, pb: PocketBase, migrationsDir: string ): Promise<string> { try { const migrationPath = path.join(migrationsDir, migrationFile); // Check if file exists await fs.access(migrationPath, fs.constants.R_OK); // Load the migration const migration = await loadMigrationFile(migrationPath); // Execute the up function await migration.up(pb); return `Successfully applied migration: ${migrationFile}`; } catch (error: any) { console.error(`Error applying migration ${migrationFile}:`, error); throw new Error(`Failed to apply migration: ${error.message}`); } }