apply_all_migrations
Apply all pending database migrations by providing an array of already applied migration filenames to determine which migrations remain to be executed.
Instructions
Apply all pending migrations.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "apply_all_migrations"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| appliedMigrations | No | Array of already applied migration filenames. |
Implementation Reference
- src/tools/migration-tools.ts:299-316 (handler)The tool handler function for 'apply_all_migrations'. It extracts appliedMigrations from args, calls the core applyAllMigrations function, and returns a formatted result.
async function handleApplyAllMigrations(args: ApplyAllMigrationsArgs, pb: PocketBase): Promise<ToolResult> { try { const appliedMigrations = args.appliedMigrations || []; const result = await applyAllMigrations(pb, appliedMigrations); if (result.length === 0) { return { content: [{ type: 'text', text: 'No new migrations to apply.' }], }; } return { content: [{ type: 'text', text: `Applied migrations:\n${result.join('\n')}` }], }; } catch (error: any) { throw new Error(`Failed to apply migrations: ${error.message}`); } } - src/migrations/index.ts:169-179 (handler)The intermediate handler that resolves the migrations directory and delegates to the execution layer.
export async function applyAllMigrations( pb: PocketBase, appliedMigrations: string[] = [], customPath?: string ): Promise<string[]> { // If customPath is provided, set the migrations directory const migrationsDir = customPath ? helpers.setMigrationsDirectory(customPath) : helpers.setMigrationsDirectory(); // Use current directory return execution.applyAllMigrations(pb, migrationsDir, appliedMigrations); } - src/migrations/execution.ts:117-148 (handler)The core execution logic: lists all migration files, filters out already-applied ones, and applies each pending migration sequentially.
export async function applyAllMigrations( pb: PocketBase, migrationsDir: string, appliedMigrations: string[] = [] ): Promise<string[]> { try { // Get all migration files const allMigrations = await listMigrationFiles(); // Filter out already applied migrations const pendingMigrations = allMigrations.filter( migration => !appliedMigrations.includes(migration) ); if (pendingMigrations.length === 0) { return []; } const newlyApplied: string[] = []; // Apply each pending migration for (const migration of pendingMigrations) { await applyMigration(migration, pb, migrationsDir); newlyApplied.push(migration); } return newlyApplied; } catch (error: any) { console.error('Error applying all migrations:', error); throw new Error(`Failed to apply all migrations: ${error.message}`); } } - src/tools/migration-tools.ts:46-48 (schema)TypeScript interface for the apply_all_migrations arguments, with an optional appliedMigrations array of strings.
interface ApplyAllMigrationsArgs { appliedMigrations?: string[]; } - src/tools/migration-tools.ts:144-157 (registration)Tool registration metadata: name 'apply_all_migrations', description 'Apply all pending migrations.', and input schema with optional appliedMigrations array.
{ name: 'apply_all_migrations', description: 'Apply all pending migrations.', inputSchema: { type: 'object', properties: { appliedMigrations: { type: 'array', items: { type: 'string' }, description: 'Array of already applied migration filenames.' }, }, }, },