db rearch

This commit is contained in:
2026-05-25 20:50:45 -04:00
parent 3ccaeaa2e3
commit 89822dedb8
19 changed files with 339 additions and 324 deletions

View File

@@ -1,17 +1,16 @@
import { pgTable, text, timestamp, index, uuid, boolean } from "drizzle-orm/pg-core";
import { sqliteTable, text, integer, index } from "drizzle-orm/sqlite-core";
import { users } from "./auth";
import { reportType } from "./enums";
export const reportSchedules = pgTable("report_schedules", {
id: uuid("id").defaultRandom().primaryKey(),
userId: uuid("user_id").notNull().references(() => users.id, { onDelete: "cascade" }),
enabled: boolean("enabled").default(true).notNull(),
export const reportSchedules = sqliteTable("report_schedules", {
id: text("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
userId: text("user_id").notNull().references(() => users.id, { onDelete: "cascade" }),
enabled: integer("enabled", { mode: "boolean" }).default(true).notNull(),
frequency: text("frequency").notNull(),
reportType: reportType("report_type").notNull(),
lastGeneratedAt: timestamp("last_generated_at", { withTimezone: true, mode: "date" }),
nextScheduledAt: timestamp("next_scheduled_at", { withTimezone: true, mode: "date" }),
createdAt: timestamp("created_at", { withTimezone: true, mode: "date" }).defaultNow().notNull(),
updatedAt: timestamp("updated_at", { withTimezone: true, mode: "date" }).defaultNow().notNull().$onUpdate(() => new Date()),
reportType: text("report_type").notNull(),
lastGeneratedAt: integer("last_generated_at", { mode: "timestamp_ms" }),
nextScheduledAt: integer("next_scheduled_at", { mode: "timestamp_ms" }),
createdAt: integer("created_at", { mode: "timestamp_ms" }).defaultNow().notNull(),
updatedAt: integer("updated_at", { mode: "timestamp_ms" }).defaultNow().notNull().$onUpdate(() => new Date()),
}, (table) => ({
userIdIdx: index("report_schedules_user_id_idx").on(table.userId),
enabledIdx: index("report_schedules_enabled_idx").on(table.enabled),