chattyness/db/reinitialize_user.md

1.6 KiB

Reinitialize User with Default Props

When stock props or avatars are updated in the database, existing users may need to be reinitialized to receive the new defaults.

Steps

  1. Find the user's ID:
SELECT id, username FROM auth.users WHERE username = 'TARGET_USERNAME';
  1. Clear existing data and reinitialize:
BEGIN;

-- Clear existing props and avatars for the user
DELETE FROM auth.active_avatars WHERE user_id = 'USER_UUID';
DELETE FROM auth.avatars WHERE user_id = 'USER_UUID';
DELETE FROM auth.inventory WHERE user_id = 'USER_UUID';

-- Reinitialize with current server props
SELECT auth.initialize_new_user('USER_UUID');

COMMIT;
  1. Verify the results:
SELECT COUNT(*) as inventory_count FROM auth.inventory WHERE user_id = 'USER_UUID';
SELECT id, name, slot_number FROM auth.avatars WHERE user_id = 'USER_UUID';

Example: Reinitialize ranosh

psql -d chattyness <<'EOF'
BEGIN;

DELETE FROM auth.active_avatars WHERE user_id = '57a12201-ea0f-4545-9ccc-c4e67ea7e2c4';
DELETE FROM auth.avatars WHERE user_id = '57a12201-ea0f-4545-9ccc-c4e67ea7e2c4';
DELETE FROM auth.inventory WHERE user_id = '57a12201-ea0f-4545-9ccc-c4e67ea7e2c4';

SELECT auth.initialize_new_user('57a12201-ea0f-4545-9ccc-c4e67ea7e2c4');

COMMIT;
EOF

What initialize_new_user Does

The auth.initialize_new_user() function:

  1. Inserts all face-tagged server props into the user's inventory
  2. Creates a default avatar (slot 0) with:
    • Face prop in the skin layer (position 4, center)
    • All emotion props mapped to their respective emotion slots