Skip to content

feat(backend): add user_devices device identity schema#206

Open
Olorunfemi20 wants to merge 1 commit into
codebestia:mainfrom
Olorunfemi20:feat/user-devices-schema
Open

feat(backend): add user_devices device identity schema#206
Olorunfemi20 wants to merge 1 commit into
codebestia:mainfrom
Olorunfemi20:feat/user-devices-schema

Conversation

@Olorunfemi20

Copy link
Copy Markdown

closes #153

Summary

Adds a user_devices table to the backend Drizzle schema to serve as a per-user device identity registry for end-to-end encryption. Each row records a registered device, its platform, and its long-term identity public key. Devices are revoked rather than deleted, so historical sessions remain auditable.

Changes

  • New device_platform pgEnum (web / ios / android).
  • New user_devices table:
    • id uuid PK, userId uuid FK -> users.id (ON DELETE CASCADE)
    • deviceId, deviceName, identityPublicKey text; platform enum
    • registrationId integer (nullable), lastSeenAt / revokedAt timestamps (nullable)
    • createdAt timestamp default now()
  • Unique index on (userId, deviceId) enforcing per-user device uniqueness at the DB level.
  • Partial index on userId WHERE revoked_at IS NULL for fast active-device lookups.
  • Drizzle relations: users.devices (many) and userDevices.user (one).
  • Exported inferred types UserDevice and NewUserDevice.
  • Generated migration 0007_user_devices.sql and registered it in the migration journal.

Acceptance criteria

  • Migration applies cleanly.
  • (userId, deviceId) uniqueness enforced at the database level.
  • Revoking a device sets revokedAt without deleting the row.
  • Relations and inferred types are exported.

Notes

The table follows the existing schema conventions (snake_case columns, cascade FKs to users, soft-delete via nullable timestamp as used by messages.deletedAt). The migration is hand-authored to match the format and journal pattern of the repository's most recent migrations.

@drips-wave

drips-wave Bot commented Jun 25, 2026

Copy link
Copy Markdown

@Olorunfemi20 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add user_devices schema (device identity registry)

1 participant