Select Git revision
notification.ts
notification.ts 1.95 KiB
import { sql } from "drizzle-orm"
import { integer, pgTable, serial, timestamp } from "drizzle-orm/pg-core"
import { createInsertSchema, createSelectSchema } from "drizzle-zod"
import type { z } from "zod"
import { actionTable, collectionTable, resourceTable, userTable } from "."
const notificationTable = pgTable('notifications', {
id: serial('id').primaryKey()
.unique()
.notNull(),
action_id: integer('action_id')
.references(() => actionTable.id, {onDelete: 'cascade'})
.notNull(),
actor_user_id: integer('actor_user_id')
.references(() => userTable.id, {onDelete: 'cascade'})
.notNull(),
target_user_id: integer('target_user_id')
.references(() => userTable.id, {onDelete: 'cascade'})
.notNull(),
target_resource_id: integer('target_resource_id')
.references(() => resourceTable.id, {onDelete: 'cascade'}),
target_collection_id: integer('target_collection_id')
.references(() => collectionTable.id, {onDelete: 'cascade'}),
createdAt: timestamp('created_at', { mode: 'string' })
.notNull()
.defaultNow(),
updatedAt: timestamp('updated_at', { mode: 'string' })
.notNull()
.defaultNow()
.$onUpdate(() => sql`current_timestamp`),
})
const notificationModelSchema = createSelectSchema(notificationTable)
const notificationDtoSchema = notificationModelSchema
const notificationInputSchema = createInsertSchema(notificationTable)
const notificationUpdateSchema = notificationInputSchema
.partial()
.required({ id: true })
export type NotificationModel = z.infer<typeof notificationModelSchema>
export type NotificationDto = z.infer<typeof notificationDtoSchema>
export type NotificationInput = z.infer<typeof notificationInputSchema>
export type NotificationUpdate = z.infer<typeof notificationUpdateSchema>
export const notificationSchemas = {
model: notificationModelSchema,
dto: notificationDtoSchema,
input: notificationInputSchema,
update: notificationUpdateSchema
}
export default notificationTable