Skip to main content
Glama

create_collection_migration

Generate a migration file to define and create a new PocketBase collection, including its schema, fields, and rules, for structured database management.

Instructions

Create a migration file specifically for creating a new PocketBase collection.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
collectionDefinitionYesThe full schema definition for the new collection (including name, id, fields, rules, etc.).
descriptionNoOptional description override for the filename.

Implementation Reference

  • The handler function for the 'create_collection_migration' tool. Validates the input arguments and calls the underlying createCollectionMigration helper to generate the migration file.
    async function handleCreateCollectionMigration(args: CreateCollectionMigrationArgs): Promise<ToolResult> { if (!args.collectionDefinition) { throw invalidParamsError("Missing required argument: collectionDefinition"); } if (!args.collectionDefinition.name || !args.collectionDefinition.id) { throw invalidParamsError("collectionDefinition must include 'name' and 'id' properties."); } const filePath = await createCollectionMigration(args.collectionDefinition, args.description); return { content: [{ type: 'text', text: `Created collection migration file: ${filePath}` }], }; }
  • The tool registration object containing the schema (inputSchema) for validating inputs to the 'create_collection_migration' tool.
    { name: 'create_collection_migration', description: 'Create a migration file specifically for creating a new PocketBase collection.', inputSchema: { type: 'object', properties: { description: { type: 'string', description: 'Optional description override for the filename.' }, collectionDefinition: { type: 'object', description: 'The full schema definition for the new collection (including name, id, fields, rules, etc.).', additionalProperties: true, // Allow any properties for the schema required: ['name', 'id'] // Enforce required schema properties }, }, required: ['collectionDefinition'], }, },
  • The core helper function that generates and writes the migration file for creating a new collection based on the provided definition.
    export async function createCollectionMigration(collectionDefinition: Record<string, any>, description?: string): Promise<string> { const timestamp = helpers.generateTimestamp(); const collectionName = collectionDefinition.name; if (!collectionName || typeof collectionName !== 'string') { throw new Error("Collection definition must have a 'name' property."); } const collectionId = collectionDefinition.id; if (!collectionId || typeof collectionId !== 'string') { throw new Error("Collection definition must have an 'id' property."); } const desc = description || `create_${collectionName}_collection`; const sanitizedDescription = desc .toLowerCase() .replace(/[^a-z0-9_]+/g, '_') .replace(/^_+|_+$/g, ''); const filename = `${timestamp}_${sanitizedDescription}.js`; // Generate specific up/down queries const upQuery = helpers.generateCreateCollectionQuery(collectionDefinition); const downQuery = helpers.generateDeleteCollectionQuery(collectionId); // Use ID for down query const content = helpers.generateMigrationTemplate(upQuery, downQuery); return helpers.createMigrationFile(filename, content); }
  • The dispatch logic in the main tool handler that routes 'create_collection_migration' calls to the migration tool handler.
    } else if (name === 'create_migration' || name === 'create_collection_migration' || name === 'add_field_migration' || name === 'list_migrations') { return handleMigrationToolCall(name, toolArgs, pb);
  • The main tool registration function that includes migration tools (via listMigrationTools()), making 'create_collection_migration' available.
    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 }; }

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