Skip to main content
Glama

add_field_migration

Generate a migration file to add a new field to an existing collection in PocketBase. Specify the collection name or ID and define the field schema for automated integration.

Instructions

Create a migration file for adding a field to an existing collection.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
collectionNameOrIdYesThe name or ID of the collection to update.
descriptionNoOptional description override for the filename.
fieldDefinitionYesThe schema definition for the new field.

Implementation Reference

  • The handler function that executes the 'add_field_migration' tool. Validates input arguments and invokes createAddFieldMigration to generate the migration file.
    async function handleAddFieldMigration(args: AddFieldMigrationArgs): Promise<ToolResult> { if (!args.collectionNameOrId) { throw invalidParamsError("Missing required argument: collectionNameOrId"); } if (!args.fieldDefinition) { throw invalidParamsError("Missing required argument: fieldDefinition"); } if (!args.fieldDefinition.name || !args.fieldDefinition.type) { throw invalidParamsError("fieldDefinition must include 'name' and 'type' properties."); } const filePath = await createAddFieldMigration(args.collectionNameOrId, args.fieldDefinition, args.description); return { content: [{ type: 'text', text: `Created field migration file: ${filePath}` }], }; }
  • The input schema definition for the 'add_field_migration' tool, specifying parameters and validation rules.
    inputSchema: { type: 'object', properties: { collectionNameOrId: { type: 'string', description: 'The name or ID of the collection to update.' }, fieldDefinition: { type: 'object', description: 'The schema definition for the new field.', additionalProperties: true, required: ['name', 'type'] }, description: { type: 'string', description: 'Optional description override for the filename.' }, }, required: ['collectionNameOrId', 'fieldDefinition'], },
  • The tool registration entry in the migrationToolInfo array, defining name, description, and input schema.
    { name: 'add_field_migration', description: 'Create a migration file for adding a field to an existing collection.', inputSchema: { type: 'object', properties: { collectionNameOrId: { type: 'string', description: 'The name or ID of the collection to update.' }, fieldDefinition: { type: 'object', description: 'The schema definition for the new field.', additionalProperties: true, required: ['name', 'type'] }, description: { type: 'string', description: 'Optional description override for the filename.' }, }, required: ['collectionNameOrId', 'fieldDefinition'], }, },
  • Routing logic in the central handleToolCall that directs 'add_field_migration' calls to handleMigrationToolCall.
    } else if (name === 'create_migration' || name === 'create_collection_migration' || name === 'add_field_migration' || name === 'list_migrations') { return handleMigrationToolCall(name, toolArgs, pb);
  • Helper function that generates the actual migration file content and saves it for adding a field to a collection.
    export async function createAddFieldMigration( collectionNameOrId: string, fieldDefinition: Record<string, any>, description?: string ): Promise<string> { const timestamp = helpers.generateTimestamp(); if (!fieldDefinition.name || !fieldDefinition.type) { throw new Error("Field definition must include 'name' and 'type' properties."); } const fieldName = fieldDefinition.name; const desc = description || `update_${collectionNameOrId}_add_${fieldName}`; const sanitizedDescription = desc .toLowerCase() .replace(/[^a-z0-9_]+/g, '_') .replace(/^_+|_+$/g, ''); const filename = `${timestamp}_${sanitizedDescription}.js`; // Generate specific up/down queries const upQuery = helpers.generateAddFieldQuery(collectionNameOrId, fieldDefinition); const downQuery = helpers.generateRemoveFieldQuery(collectionNameOrId, fieldName); const content = helpers.generateMigrationTemplate(upQuery, downQuery); return helpers.createMigrationFile(filename, content); }

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