93 lines
2.9 KiB
TypeScript
Executable File
93 lines
2.9 KiB
TypeScript
Executable File
import { sql } from "drizzle-orm";
|
|
import {
|
|
pgTableCreator,
|
|
serial,
|
|
timestamp,
|
|
varchar,
|
|
text,
|
|
integer,
|
|
boolean,
|
|
pgEnum
|
|
} from "drizzle-orm/pg-core";
|
|
|
|
export const createTable = pgTableCreator((name) => `${name}`);
|
|
|
|
export const statusEnum = pgEnum("status", ["pending", "accepted", "rejected"]);
|
|
export const messageTypeEnum = pgEnum("message_types", ["text", "image", "video", "audio", "file", "link"]);
|
|
|
|
export const users = createTable(
|
|
"user",
|
|
{
|
|
id: serial("id").primaryKey(),
|
|
appleId: varchar("apple_id", { length: 255 }).unique(),
|
|
appleEmail: varchar("apple_email", { length: 255 }).unique().notNull(),
|
|
fullName: varchar("full_name", { length: 100 }),
|
|
pfpURL: varchar("pfp_url", { length: 255 }),
|
|
pushToken: varchar("pushToken", { length: 255 }),
|
|
createdAt: timestamp("created_at", { withTimezone: true })
|
|
.default(sql`CURRENT_TIMESTAMP`)
|
|
.notNull(),
|
|
},
|
|
);
|
|
|
|
export const relationships = createTable(
|
|
"relationship",
|
|
{
|
|
id: serial("id").primaryKey(),
|
|
title: varchar("title", { length: 100 }).default("Relationship").notNull(),
|
|
status: statusEnum("status").default("pending").notNull(),
|
|
relationshipStartDate: timestamp("relationship_start_date", { withTimezone: true })
|
|
.default(sql`CURRENT_TIMESTAMP`).notNull(),
|
|
createdAt: timestamp("created_at", { withTimezone: true })
|
|
.default(sql`CURRENT_TIMESTAMP`).notNull(),
|
|
},
|
|
);
|
|
|
|
export const userRelationships = createTable(
|
|
"user_relationship",
|
|
{
|
|
id: serial("id").primaryKey(),
|
|
userId: integer("user_id").references(() => users.id).notNull(),
|
|
relationshipId: integer("relationship_id").references(() => relationships.id).notNull(),
|
|
},
|
|
);
|
|
|
|
export const messages = createTable(
|
|
"message",
|
|
{
|
|
id: serial("id").primaryKey(),
|
|
senderId: integer("sender_id").references(() => users.id).notNull(),
|
|
receiverId: integer("receiver_id").references(() => users.id).notNull(),
|
|
content: text("content").notNull(),
|
|
createdAt: timestamp("created_at", { withTimezone: true })
|
|
.default(sql`CURRENT_TIMESTAMP`)
|
|
.notNull(),
|
|
isRead: boolean("is_read").default(false).notNull(),
|
|
},
|
|
);
|
|
|
|
export const messageMedia = createTable(
|
|
"message_media",
|
|
{
|
|
id: serial("id").primaryKey(),
|
|
messageId: integer("message_id").references(() => messages.id).notNull(),
|
|
type: messageTypeEnum("type").notNull(),
|
|
mediaUrl: varchar("url", { length: 255 }).notNull(),
|
|
},
|
|
);
|
|
|
|
export const countdowns = createTable(
|
|
"countdown",
|
|
{
|
|
id: serial("id").primaryKey(),
|
|
relationshipId: integer("relationship_id").references(() => relationships.id).notNull(),
|
|
title: varchar("title", { length: 100 })
|
|
.default("Countdown to Next Visit")
|
|
.notNull(),
|
|
date: timestamp("date", { withTimezone: true }),
|
|
createdAt: timestamp("created_at", { withTimezone: true })
|
|
.default(sql`CURRENT_TIMESTAMP`)
|
|
.notNull(),
|
|
},
|
|
);
|