Skip to main content
Glama

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
NameRequiredDescriptionDefault
migrationFileYesName of the migration file to apply.

Implementation Reference

  • 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}`); } }
  • TypeScript interface defining the input arguments for the apply_migration tool.
    interface ApplyMigrationArgs { migrationFile: string; }
  • 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'], }, },
  • 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 }; }
  • 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}`); } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mabeldata/pocketbase-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server