This skill should be used when the user asks to "add fields to PocketBase collection", "modify PocketBase schema", "add new collection fields", "update PocketBase collection", "PocketBase JavaScript SDK API", "programmatically add PocketBase fields", or mentions modifying PocketBase collection schemas via API. Provides comprehensive guidance for adding fields to existing PocketBase collections using the JavaScript SDK API.
Programmatically add fields to existing PocketBase collections using the JavaScript SDK API. Use when users request schema modifications via API, automated migrations, or deployment scripts instead of Admin UI.
/plugin marketplace add Whamp/marketplace/plugin install pocketbase@whamp-claude-toolsThis skill inherits all available tools. When active, it can use any tool Claude has access to.
examples/basic-field-addition.jsexamples/batch-schema-update.jsexamples/migration-script.jsreferences/advanced-patterns.mdreferences/field-types.mdscripts/field-conflict-check.jsscripts/validate-schema.jsThis skill provides comprehensive guidance for programmatically adding fields to existing PocketBase collections using the JavaScript SDK API. It enables developers to modify collection schemas without using the Admin UI, making it ideal for automated migrations, deployment scripts, and programmatic database schema updates.
Use this skill when you need to:
Install the PocketBase SDK if not already available:
npm install pocketbase
import PocketBase from 'pocketbase';
const pb = new PocketBase('http://127.0.0.1:8090');
Schema modifications require admin privileges. Authenticate using one of these methods:
// Method 1: Admin credentials
await pb.admins.authWithPassword('admin@example.com', 'your-admin-password');
// Method 2: Existing admin token
pb.authStore.save('your-admin-token');
Retrieve the existing collection to understand current schema:
async function getCollectionSchema(collectionNameOrId) {
const collection = await pb.collections.getOne(collectionNameOrId);
return collection;
}
Create field definitions following PocketBase field schema format:
const newFields = [
{
name: 'bio',
type: 'text',
required: false,
options: {
max: 1000
}
},
{
name: 'avatar',
type: 'file',
required: false,
options: {
maxSelect: 1,
maxSize: 5242880, // 5MB
mimeTypes: ['image/jpeg', 'image/png', 'image/webp']
}
}
];
Merge new fields with existing schema and update collection:
async function addFieldsToCollection(collectionId, newFields) {
const collection = await pb.collections.getOne(collectionId);
// Add new fields to existing schema
const updatedSchema = [...collection.schema, ...newFields];
// Update collection
const updatedCollection = await pb.collections.update(collectionId, {
name: collection.name,
schema: updatedSchema
});
return updatedCollection;
}
Confirm the schema was updated successfully:
async function verifySchemaChanges(collectionId, expectedFields) {
const collection = await pb.collections.getOne(collectionId);
const fieldNames = collection.schema.map(field => field.name);
return expectedFields.every(field => fieldNames.includes(field));
}
import PocketBase from 'pocketbase';
async function addFieldsToUsersCollection() {
const pb = new PocketBase('http://127.0.0.1:8090');
try {
// Authenticate as admin
await pb.admins.authWithPassword('admin@example.com', 'your-admin-password');
// Get current users collection
const usersCollection = await pb.collections.getOne('users');
// Define new fields
const newFields = [
{
name: 'bio',
type: 'text',
required: false,
options: {
max: 1000
}
},
{
name: 'is_active',
type: 'bool',
required: false,
default: true
},
{
name: 'date_of_birth',
type: 'date',
required: false
}
];
// Add fields to schema
const updatedSchema = [...usersCollection.schema, ...newFields];
// Update collection
const updatedCollection = await pb.collections.update(usersCollection.id, {
name: usersCollection.name,
schema: updatedSchema
});
console.log('Fields added successfully!');
return updatedCollection;
} catch (error) {
console.error('Error adding fields:', error);
throw error;
} finally {
pb.authStore.clear();
}
}
Common field configurations for different data types:
{
name: 'full_name',
type: 'text',
required: true,
options: {
min: 1,
max: 100
}
}
{
name: 'secondary_email',
type: 'email',
required: false
}
{
name: 'age',
type: 'number',
required: false,
options: {
min: 0,
max: 150
}
}
{
name: 'status',
type: 'select',
required: true,
options: {
values: ['active', 'inactive', 'pending']
}
}
{
name: 'team',
type: 'relation',
required: false,
options: {
collectionId: 'teams_collection_id',
maxSelect: 1
}
}
Check for conflicts with existing fields:
function validateFieldNames(newFields, existingSchema) {
const existingNames = existingSchema.map(field => field.name);
const conflicts = newFields.filter(field => existingNames.includes(field.name));
if (conflicts.length > 0) {
throw new Error(`Field name conflicts: ${conflicts.map(f => f.name).join(', ')}`);
}
}
Backup and restore schema on failure:
async function safeFieldAddition(collectionId, newFields) {
const originalCollection = await pb.collections.getOne(collectionId);
try {
await pb.admins.authWithPassword('admin@example.com', 'password');
// Validate no conflicts
validateFieldNames(newFields, originalCollection.schema);
// Add fields
const updatedSchema = [...originalCollection.schema, ...newFields];
await pb.collections.update(collectionId, {
name: originalCollection.name,
schema: updatedSchema
});
} catch (error) {
// Restore original schema on failure
await pb.collections.update(collectionId, {
name: originalCollection.name,
schema: originalCollection.schema
});
throw error;
}
}
Always clean up authentication state:
try {
// Your schema modification logic
} catch (error) {
console.error('Schema modification failed:', error);
throw error;
} finally {
pb.authStore.clear();
}
references/field-types.md - Complete field type reference with all optionsreferences/advanced-patterns.md - Advanced schema modification patternsreferences/error-handling.md - Comprehensive error handling strategiesexamples/basic-field-addition.js - Simple field addition exampleexamples/batch-schema-update.js - Multiple fields and collectionsexamples/migration-script.js - Production migration script templatescripts/validate-schema.js - Schema validation utilityscripts/backup-restore.js - Schema backup and restore helperscripts/field-conflict-check.js - Field name conflict detectionThis approach provides complete programmatic control over PocketBase collection schemas, enabling automated migrations and deployment workflows.
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.