ALTER TABLE users ADD COLUMN name TEXT NOT NULL DEFAULT '';

UPDATE users SET name = (
    SELECT p.name FROM profiles p WHERE p.user_id = users.id
) WHERE id IN (SELECT user_id FROM profiles WHERE name != '');

ALTER TABLE profiles DROP COLUMN name;
