- Notifications
You must be signed in to change notification settings - Fork927
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
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; |
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; | ||
Emyrk marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
COMMIT; |
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.