-
Notifications
You must be signed in to change notification settings - Fork 928
fix: allow regular users to push files #4500
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
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
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
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,41 @@ | ||
BEGIN; | ||
|
||
-- Add back the storage_source column. This must be nullable temporarily. | ||
ALTER TABLE provisioner_jobs ADD COLUMN storage_source text; | ||
|
||
-- Set the storage_source to the hash of the files.id reference. | ||
UPDATE | ||
provisioner_jobs | ||
SET | ||
storage_source=files.hash | ||
FROM | ||
files | ||
WHERE | ||
provisioner_jobs.file_id = files.id; | ||
|
||
-- Now that we've populated storage_source drop the file_id column. | ||
ALTER TABLE provisioner_jobs DROP COLUMN file_id; | ||
-- We can set the storage_source column as NOT NULL now. | ||
ALTER TABLE provisioner_jobs ALTER COLUMN storage_source SET NOT NULL; | ||
|
||
-- Delete all the duplicate rows where hashes collide. | ||
-- We filter on 'id' to ensure only 1 unique row. | ||
DELETE FROM | ||
files a | ||
USING | ||
files b | ||
WHERE | ||
a.created_by < b.created_by | ||
AND | ||
a.hash = b.hash; | ||
|
||
-- Drop the primary key on files.id. | ||
ALTER TABLE files DROP CONSTRAINT files_pkey; | ||
-- Drop the id column. | ||
ALTER TABLE files DROP COLUMN id; | ||
-- Drop the unique constraint on hash + owner. | ||
ALTER TABLE files DROP CONSTRAINT files_hash_created_by_key; | ||
-- Set the primary key back to hash. | ||
ALTER TABLE files ADD PRIMARY KEY (hash); | ||
|
||
COMMIT; |
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,42 @@ | ||
-- This migration updates the files table to move the unique | ||
-- constraint to be hash + created_by. This is necessary to | ||
-- allow regular users who have been granted admin to a specific | ||
-- template to be able to push and read files used for template | ||
-- versions they create. | ||
-- Prior to this collisions on file.hash were not an issue | ||
-- since users who could push files could also read all files. | ||
-- | ||
-- This migration also adds a 'files.id' column as the primary | ||
-- key. As a side effect the provisioner_jobs must now reference | ||
-- the files.id column since the 'hash' column is now ambiguous. | ||
BEGIN; | ||
|
||
-- Drop the primary key on hash. | ||
ALTER TABLE files DROP CONSTRAINT files_pkey; | ||
|
||
-- Add an 'id' column and designate it the primary key. | ||
ALTER TABLE files ADD COLUMN | ||
id uuid NOT NULL PRIMARY KEY DEFAULT gen_random_uuid (); | ||
|
||
-- Update the constraint to include the user who created it. | ||
ALTER TABLE files ADD UNIQUE(hash, created_by); | ||
|
||
-- Update provisioner_jobs to include a file_id column. | ||
-- This must be temporarily nullable. | ||
ALTER TABLE provisioner_jobs ADD COLUMN file_id uuid; | ||
|
||
-- Update all the rows to point to key in the files table. | ||
UPDATE provisioner_jobs | ||
SET | ||
file_id = files.id | ||
FROM | ||
files | ||
WHERE | ||
provisioner_jobs.storage_source = files.hash; | ||
|
||
-- Enforce NOT NULL on file_id now. | ||
ALTER TABLE provisioner_jobs ALTER COLUMN file_id SET NOT NULL; | ||
-- Drop storage_source since it is no longer useful for anything. | ||
ALTER TABLE provisioner_jobs DROP COLUMN storage_source; | ||
|
||
COMMIT; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Uh oh!
There was an error while loading. Please reload this page.