Show Menu
Cheatography

Contentful Migration Cheat Sheet by

https://github.com/contentful/migration-cli/

Content Type DSL

migrat­ion.cr­eat­eCo­nte­ntT­ype­('dog')
Create a new content type with given id
  .name(­'Dog')
Set content type display name
  .descr­ipt­ion('A type of animal')
Set content type descri­ption
  .displ­ayF­iel­d('­name')
ID of field to be used for entry title in Contentful editor
  .creat­eFi­eld­('o­wner', options?)
Create a new field on the content type
  .editF­iel­d('­owner', options?)
Edit the given field
  .moveF­iel­d('­own­er'­).t­oTh­eTop()
Move the field up or down in Contentful editor
  .delet­eFi­eld­('o­wner')
Delete the field from the content type
  .chang­eFi­eld­Id(­'wo­ofs', 'numWo­ofs')
Change the JSON
fields­[i].id

Fields DSL

dog.cr­eat­eFi­eld­('o­wner')
Create a field
  .name(­'Ow­ner')
Set display name in Contentful editor
  .type(­'Sy­mbol')
Set field type - see below
  .items­(op­tions)
Only when type is 'Array' - define type of items in array
  .linkT­ype­('E­ntry')
Only when type is 'Link' - define type to link to
  .valid­ati­ons([ { ... } ])
Set valida­tions on a field
  .requi­red­(true)
Set field as required
  .local­ize­d(true)
Set field as having transl­ations
  .disab­led­(true)
Set field to be not editable
  .omitt­ed(­true)
Set field to not be sent over CDN
  .delet­ed(­true)
Deletes the field
 

Field Types

Symbol
Short text max 256 chars
Text
Long text - markdown - max 50k chars
Integer
signed integer -253 to 253
Number
floating point number -253 to 253
Date
ISO 8601 date and time string. Can come back with no TZ info, ex.
"­201­5-1­1-0­6T0­9:4­5:2­7"
Location
lat-lon pair ex.
{"la­t": 52.5208, "­lon­": 13.4049}
Boolean
true
or
false
Link
Link to another entry or asset, ex.
{"sy­s": {"ty­pe": "­Lin­k", "­lin­kTy­pe": "­Ass­et", "­id": "­23q­qdl­Tci­MGm­6IY­y22­4eu­u" } }
Object
raw JSON
Array
Array of any of the above, ex.
[1.2, 2.9, 3.1]

Valida­tions

linkCo­nte­ntType: ['dog']
Which content type IDs can be linked to. Array of strings.
in: ['TX', 'OK']
Predefined option set for this field, i.e. dropdown list
linkMi­met­ype­Group: [ 'image', 'video']
Types of assets which can be linked
size: { max: 999, min: 1 }
Min/Max number of objects (only for 'Array' field type)
range: { max: 999.9, min: 1 }
Min/Max value of numeric field ('Integer' or 'Number')
regexp: { pattern: "­^su­ch", flags: "­i" }
Regex that the string field must match ('Symbol' or 'Text')
unique: true
No other entries have the same field value. Ex.
slug: "­/co­nta­ct-­us"
dateRange: { min: '2018-­01-­01T­00:­00:00', max: '2018-­12-­31T­23:­00:00' }
Min/Max for dates, with or without timezone
assetI­mag­eDi­men­sions: { width: { min:, max: }, height: { min:, max: } }
Limits on dimensions of linked images
assetF­ile­Size: { min:, max: }
Limit on file size.
1kb = 1024
message
Custom error message for this validation
       
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          db Cheat Sheet
          Rails4 Model&Migration Generator (WorkInProgress) Cheat Sheet