New schema cheatsheet
This cheatsheet summarises the changes needed to update your database to use the new Keystone database schema, introduced in the Arcade release.
For full instructions please consult the migration guide.
One-to-many (one-sided)
JS
keystone.createList('User', { fields: { name: { type: Text } } });
keystone.createList('Post', {
fields: {
title: { type: Text },
content: { type: Text },
author: { type: Relationship, ref: 'User', many: false },
},
});
Migration strategy
- No changes are required for these relationships.
Many-to-many (one-sided)
JS
keystone.createList('User', { fields: { name: { type: Text } } });
keystone.createList('Post', {
fields: {
title: { type: Text },
content: { type: Text },
authors: { type: Relationship, ref: 'User', many: true },
},
});
Migration Strategy
PostgreSQL
- Rename
Post_authorstoPost_authors_many. - Rename
Post_idtoPost_left_idandUser_idtoUser_right_id.
MongoDB
- Create a collection
post_authors_manieswith fieldsPost_left_idandUser_right_id. - Move the data from
posts.authorsintopost_authors_manies. - Delete
posts.authors.
One-to-many (two-sided)
JS
keystone.createList('User', {
fields: {
name: { type: Text },
posts: { type: Relationship, ref: 'Post.author', many: true },
},
});
keystone.createList('Post', {
fields: {
title: { type: Text },
content: { type: Text },
author: { type: Relationship, ref: 'User.posts', many: false },
},
});
Migration strategy
PostgreSQL
- Drop the
User_poststable.
MongoDB
- Remove
users.posts.
Many-to-many (two-sided)
JS
keystone.createList('User', {
fields: {
name: { type: Text },
posts: { type: Relationship, ref: 'Post.authors', many: true },
},
});
keystone.createList('Post', {
fields: {
title: { type: Text },
content: { type: Text },
authors: { type: Relationship, ref: 'User.posts', many: true },
},
});
Migration strategy
PostgreSQL
- Drop the
Post_authorstable. - Rename
User_poststoUser_posts_Post_authors. - Rename
User_idtoUser_left_idandPost_idtoPost_right_id.
MongoDB
- Create a collection
user_posts_post_authorswith fieldsUser_left_idandPost_right_id. - Move the data from
users.postsintouser_posts_post_authors. - Delete
users.posts. - Delete
posts.authors.
One-to-one (two-sided)
JS
keystone.createList('User', {
fields: {
name: { type: Text },
post: { type: Relationship, ref: 'Post.author', many: false },
},
});
keystone.createList('Post', {
fields: {
title: { type: Text },
content: { type: Text },
author: { type: Relationship, ref: 'User.post', many: false },
},
});
Migration strategy
PostgreSQL
One to one relationships in the before state had a foreign key column on each table.
In the after state, only one of these is stored.
Because of the symmetry of the one-to-one relationship, Keystone makes an arbitrary decision about which column to use.
- Identify the foreign key column which is no longer required, and delete it.
- In our example above we would delete the
Post.authorcolumn.
MongoDB
One to one relationships in the before state had a field in each collection.
In the after state, only one of these is stored.
Because of the symmetry of the one-to-one relationship, Keystone makes an arbitrary decision about which field to use.
- Identify the field which is no longer required, and delete it.
- In our example above we would delete the
post.authorfield.