UNPKG

appwrite-utils-cli

Version:

Appwrite Utility Functions to help with database management, data conversion, data import, migrations, and much more. Meant to be used as a CLI tool, I do not recommend installing this in frontend environments.

208 lines (180 loc) 5.83 kB
# yaml-language-server: $schema=../.yaml_schemas/import-config.schema.json # Posts Import Configuration with Relationships and File Handling source: file: "importData/posts.json" basePath: "RECORDS" type: "json" target: collection: "Posts" type: "create" primaryKey: "post_id" createUsers: false mapping: attributes: # Core Content - oldKey: "post_id" targetKey: "postId" converters: ["anyToString"] validation: - rule: "required" params: ["{postId}"] - oldKey: "title" targetKey: "title" converters: ["anyToString", "stringTrim"] validation: - rule: "required" params: ["{title}"] - rule: "minLength" params: ["{title}", "5"] - rule: "maxLength" params: ["{title}", "200"] - oldKey: "slug" targetKey: "slug" converters: ["anyToString", "stringToLowerCase", "stringTrim"] - oldKey: "content" targetKey: "content" converters: ["anyToString"] validation: - rule: "required" params: ["{content}"] - rule: "minLength" params: ["{content}", "100"] - oldKey: "excerpt" targetKey: "excerpt" converters: ["anyToString", "stringTrim"] validation: - rule: "maxLength" params: ["{excerpt}", "500"] # Author Relationship (handled in relationships section) - oldKey: "author_id" targetKey: "authorId" converters: ["anyToString"] validation: - rule: "required" params: ["{authorId}"] # Category Relationship (handled in relationships section) - oldKey: "category_id" targetKey: "categoryId" converters: ["anyToString"] # Featured Image with URL Download - oldKey: "featured_image_url" targetKey: "featuredImage" fileData: path: "{featured_image_url}" name: "{post_id}_featured" afterImport: - action: "createFileAndUpdateField" params: ["{dbId}", "{collId}", "{docId}", "featuredImage", "{bucketId}", "{filePath}", "{fileName}"] # Gallery Images (multiple files) - oldKey: "gallery_urls" targetKey: "gallery" fileData: path: "{gallery_urls}" name: "{post_id}_gallery_{index}" afterImport: - action: "createFileAndUpdateField" params: ["{dbId}", "{collId}", "{docId}", "gallery", "{bucketId}", "{filePath}", "{fileName}"] # Tags Array - oldKey: "tags" targetKey: "tags" converters: ["anyToStringArray"] # Status and Publishing - oldKey: "status" targetKey: "status" converters: ["anyToString", "stringToLowerCase"] validation: - rule: "required" params: ["{status}"] - oldKey: "published_at" targetKey: "publishedAt" converters: ["anyToDate"] - oldKey: "scheduled_at" targetKey: "scheduledAt" converters: ["anyToDate"] # Engagement Metrics - oldKey: "view_count" targetKey: "viewCount" converters: ["anyToNumber"] validation: - rule: "numeric" params: ["{viewCount}"] - rule: "positive" params: ["{viewCount}"] - oldKey: "like_count" targetKey: "likeCount" converters: ["anyToNumber"] validation: - rule: "numeric" params: ["{likeCount}"] - rule: "positive" params: ["{likeCount}"] - oldKey: "comment_count" targetKey: "commentCount" converters: ["anyToNumber"] validation: - rule: "numeric" params: ["{commentCount}"] - rule: "positive" params: ["{commentCount}"] - oldKey: "share_count" targetKey: "shareCount" converters: ["anyToNumber"] validation: - rule: "numeric" params: ["{shareCount}"] - rule: "positive" params: ["{shareCount}"] # SEO Fields - oldKey: "meta_title" targetKey: "metaTitle" converters: ["anyToString", "stringTrim"] validation: - rule: "maxLength" params: ["{metaTitle}", "60"] - oldKey: "meta_description" targetKey: "metaDescription" converters: ["anyToString", "stringTrim"] validation: - rule: "maxLength" params: ["{metaDescription}", "160"] # Social Image with URL Download - oldKey: "social_image_url" targetKey: "socialImage" fileData: path: "{social_image_url}" name: "{post_id}_social" afterImport: - action: "createFileAndUpdateField" params: ["{dbId}", "{collId}", "{docId}", "socialImage", "{bucketId}", "{filePath}", "{fileName}"] # Reading Time - oldKey: "reading_time" targetKey: "readingTime" converters: ["anyToNumber"] validation: - rule: "numeric" params: ["{readingTime}"] - rule: "positive" params: ["{readingTime}"] # Featured Status - oldKey: "is_featured" targetKey: "isFeatured" converters: ["anyToBoolean"] - oldKey: "is_pinned" targetKey: "isPinned" converters: ["anyToBoolean"] relationships: # Author Relationship - Link to Users collection - sourceField: "author_id" targetField: "userId" targetCollection: "Users" fieldToSet: "authorId" # Category Relationship - Link to Categories collection - sourceField: "category_id" targetField: "categoryId" targetCollection: "Categories" fieldToSet: "categoryId" options: batchSize: 20 skipValidation: false dryRun: false continueOnError: true