import { pgTable, foreignKey, uuid, text, date, boolean, varchar, index, time, primaryKey, pgSequence } from "drizzle-orm/pg-core" import { sql } from "drizzle-orm" export const versionIdSeq = pgSequence("version_id_seq", { startWith: "1", increment: "1", minValue: "1", maxValue: "9223372036854775807", cache: "1", cycle: false }) export const accessTokenIdSeq = pgSequence("access_token_id_seq", { startWith: "1", increment: "1", minValue: "1", maxValue: "9223372036854775807", cache: "1", cycle: false }) export const oauth2ApplicationIdSeq = pgSequence("oauth2_application_id_seq", { startWith: "1", increment: "1", minValue: "1", maxValue: "9223372036854775807", cache: "1", cycle: false }) export const oauth2AuthorizationCodeIdSeq = pgSequence("oauth2_authorization_code_id_seq", { startWith: "1", increment: "1", minValue: "1", maxValue: "9223372036854775807", cache: "1", cycle: false }) export const oauth2GrantIdSeq = pgSequence("oauth2_grant_id_seq", { startWith: "1", increment: "1", minValue: "1", maxValue: "9223372036854775807", cache: "1", cycle: false }) export const loginSourceIdSeq = pgSequence("login_source_id_seq", { startWith: "1", increment: "1", minValue: "1", maxValue: "9223372036854775807", cache: "1", cycle: false }) export const twoFactorIdSeq = pgSequence("two_factor_id_seq", { startWith: "1", increment: "1", minValue: "1", maxValue: "9223372036854775807", cache: "1", cycle: false }) export const webauthnCredentialIdSeq = pgSequence("webauthn_credential_id_seq", { startWith: "1", increment: "1", minValue: "1", maxValue: "9223372036854775807", cache: "1", cycle: false }) export const dbfsMetaIdSeq = pgSequence("dbfs_meta_id_seq", { startWith: "1", increment: "1", minValue: "1", maxValue: "9223372036854775807", cache: "1", cycle: false }) export const dbfsDataIdSeq = pgSequence("dbfs_data_id_seq", { startWith: "1", increment: "1", minValue: "1", maxValue: "9223372036854775807", cache: "1", cycle: false }) export const noticeIdSeq = pgSequence("notice_id_seq", { startWith: "1", increment: "1", minValue: "1", maxValue: "9223372036854775807", cache: "1", cycle: false }) export const systemSettingIdSeq = pgSequence("system_setting_id_seq", { startWith: "1", increment: "1", minValue: "1", maxValue: "9223372036854775807", cache: "1", cycle: false }) export const badgeIdSeq = pgSequence("badge_id_seq", { startWith: "1", increment: "1", minValue: "1", maxValue: "9223372036854775807", cache: "1", cycle: false }) export const userBadgeIdSeq = pgSequence("user_badge_id_seq", { startWith: "1", increment: "1", minValue: "1", maxValue: "9223372036854775807", cache: "1", cycle: false }) export const userBlockingIdSeq = pgSequence("user_blocking_id_seq", { startWith: "1", increment: "1", minValue: "1", maxValue: "9223372036854775807", cache: "1", cycle: false }) export const emailAddressIdSeq = pgSequence("email_address_id_seq", { startWith: "1", increment: "1", minValue: "1", maxValue: "9223372036854775807", cache: "1", cycle: false }) export const comment = pgTable("comment", { id: uuid().primaryKey().notNull(), content: text(), createdAt: date("created_at"), isDeleted: boolean("is_deleted").default(false), writerId: uuid("writer_id"), parentId: uuid("parent_id"), }, (table) => [ foreignKey({ columns: [table.writerId], foreignColumns: [account.id], name: "writer_id" }), foreignKey({ columns: [table.parentId], foreignColumns: [table.id], name: "parent_id" }), ]); export const account = pgTable("account", { name: varchar().notNull(), email: varchar().notNull(), password: varchar().notNull(), birthday: date(), accountId: varchar("account_id").notNull(), nickname: varchar().notNull(), status: varchar().default('active').notNull(), isDeleted: boolean("is_deleted").default(false).notNull(), createdAt: date("created_at").defaultNow().notNull(), id: uuid().default(sql`uuid_generate_v4()`).primaryKey().notNull(), }); export const participant = pgTable("participant", { participantId: uuid("participant_id").notNull(), scheduleId: uuid("schedule_id").notNull(), isDeleted: boolean("is_deleted").default(false), }, (table) => [ index("participant_participant_id_idx").using("btree", table.participantId.asc().nullsLast().op("uuid_ops")), index("participant_schedule_id_idx").using("btree", table.scheduleId.asc().nullsLast().op("uuid_ops")), foreignKey({ columns: [table.scheduleId], foreignColumns: [schedule.id], name: "schedule_id" }), foreignKey({ columns: [table.participantId], foreignColumns: [account.id], name: "participant_id" }), ]); export const schedule = pgTable("schedule", { id: uuid().primaryKey().notNull(), name: varchar(), startDate: date("start_date"), endDate: date("end_date"), status: varchar(), content: text(), isDeleted: boolean("is_deleted").default(false), type: varchar(), createdAt: date("created_at"), owner: uuid(), style: varchar(), startTime: time("start_time"), endTime: time("end_time"), }, (table) => [ index("schedule_enddatetime_idx").using("btree", table.endDate.asc().nullsLast().op("date_ops")), index("schedule_name_idx").using("btree", table.name.asc().nullsLast().op("text_ops"), table.content.asc().nullsLast().op("text_ops")), index("schedule_startdatetime_idx").using("btree", table.startDate.asc().nullsLast().op("date_ops")), index("schedule_status_idx").using("btree", table.status.asc().nullsLast().op("text_ops")), index("schedule_type_idx").using("btree", table.type.asc().nullsLast().op("text_ops")), foreignKey({ columns: [table.owner], foreignColumns: [account.id], name: "schedule_user_fk" }), ]); export const favorite = pgTable("favorite", { isDeleted: boolean("is_deleted").default(false), createdAt: date("created_at"), userId: uuid("user_id").notNull(), scheduleId: uuid("schedule_id").notNull(), }, (table) => [ foreignKey({ columns: [table.scheduleId], foreignColumns: [schedule.id], name: "schedule_id" }), foreignKey({ columns: [table.userId], foreignColumns: [account.id], name: "user_id" }), primaryKey({ columns: [table.userId, table.scheduleId], name: "favorite_pk"}), ]); export const follow = pgTable("follow", { isDeleted: boolean("is_deleted").default(false), isAccepted: boolean("is_accepted").default(false), isLinked: boolean("is_linked").default(false), createdAt: date("created_at"), following: uuid().notNull(), follower: uuid().notNull(), }, (table) => [ foreignKey({ columns: [table.follower], foreignColumns: [account.id], name: "follower_id" }), foreignKey({ columns: [table.following], foreignColumns: [account.id], name: "following_id" }), primaryKey({ columns: [table.following, table.follower], name: "follow_pk"}), ]);