@@ -29,6 +29,30 @@ export const wallets = pgTable('wallets', {
2929 createdAt : timestamp ( 'created_at' ) . notNull ( ) . defaultNow ( ) ,
3030} ) ;
3131
32+ export const devices = pgTable ( 'devices' , {
33+ id : uuid ( 'id' ) . primaryKey ( ) . defaultRandom ( ) ,
34+ userId : uuid ( 'user_id' )
35+ . notNull ( )
36+ . references ( ( ) => users . id , { onDelete : 'cascade' } ) ,
37+ deviceId : text ( 'device_id' ) . notNull ( ) ,
38+ deviceName : text ( 'device_name' ) . notNull ( ) ,
39+ platform : text ( 'platform' ) . notNull ( ) ,
40+ identityPublicKey : text ( 'identity_public_key' ) . notNull ( ) ,
41+ registrationId : text ( 'registration_id' ) ,
42+ isRevoked : boolean ( 'is_revoked' ) . notNull ( ) . default ( false ) ,
43+ createdAt : timestamp ( 'created_at' ) . notNull ( ) . defaultNow ( ) ,
44+ updatedAt : timestamp ( 'updated_at' ) . notNull ( ) . defaultNow ( ) ,
45+ } ) ;
46+
47+ export const devicePrekeys = pgTable ( 'device_prekeys' , {
48+ id : uuid ( 'id' ) . primaryKey ( ) . defaultRandom ( ) ,
49+ deviceId : uuid ( 'device_id' )
50+ . notNull ( )
51+ . references ( ( ) => devices . id , { onDelete : 'cascade' } ) ,
52+ prekey : text ( 'prekey' ) . notNull ( ) ,
53+ createdAt : timestamp ( 'created_at' ) . notNull ( ) . defaultNow ( ) ,
54+ } ) ;
55+
3256// ─── Conversations ────────────────────────────────────────────────────────────
3357
3458export const conversationTypeEnum = pgEnum ( 'conversation_type' , [ 'dm' , 'group' ] ) ;
@@ -183,6 +207,15 @@ export const tokenTransfersRelations = relations(tokenTransfers, ({ one }) => ({
183207 } ) ,
184208} ) ) ;
185209
210+ export const devicesRelations = relations ( devices , ( { one, many } ) => ( {
211+ user : one ( users , { fields : [ devices . userId ] , references : [ users . id ] } ) ,
212+ prekeys : many ( devicePrekeys ) ,
213+ } ) ) ;
214+
215+ export const devicePrekeysRelations = relations ( devicePrekeys , ( { one } ) => ( {
216+ device : one ( devices , { fields : [ devicePrekeys . deviceId ] , references : [ devices . id ] } ) ,
217+ } ) ) ;
218+
186219export const userDevicesRelations = relations ( userDevices , ( { one } ) => ( {
187220 user : one ( users , { fields : [ userDevices . userId ] , references : [ users . id ] } ) ,
188221} ) ) ;
@@ -200,5 +233,9 @@ export type Message = typeof messages.$inferSelect;
200233export type NewMessage = typeof messages . $inferInsert ;
201234export type TokenTransfer = typeof tokenTransfers . $inferSelect ;
202235export type NewTokenTransfer = typeof tokenTransfers . $inferInsert ;
236+ export type Device = typeof devices . $inferSelect ;
237+ export type NewDevice = typeof devices . $inferInsert ;
238+ export type DevicePrekey = typeof devicePrekeys . $inferSelect ;
239+ export type NewDevicePrekey = typeof devicePrekeys . $inferInsert ;
203240export type UserDevice = typeof userDevices . $inferSelect ;
204241export type NewUserDevice = typeof userDevices . $inferInsert ;
0 commit comments