Spaces:
Sleeping

File size: 1,420 Bytes
7f81110
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { pgTable, uuid, text, timestamp, jsonb, index, integer } from "drizzle-orm/pg-core";
import { stores } from "../../../../../modules/shopify/infrastructure/postgres/schema/stores";

export const syncJobs = pgTable("sync_jobs", {
    id: text("id").primaryKey(),
    storeId: uuid("store_id").notNull().references(() => stores.id, { onDelete: "cascade" }),
    organizationId: uuid("organization_id").notNull(),
    provider: text("provider").default("shopify").notNull(),
    type: text("type").notNull(), // full | reconciliation
    status: text("status").notNull().default("pending"), // pending | running | completed | failed
    progress: jsonb("progress").default({}).notNull(),
    cursor: jsonb("cursor"),
    triggeredBy: text("triggered_by"),
    attempts: integer("attempts").default(0).notNull(),
    maxAttempts: integer("max_attempts").default(5).notNull(),
    error: text("error"),
    startedAt: timestamp("started_at"),
    finishedAt: timestamp("finished_at"),
    nextRunAt: timestamp("next_run_at").defaultNow().notNull(),
    createdAt: timestamp("created_at").defaultNow().notNull(),
    updatedAt: timestamp("updated_at").defaultNow().notNull(),
}, (t) => ({
    storeIdx: index("idx_sync_jobs_store").on(t.storeId),
    statusIdx: index("idx_sync_jobs_status").on(t.status),
}));

export type SyncJob = typeof syncJobs.$inferSelect;
export type NewSyncJob = typeof syncJobs.$inferInsert;