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

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

ALTER TABLE users DROP COLUMN name;
