-- Abort if any user has no email address set.
-- All users must have an email before this migration can run.
DO $$
BEGIN
  IF EXISTS (SELECT 1 FROM users WHERE email IS NULL) THEN
    RAISE EXCEPTION 'Migration aborted: some users have no email address. Set emails for all users before running this migration.';
  END IF;
END $$;

ALTER TABLE users ALTER COLUMN email SET NOT NULL;
ALTER TABLE users DROP COLUMN username;
