-
Notifications
You must be signed in to change notification settings - Fork 12
Implement file uploads #722
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
Open
noahlevi
wants to merge
10
commits into
launch/v1.0.0
Choose a base branch
from
feature/file-uploud
base: launch/v1.0.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3c7a82d
feat: migration v0.15.0 with file/file_upload tables, file_type enum,…
noahlevi 3764a6e
feat: adding aws funcionality mapping
noahlevi 00f6aae
fix: minor
noahlevi c76e9fc
chore: moving file structs and functions from graphql/model.rs
noahlevi 60a3a48
test: testing upload with .pdf files
noahlevi 21c1446
Merge branch 'launch/v1.0.0' into feature/file-uploud
noahlevi 1dc2bfd
fix: format, lint errors fixing
noahlevi 78023e4
fix: remove unused code and comments
noahlevi 00a5821
fix: minor
noahlevi 1741c5d
fix: correct quering of biographies
noahlevi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
This file contains hidden or 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 file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| -- Drop file_upload table | ||
| DROP TABLE IF EXISTS file_upload; | ||
|
|
||
| -- Drop file table | ||
| DROP TABLE IF EXISTS file; | ||
|
|
||
| -- Drop file_type enum | ||
| DROP TYPE IF EXISTS file_type; | ||
|
|
||
| -- Remove storage configuration columns from imprint table | ||
| ALTER TABLE imprint | ||
| DROP CONSTRAINT IF EXISTS imprint_storage_cfg_all_or_none, | ||
| DROP COLUMN IF EXISTS s3_bucket, | ||
| DROP COLUMN IF EXISTS s3_region, | ||
| DROP COLUMN IF EXISTS cdn_domain, | ||
| DROP COLUMN IF EXISTS cloudfront_dist_id; | ||
|
|
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| -- Add storage configuration columns to imprint table | ||
| ALTER TABLE imprint | ||
| ADD COLUMN s3_bucket TEXT, | ||
| ADD COLUMN s3_region TEXT, | ||
| ADD COLUMN cdn_domain TEXT, | ||
| ADD COLUMN cloudfront_dist_id TEXT; | ||
|
|
||
| -- All or nothing constraint: either all storage config fields are NULL or all are NOT NULL | ||
| ALTER TABLE imprint | ||
| ADD CONSTRAINT imprint_storage_cfg_all_or_none | ||
| CHECK ( | ||
| ( | ||
| s3_bucket IS NULL AND | ||
| s3_region IS NULL AND | ||
| cdn_domain IS NULL AND | ||
| cloudfront_dist_id IS NULL | ||
| ) | ||
| OR | ||
| ( | ||
| s3_bucket IS NOT NULL AND | ||
| s3_region IS NOT NULL AND | ||
| cdn_domain IS NOT NULL AND | ||
| cloudfront_dist_id IS NOT NULL | ||
| ) | ||
| ); | ||
|
|
||
| -- Create file_type enum | ||
| CREATE TYPE file_type AS ENUM ('publication', 'frontcover'); | ||
|
|
||
| -- Create file table (final stored files) | ||
| CREATE TABLE file ( | ||
| file_id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), | ||
|
|
||
| file_type file_type NOT NULL, -- 'publication' | 'frontcover' | ||
|
|
||
| work_id UUID REFERENCES work (work_id), | ||
| publication_id UUID REFERENCES publication (publication_id), | ||
|
|
||
| object_key TEXT NOT NULL, -- lowercase DOI-based canonical path | ||
| cdn_url TEXT NOT NULL, -- full public URL | ||
|
|
||
| mime_type TEXT NOT NULL, | ||
| bytes BIGINT NOT NULL, | ||
| sha256 TEXT NOT NULL, | ||
|
|
||
| created_at TIMESTAMPTZ NOT NULL DEFAULT now(), | ||
| updated_at TIMESTAMPTZ NOT NULL DEFAULT now() | ||
| ); | ||
|
|
||
| -- Enforce file type constraints | ||
| ALTER TABLE file | ||
| ADD CONSTRAINT file_type_check | ||
| CHECK ( | ||
| (file_type = 'frontcover' AND work_id IS NOT NULL AND publication_id IS NULL) OR | ||
| (file_type = 'publication' AND publication_id IS NOT NULL AND work_id IS NULL) | ||
| ); | ||
|
|
||
| -- One frontcover per work | ||
| CREATE UNIQUE INDEX file_frontcover_work_unique_idx | ||
| ON file (work_id) | ||
| WHERE file_type = 'frontcover'; | ||
|
|
||
| -- One publication file per publication | ||
| CREATE UNIQUE INDEX file_publication_unique_idx | ||
| ON file (publication_id) | ||
| WHERE file_type = 'publication'; | ||
|
|
||
| -- Never reuse the same object key | ||
| CREATE UNIQUE INDEX file_object_key_unique_idx | ||
| ON file (object_key); | ||
|
|
||
| -- Enable automatic updated_at management | ||
| SELECT diesel_manage_updated_at('file'); | ||
|
|
||
| -- Create file_upload table (temporary uploads) | ||
| CREATE TABLE file_upload ( | ||
| file_upload_id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), | ||
|
|
||
| file_type file_type NOT NULL, -- same enum as final file table | ||
|
|
||
| work_id UUID REFERENCES work (work_id), | ||
| publication_id UUID REFERENCES publication (publication_id), | ||
|
|
||
| declared_mime_type TEXT NOT NULL, | ||
| declared_extension TEXT NOT NULL, | ||
| declared_sha256 TEXT NOT NULL, | ||
|
|
||
| created_at TIMESTAMPTZ NOT NULL DEFAULT now(), | ||
| updated_at TIMESTAMPTZ NOT NULL DEFAULT now() | ||
| ); | ||
|
|
||
| -- Enforce file_upload type constraints | ||
| ALTER TABLE file_upload | ||
| ADD CONSTRAINT file_upload_type_check | ||
| CHECK ( | ||
| (file_type = 'frontcover' AND work_id IS NOT NULL AND publication_id IS NULL) OR | ||
| (file_type = 'publication' AND publication_id IS NOT NULL AND work_id IS NULL) | ||
| ); | ||
|
|
||
| -- Indexes for file_upload lookups | ||
| CREATE INDEX file_upload_work_idx | ||
| ON file_upload (work_id) | ||
| WHERE file_type = 'frontcover'; | ||
|
|
||
| CREATE INDEX file_upload_publication_idx | ||
| ON file_upload (publication_id) | ||
| WHERE file_type = 'publication'; | ||
|
|
||
| -- Enable automatic updated_at management | ||
| SELECT diesel_manage_updated_at('file_upload'); | ||
|
|
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this can go