-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewrite of Image and Files (breaking) #7070
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as outdated.
This comment was marked as outdated.
dcousens
reviewed
Dec 14, 2021
dcousens
reviewed
Feb 3, 2022
dcousens
reviewed
Feb 3, 2022
borisno2
reviewed
May 24, 2022
Co-authored-by: Josh Calder <josh@opensaas.com.au>
Co-authored-by: Daniel Cousens <413395+dcousens@users.noreply.github.com>
emmatown
approved these changes
May 26, 2022
Merged
Merged
looks like this is not released yet... documentation is updated but @keystonejs/core - not |
dcousens
changed the title
Rewrite of Image and Files
Rewrite of Image and Files (breaking)
Jun 9, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request replaces
image
andfiles
configuration options in Keystone's configuration, and replaces them with a newstorage
configuration object.How to upgrade
Previously, your images and files were managed in your root Keystone configuration, under the fields
.images
and.files
respectively.The underlying storage mechanism was denominated through an
upload
field on each respectively, and you had no easy way to modify this behaviour for different fields.It probably looked something like this
As of this pull request, there is now a unified
.storage
configuration object that can contain multiple different storage providers, which you can optionally share or differentiate between for different fields as desired.A canonical example for storing some images on the local filesystem might look something like the following:
A canonical example for storing some images on an S3 compatible storage provider might look something like the following:
Goodbye refs
The previous implementation of refs were useful for moving images between different lists using the admin interface, allowing a user to refer to same image or file without copying that duplicating that image or file at the storage layer.
Unfortunately, this creates a precarious and imperformant situation when you want or need to delete these images or file; you then need to undertake a form of ref-counting across your different lists in a custom hook to ensure you won't 404 the the underlying image or file.
This complexity didn't really pay off for the benefits it provided, when compared with typical Keystone relationships; and in fact the inability to use GraphQL to introspect these references was inhibitive.
The end result is images or files are left to orphan and/or duplicate themselves until some external reason results in the manual database and storage layer interventions.
With refs removed, the new recommendation for sharing images between lists and fields is an approach you may already be familiar with: Keystone Relationships.
A canonical examle for sharing an image between multiple lists might look something like the following:
Using Keystone relationships allows you to mirror the previous functionality while supporting the needs and features required when scaling up.
What if I can't?
If you can't migrate your schema to use Keystone relationships, but you still want to update your Keystone instance to the new
storage
configuration, you can usepreserve: true
to ensure that files - that are replaced or deleted from the database - are not deleted from the underlying storage layer.However, similar to the previous behaviour prior to this pull request, this will result in images and files becoming orphans within the relevant filesystems as they are removed from the database.
Other changes
Local images no longer need a baseUrl
If you were previously using
baseUrl
for yourupload: 'local'
, the configuration approach has changed toserverRoute.path
.For example