-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add copy_upload_history db function to migrate user data (#1964)
* feat: add copyUserData db function to migrate user data * rm comment * refactor copy_user_data to copy_upload_history, add auth key arg * revert changes to DBClient
- Loading branch information
1 parent
f7ee2bb
commit 7edca7b
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
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
32 changes: 32 additions & 0 deletions
32
packages/api/db/migrations/006-add-copy-upload-history-fn.sql
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
-- Copies upload history from one user id to another. | ||
-- Copied uploads will be associated with new_auth_key, which | ||
-- should be the id of an auth_key belonging to the new user. | ||
CREATE OR REPLACE FUNCTION copy_upload_history(old_user_id BIGINT, new_user_id BIGINT, new_auth_key_id BIGINT) RETURNS void | ||
LANGUAGE plpgsql | ||
volatile | ||
PARALLEL UNSAFE | ||
AS | ||
$$ | ||
BEGIN | ||
|
||
INSERT INTO upload ( | ||
user_id, | ||
key_id, | ||
content_cid, | ||
source_cid, | ||
mime_type, | ||
type, | ||
name, | ||
files, | ||
origins, | ||
meta, | ||
backup_urls, | ||
updated_at, | ||
inserted_at | ||
) | ||
SELECT new_user_id, new_auth_key_id, u.content_cid, u.source_cid, u.mime_type, u.type, u.name, u.files, u.origins, u.meta, u.backup_urls, u.updated_at, u.inserted_at | ||
FROM upload as u | ||
WHERE u.user_id = old_user_id; | ||
|
||
END | ||
$$; |