create_migration
Generate a timestamped, empty migration file in PocketBase to manage database schema changes with a descriptive filename for tracking purposes.
Instructions
Create a new, empty PocketBase migration file with a timestamped name.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| description | Yes | A brief description for the migration filename (e.g., "add_user_email_index"). |
Implementation Reference
- src/tools/migration-tools.ts:211-219 (handler)Main handler for 'create_migration' tool: validates input, calls createNewMigration, and returns success message with file path.async function handleCreateMigration(args: CreateMigrationArgs): Promise<ToolResult> { if (!args.description) { throw invalidParamsError("Missing required argument: description"); } const filePath = await createNewMigration(args.description); return { content: [{ type: 'text', text: `Created new migration file: ${filePath}` }], }; }
- src/tools/migration-tools.ts:67-77 (schema)ToolInfo definition including name, description, and inputSchema for 'create_migration' used for MCP tool registration.{ name: 'create_migration', description: 'Create a new, empty PocketBase migration file with a timestamped name.', inputSchema: { type: 'object', properties: { description: { type: 'string', description: 'A brief description for the migration filename (e.g., "add_user_email_index").' }, }, required: ['description'], }, },
- src/tools/index.ts:51-52 (registration)Routing logic in handleToolCall that dispatches 'create_migration' calls to the migration tools handler.} else if (name === 'create_migration' || name === 'create_collection_migration' || name === 'add_field_migration' || name === 'list_migrations') { return handleMigrationToolCall(name, toolArgs, pb);
- src/tools/index.ts:20-20 (registration)Includes migration tools (including 'create_migration') in the overall tool list via listMigrationTools() in registerTools()....listMigrationTools(), // Uncommented
- src/migrations/index.ts:25-41 (helper)Core helper function createNewMigration that generates filename and content, called by the tool handler.export async function createNewMigration(description: string): Promise<string> { const timestamp = helpers.generateTimestamp(); // Sanitize description for filename const sanitizedDescription = description .toLowerCase() .replace(/[^a-z0-9_]+/g, '_') // Replace non-alphanumeric/underscore with underscore .replace(/^_+|_+$/g, ''); // Trim leading/trailing underscores if (!sanitizedDescription) { throw new Error("Migration description cannot be empty or only contain invalid characters."); } const filename = `${timestamp}_${sanitizedDescription}.js`; const content = helpers.generateMigrationTemplate(); // Generate basic template return helpers.createMigrationFile(filename, content); }