File size: 2,061 Bytes
2c16c8c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import {
  pgTable,
  uuid,
  text,
  boolean,
  integer,
  timestamp,
  index,
  pgEnum,
} from 'drizzle-orm/pg-core';

export const languageEnum = pgEnum('language', ['ur', 'en', 'ps']);
export const notificationFrequencyEnum = pgEnum('notification_frequency', ['none', 'daily', 'weekly']);
export const subscriptionTypeEnum = pgEnum('subscription_type', ['freemium', 'premium']);
export const subscriptionStatusEnum = pgEnum('subscription_status', ['active', 'cancelled', 'expired']);

export const users = pgTable('users', {
  id: uuid('id').primaryKey(),

  email: text('email').notNull(),

  phoneNumber: text('phone_number').notNull(),

  fullName: text('full_name').notNull(),

  profileImageUrl: text('profile_image_url'),

  defaultLanguage: languageEnum('default_language').default('ur').notNull(),

  timezone: text('timezone').default('Asia/Karachi').notNull(),

  notificationEnabled: boolean('notification_enabled').default(true).notNull(),

  notificationFrequency: notificationFrequencyEnum('notification_frequency').default('daily').notNull(),

  subscriptionType: subscriptionTypeEnum('subscription_type').default('freemium').notNull(),

  subscriptionStatus: subscriptionStatusEnum('subscription_status').default('active').notNull(),

  dailyMessageLimit: integer('daily_message_limit').default(20).notNull(),

  dailyMessagesUsed: integer('daily_messages_used').default(0).notNull(),

  dailyLimitResetAt: timestamp('daily_limit_reset_at', { withTimezone: true }),

  createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
  updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull(),
  deletedAt: timestamp('deleted_at', { withTimezone: true }),
}, (table) => {
  return {
    emailIndex: index('users_email_idx').on(table.email),
    phoneIndex: index('users_phone_idx').on(table.phoneNumber),
    subscriptionIndex: index('users_subscription_type_status_idx')
      .on(table.subscriptionType, table.subscriptionStatus),
  };
});