|
| 1 | +import { mysqlTable, varchar, text, boolean, timestamp, datetime, tinyint, json, mysqlEnum } from 'drizzle-orm/mysql-core' |
| 2 | + |
| 3 | +export const user = mysqlTable('user', { |
| 4 | + id: varchar('id', { length: 36 }).primaryKey(), |
| 5 | + name: varchar('name', { length: 255 }).notNull(), |
| 6 | + email: varchar('email', { length: 255 }).notNull().unique(), |
| 7 | + emailVerified: boolean('email_verified').notNull().default(false), |
| 8 | + image: text('image'), |
| 9 | + timezone: varchar('timezone', { length: 64 }).notNull().default('Asia/Seoul'), |
| 10 | + createdAt: timestamp('created_at').notNull().defaultNow(), |
| 11 | + updatedAt: timestamp('updated_at').notNull().defaultNow().onUpdateNow(), |
| 12 | +}) |
| 13 | + |
| 14 | +export const session = mysqlTable('session', { |
| 15 | + id: varchar('id', { length: 36 }).primaryKey(), |
| 16 | + userId: varchar('user_id', { length: 36 }) |
| 17 | + .notNull() |
| 18 | + .references(() => user.id, { onDelete: 'cascade' }), |
| 19 | + token: varchar('token', { length: 255 }).notNull().unique(), |
| 20 | + expiresAt: timestamp('expires_at').notNull(), |
| 21 | + ipAddress: varchar('ip_address', { length: 45 }), |
| 22 | + userAgent: text('user_agent'), |
| 23 | + createdAt: timestamp('created_at').notNull().defaultNow(), |
| 24 | + updatedAt: timestamp('updated_at').notNull().defaultNow().onUpdateNow(), |
| 25 | +}) |
| 26 | + |
| 27 | +export const account = mysqlTable('account', { |
| 28 | + id: varchar('id', { length: 36 }).primaryKey(), |
| 29 | + userId: varchar('user_id', { length: 36 }) |
| 30 | + .notNull() |
| 31 | + .references(() => user.id, { onDelete: 'cascade' }), |
| 32 | + accountId: varchar('account_id', { length: 255 }).notNull(), |
| 33 | + providerId: varchar('provider_id', { length: 255 }).notNull(), |
| 34 | + accessToken: text('access_token'), |
| 35 | + refreshToken: text('refresh_token'), |
| 36 | + accessTokenExpiresAt: timestamp('access_token_expires_at'), |
| 37 | + refreshTokenExpiresAt: timestamp('refresh_token_expires_at'), |
| 38 | + scope: text('scope'), |
| 39 | + idToken: text('id_token'), |
| 40 | + password: text('password'), |
| 41 | + createdAt: timestamp('created_at').notNull().defaultNow(), |
| 42 | + updatedAt: timestamp('updated_at').notNull().defaultNow().onUpdateNow(), |
| 43 | +}) |
| 44 | + |
| 45 | +export const verification = mysqlTable('verification', { |
| 46 | + id: varchar('id', { length: 36 }).primaryKey(), |
| 47 | + identifier: varchar('identifier', { length: 255 }).notNull(), |
| 48 | + value: text('value').notNull(), |
| 49 | + expiresAt: timestamp('expires_at').notNull(), |
| 50 | + createdAt: timestamp('created_at').notNull().defaultNow(), |
| 51 | + updatedAt: timestamp('updated_at').notNull().defaultNow().onUpdateNow(), |
| 52 | +}) |
| 53 | + |
| 54 | +export type RRuleType = { |
| 55 | + freq: 'DAILY' | 'WEEKLY' | 'MONTHLY' | 'YEARLY' |
| 56 | + interval?: number |
| 57 | + count?: number |
| 58 | + until?: string |
| 59 | + byDay?: string[] |
| 60 | + byMonth?: number[] |
| 61 | + byMonthDay?: number[] |
| 62 | +} | null |
| 63 | + |
| 64 | +export const calendarEvent = mysqlTable('calendar_event', { |
| 65 | + id: varchar('id', { length: 36 }).primaryKey(), |
| 66 | + userId: varchar('user_id', { length: 36 }) |
| 67 | + .notNull() |
| 68 | + .references(() => user.id, { onDelete: 'cascade' }), |
| 69 | + uid: varchar('uid', { length: 255 }).notNull().unique(), |
| 70 | + summary: varchar('summary', { length: 500 }).notNull(), |
| 71 | + description: text('description'), |
| 72 | + location: varchar('location', { length: 500 }), |
| 73 | + dtstart: datetime('dtstart').notNull(), |
| 74 | + dtend: datetime('dtend').notNull(), |
| 75 | + isAllDay: boolean('is_all_day').notNull().default(false), |
| 76 | + rrule: json('rrule').$type<RRuleType>(), |
| 77 | + exdate: json('exdate').$type<string[]>(), |
| 78 | + status: mysqlEnum('status', ['TENTATIVE', 'CONFIRMED', 'CANCELLED']).default('CONFIRMED'), |
| 79 | + transp: mysqlEnum('transp', ['TRANSPARENT', 'OPAQUE']).default('OPAQUE'), |
| 80 | + priority: tinyint('priority'), |
| 81 | + categories: json('categories').$type<string[]>(), |
| 82 | + color: varchar('color', { length: 50 }), |
| 83 | + sequence: tinyint('sequence').notNull().default(0), |
| 84 | + dtstamp: datetime('dtstamp').notNull(), |
| 85 | + createdAt: timestamp('created_at').notNull().defaultNow(), |
| 86 | + updatedAt: timestamp('updated_at').notNull().defaultNow().onUpdateNow(), |
| 87 | +}) |
| 88 | + |
| 89 | +export const deletedCalendarEvent = mysqlTable('deleted_calendar_event', { |
| 90 | + id: varchar('id', { length: 36 }).primaryKey(), |
| 91 | + userId: varchar('user_id', { length: 36 }) |
| 92 | + .notNull() |
| 93 | + .references(() => user.id, { onDelete: 'cascade' }), |
| 94 | + uid: varchar('uid', { length: 255 }).notNull(), |
| 95 | + deletedAt: timestamp('deleted_at').notNull().defaultNow(), |
| 96 | + syncToken: varchar('sync_token', { length: 64 }).notNull(), |
| 97 | +}) |
| 98 | + |
| 99 | +export const calendarSubscription = mysqlTable('calendar_subscription', { |
| 100 | + id: varchar('id', { length: 36 }).primaryKey(), |
| 101 | + userId: varchar('user_id', { length: 36 }) |
| 102 | + .notNull() |
| 103 | + .references(() => user.id, { onDelete: 'cascade' }), |
| 104 | + token: varchar('token', { length: 64 }).notNull().unique(), |
| 105 | + icsToken: varchar('ics_token', { length: 64 }).notNull().unique(), |
| 106 | + name: varchar('name', { length: 255 }), |
| 107 | + isActive: boolean('is_active').notNull().default(true), |
| 108 | + ctag: varchar('ctag', { length: 64 }).notNull().default('0'), |
| 109 | + lastAccessedAt: datetime('last_accessed_at'), |
| 110 | + createdAt: timestamp('created_at').notNull().defaultNow(), |
| 111 | + updatedAt: timestamp('updated_at').notNull().defaultNow().onUpdateNow(), |
| 112 | +}) |
| 113 | + |
| 114 | +export type User = typeof user.$inferSelect |
| 115 | +export type Session = typeof session.$inferSelect |
| 116 | +export type Account = typeof account.$inferSelect |
| 117 | +export type CalendarEventRow = typeof calendarEvent.$inferSelect |
| 118 | +export type CalendarSubscriptionRow = typeof calendarSubscription.$inferSelect |
0 commit comments