Files
upstream-ourboard/scripts/migrate_user_email.sh
upstream-mirror d57328655f
Some checks failed
build / test (18.x) (push) Failing after 10s
build / lint (18.x) (push) Failing after 0s
build / docker-image (push) Has been skipped
snapshot of https://github.com/raimohanska/ourboard.git (master, 2026-09-23; blobs > 131072B omitted)
2026-09-23 16:16:17 +05:00

34 lines
748 B
Bash
Executable File

#!/bin/bash
from_email=$1
to_email=$2
if [ -z $to_email ]; then
echo "Usage: migrate_user_email.sh <fromemail> <toemail>"
exit 1
fi
if [ -z $DATABASE_URL ]; then
echo "DATABASE_URL env missing"
exit 1
fi
echo Migrating user email from $from_email to $to_email
cat << EOF | psql $DATABASE_URL
BEGIN;
insert into app_user(id, email)
values (uuid_generate_v4(), '$to_email')
on conflict do nothing;
update board_access set email='$to_email' where email='$from_email';
insert into user_board(board_id, user_id, last_opened) (
select board_id, (select id from app_user where email='$to_email'), last_opened
from user_board where user_id = (select id from app_user where email='$from_email')
) on conflict do nothing;
COMMIT;
EOF