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,42 +1,41 @@
import { pgTable, text, timestamp, index, uuid, boolean, jsonb, integer } from "drizzle-orm/pg-core";
import { sqliteTable, text, integer, index } from "drizzle-orm/sqlite-core";
import { subscriptions } from "./subscription";
import { brokerCategory, removalMethod, removalStatus } from "./enums";
export const infoBrokers = pgTable("info_brokers", {
id: uuid("id").defaultRandom().primaryKey(),
export const infoBrokers = sqliteTable("info_brokers", {
id: text("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
name: text("name").notNull(),
domain: text("domain").notNull().unique(),
category: brokerCategory("category").notNull(),
removalMethod: removalMethod("removal_method").notNull(),
category: text("category").notNull(),
removalMethod: text("removal_method").notNull(),
removalUrl: text("removal_url"),
requiresAccount: boolean("requires_account").default(false).notNull(),
requiresVerification: boolean("requires_verification").default(false).notNull(),
requiresAccount: integer("requires_account", { mode: "boolean" }).default(false).notNull(),
requiresVerification: integer("requires_verification", { mode: "boolean" }).default(false).notNull(),
estimatedDays: integer("estimated_days").default(14).notNull(),
isActive: boolean("is_active").default(true).notNull(),
createdAt: timestamp("created_at", { withTimezone: true, mode: "date" }).defaultNow().notNull(),
updatedAt: timestamp("updated_at", { withTimezone: true, mode: "date" }).defaultNow().notNull().$onUpdate(() => new Date()),
isActive: integer("is_active", { mode: "boolean" }).default(true).notNull(),
createdAt: integer("created_at", { mode: "timestamp_ms" }).defaultNow().notNull(),
updatedAt: integer("updated_at", { mode: "timestamp_ms" }).defaultNow().notNull().$onUpdate(() => new Date()),
}, (table) => ({
categoryIdx: index("info_brokers_category_idx").on(table.category),
isActiveIdx: index("info_brokers_is_active_idx").on(table.isActive),
removalMethodIdx: index("info_brokers_removal_method_idx").on(table.removalMethod),
}));
export const removalRequests = pgTable("removal_requests", {
id: uuid("id").defaultRandom().primaryKey(),
subscriptionId: uuid("subscription_id").notNull().references(() => subscriptions.id, { onDelete: "cascade" }),
brokerId: uuid("broker_id").notNull().references(() => infoBrokers.id),
status: removalStatus("status").default("PENDING").notNull(),
personalInfo: jsonb("personal_info").notNull(),
method: removalMethod("method").notNull(),
export const removalRequests = sqliteTable("removal_requests", {
id: text("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
subscriptionId: text("subscription_id").notNull().references(() => subscriptions.id, { onDelete: "cascade" }),
brokerId: text("broker_id").notNull().references(() => infoBrokers.id),
status: text("status").default("PENDING").notNull(),
personalInfo: text("personal_info", { mode: "json" }).notNull(),
method: text("method").notNull(),
attempts: integer("attempts").default(0).notNull(),
nextRetryAt: timestamp("next_retry_at", { withTimezone: true, mode: "date" }),
submittedAt: timestamp("submitted_at", { withTimezone: true, mode: "date" }),
completedAt: timestamp("completed_at", { withTimezone: true, mode: "date" }),
nextRetryAt: integer("next_retry_at", { mode: "timestamp_ms" }),
submittedAt: integer("submitted_at", { mode: "timestamp_ms" }),
completedAt: integer("completed_at", { mode: "timestamp_ms" }),
error: text("error"),
notes: text("notes"),
metadata: jsonb("metadata"),
createdAt: timestamp("created_at", { withTimezone: true, mode: "date" }).defaultNow().notNull(),
updatedAt: timestamp("updated_at", { withTimezone: true, mode: "date" }).defaultNow().notNull().$onUpdate(() => new Date()),
metadata: text("metadata", { mode: "json" }),
createdAt: integer("created_at", { mode: "timestamp_ms" }).defaultNow().notNull(),
updatedAt: integer("updated_at", { mode: "timestamp_ms" }).defaultNow().notNull().$onUpdate(() => new Date()),
}, (table) => ({
subscriptionIdIdx: index("removal_requests_subscription_id_idx").on(table.subscriptionId),
brokerIdIdx: index("removal_requests_broker_id_idx").on(table.brokerId),
@@ -45,19 +44,19 @@ export const removalRequests = pgTable("removal_requests", {
subscriptionIdStatusIdx: index("removal_requests_sub_id_status_idx").on(table.subscriptionId, table.status),
}));
export const brokerListings = pgTable("broker_listings", {
id: uuid("id").defaultRandom().primaryKey(),
subscriptionId: uuid("subscription_id").notNull().references(() => subscriptions.id, { onDelete: "cascade" }),
brokerId: uuid("broker_id").notNull(),
removalRequestId: uuid("removal_request_id").references(() => removalRequests.id),
export const brokerListings = sqliteTable("broker_listings", {
id: text("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
subscriptionId: text("subscription_id").notNull().references(() => subscriptions.id, { onDelete: "cascade" }),
brokerId: text("broker_id").notNull(),
removalRequestId: text("removal_request_id").references(() => removalRequests.id),
url: text("url").notNull(),
dataFound: jsonb("data_found").notNull(),
dataFound: text("data_found", { mode: "json" }).notNull(),
screenshotUrl: text("screenshot_url"),
isRemoved: boolean("is_removed").default(false).notNull(),
removedAt: timestamp("removed_at", { withTimezone: true, mode: "date" }),
scannedAt: timestamp("scanned_at", { withTimezone: true, mode: "date" }).defaultNow().notNull(),
createdAt: timestamp("created_at", { withTimezone: true, mode: "date" }).defaultNow().notNull(),
updatedAt: timestamp("updated_at", { withTimezone: true, mode: "date" }).defaultNow().notNull().$onUpdate(() => new Date()),
isRemoved: integer("is_removed", { mode: "boolean" }).default(false).notNull(),
removedAt: integer("removed_at", { mode: "timestamp_ms" }),
scannedAt: integer("scanned_at", { mode: "timestamp_ms" }).defaultNow().notNull(),
createdAt: integer("created_at", { mode: "timestamp_ms" }).defaultNow().notNull(),
updatedAt: integer("updated_at", { mode: "timestamp_ms" }).defaultNow().notNull().$onUpdate(() => new Date()),
}, (table) => ({
subscriptionIdIdx: index("broker_listings_subscription_id_idx").on(table.subscriptionId),
brokerIdIdx: index("broker_listings_broker_id_idx").on(table.brokerId),