Skip to content
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

blobs: prevent NULL contentType in db #1355

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

alxndrsn
Copy link
Contributor

@alxndrsn alxndrsn commented Jan 13, 2025

Set blob."contentType" values to application/octet-stream if no mime type is supplied on upload.

Related: #1351

What has been done to verify that this works as intended?

CI.

Why is this the best possible solution? Were any other approaches considered?

Discussion on #1351.

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

This will change Content-Type headers for files uploaded without one from the string null to the string application/octet-stream.

Does this change require updates to the API documentation? If so, please update docs/api.yaml as part of this PR.

Yes.

Before submitting this PR, please make sure you have:

  • run make test and confirmed all checks still pass OR confirm CircleCI build passes
  • verified that any code from external sources are properly credited in comments or that everything is internally sourced

alxndrsn added 2 commits January 13, 2025 06:20
Set blob."contentType" values to application/octet-stream if no mime type is supplied on upload.

Related: getodk#1351
@alxndrsn alxndrsn marked this pull request as draft January 13, 2025 06:26
@alxndrsn alxndrsn marked this pull request as ready for review January 13, 2025 07:27
@alxndrsn alxndrsn requested review from ktuite and lognaturel January 13, 2025 07:50
@alxndrsn alxndrsn changed the title blobs: prevent default contentType column blobs: set default contentType value in db Jan 13, 2025
@alxndrsn alxndrsn changed the title blobs: set default contentType value in db blobs: set default contentType in db Jan 13, 2025
@alxndrsn alxndrsn changed the title blobs: set default contentType in db blobs: prevent NULL contentType in db Jan 13, 2025
Comment on lines +10 to +14
const up = (db) => db.raw(`
ALTER TABLE blobs
ALTER COLUMN "contentType" SET NOT NULL,
ALTER COLUMN "contentType" SET DEFAULT 'application/octet-stream'
`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I run this (with null content type values in my DB) I get an error

migration file "20250113-01-disable-nullable-blob-content-types.js" failed
migration failed with error:
  ALTER TABLE blobs
    ALTER COLUMN "contentType" SET NOT NULL,
    ALTER COLUMN "contentType" SET DEFAULT 'application/octet-stream'
 - column "contentType" of relation "blobs" contains null values

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants