49 lines
1.8 KiB
TypeScript
49 lines
1.8 KiB
TypeScript
import { date, doublePrecision, integer, pgEnum, pgTable, text, uuid, varchar } from 'drizzle-orm/pg-core';
|
|
import { user } from './user.schema';
|
|
import { city, cityDistrict } from './city.schema';
|
|
|
|
export const genderEnum = pgEnum('gender', ['male', 'female']);
|
|
export const profileMediaTypeEnum = pgEnum('profile_media_type', ['photo', 'video', 'audio']);
|
|
|
|
export const profile = pgTable('profile', {
|
|
id: uuid('id').primaryKey().defaultRandom(),
|
|
userId: uuid('user_id')
|
|
.notNull()
|
|
.references(() => user.id, { onDelete: 'cascade' }),
|
|
name: varchar('name', { length: 100 }).notNull(),
|
|
birthDate: date('birth_date').notNull(),
|
|
gender: genderEnum('gender').notNull(),
|
|
cityId: uuid('city_id').references(() => city.id, { onDelete: 'set null' }),
|
|
districtId: uuid('district_id').references(() => cityDistrict.id, { onDelete: 'set null' }),
|
|
description: text('description'),
|
|
nation: varchar('nation', { length: 100 }),
|
|
height: doublePrecision('height'),
|
|
weight: doublePrecision('weight'),
|
|
activeChatId: uuid('active_chat_id'),
|
|
});
|
|
|
|
// Media attachments for a profile (photos, videos, audio)
|
|
export const profileMedia = pgTable('profile_media', {
|
|
id: uuid('id').primaryKey().defaultRandom(),
|
|
profileId: uuid('profile_id')
|
|
.notNull()
|
|
.references(() => profile.id, { onDelete: 'cascade' }),
|
|
path: text('path').notNull(),
|
|
type: profileMediaTypeEnum('type').notNull(),
|
|
sortOrder: integer('sort_order').notNull().default(0),
|
|
});
|
|
|
|
export const tag = pgTable('tag', {
|
|
id: uuid('id').primaryKey().defaultRandom(),
|
|
value: varchar('value', { length: 100 }).notNull().unique(),
|
|
});
|
|
|
|
export const profileTag = pgTable('profile_tag', {
|
|
profileId: uuid('profile_id')
|
|
.notNull()
|
|
.references(() => profile.id, { onDelete: 'cascade' }),
|
|
tagId: uuid('tag_id')
|
|
.notNull()
|
|
.references(() => tag.id, { onDelete: 'cascade' }),
|
|
});
|