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
source:
file: "importData/posts.json"
basePath: "RECORDS"
type: "json"
target:
collection: "Posts"
type: "create"
primaryKey: "post_id"
createUsers: false
mapping:
attributes:
- 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"]
- oldKey: "author_id"
targetKey: "authorId"
converters: ["anyToString"]
validation:
- rule: "required"
params: ["{authorId}"]
- oldKey: "category_id"
targetKey: "categoryId"
converters: ["anyToString"]
- 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}"]
- 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}"]
- oldKey: "tags"
targetKey: "tags"
converters: ["anyToStringArray"]
- 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"]
- 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}"]
- 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"]
- 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}"]
- oldKey: "reading_time"
targetKey: "readingTime"
converters: ["anyToNumber"]
validation:
- rule: "numeric"
params: ["{readingTime}"]
- rule: "positive"
params: ["{readingTime}"]
- oldKey: "is_featured"
targetKey: "isFeatured"
converters: ["anyToBoolean"]
- oldKey: "is_pinned"
targetKey: "isPinned"
converters: ["anyToBoolean"]
relationships:
- sourceField: "author_id"
targetField: "userId"
targetCollection: "Users"
fieldToSet: "authorId"
- sourceField: "category_id"
targetField: "categoryId"
targetCollection: "Categories"
fieldToSet: "categoryId"
options:
batchSize: 20
skipValidation: false
dryRun: false
continueOnError: true