create_collection_migration
Create a PocketBase migration file to add a new collection by specifying its full schema definition, including name, fields, and rules.
Instructions
Create a migration file specifically for creating a new PocketBase collection.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| description | No | Optional description override for the filename. | |
| collectionDefinition | Yes | The full schema definition for the new collection (including name, id, fields, rules, etc.). |
Implementation Reference
- src/tools/migration-tools.ts:221-232 (handler)Tool handler for 'create_collection_migration'. Validates args (requires collectionDefinition with name and id), then delegates to the core createCollectionMigration function and returns a success message.
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}` }], }; } - src/tools/migration-tools.ts:21-24 (schema)TypeScript interface defining the input schema for CreateCollectionMigrationArgs: optional description string and required collectionDefinition Record.
interface CreateCollectionMigrationArgs { description?: string; collectionDefinition: Record<string, any>; } - src/tools/migration-tools.ts:79-93 (schema)Tool registration metadata for 'create_collection_migration', including inputSchema with required collectionDefinition (object with required name, id, additionalProperties true).
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'], }, - src/migrations/index.ts:49-76 (handler)Core logic: creates a migration file for a new collection. Generates timestamp, sanitizes description, builds filename, creates up query (create collection) and down query (delete collection), and writes file via helpers.
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); } - src/tools/index.ts:51-52 (registration)Routes the 'create_collection_migration' tool name to handleMigrationToolCall in the central dispatcher.
} else if (name === 'create_migration' || name === 'create_collection_migration' || name === 'add_field_migration' || name === 'list_migrations') { return handleMigrationToolCall(name, toolArgs, pb);