Spaces:
Sleeping

File size: 1,488 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, jsonb, timestamp, index, unique, numeric, integer } from "drizzle-orm/pg-core";
import { stores } from "../../../../../modules/shopify/infrastructure/postgres/schema/stores";
import { products } from "./products";

export const variants = pgTable("variants", {
    id: uuid("id").primaryKey().defaultRandom(),
    storeId: uuid("store_id").notNull().references(() => stores.id, { onDelete: "cascade" }),
    productId: uuid("product_id").notNull().references(() => products.id, { onDelete: "cascade" }),
    shopifyId: text("shopify_id").notNull(),
    title: text("title"),
    sku: text("sku"),
    price: numeric("price", { precision: 15, scale: 2 }),
    compareAtPrice: numeric("compare_at_price", { precision: 15, scale: 2 }),
    inventoryQuantity: integer("inventory_quantity"),
    data: jsonb("data").notNull(),
    createdAt: timestamp("created_at").defaultNow().notNull(),
    updatedAt: timestamp("updated_at").defaultNow().notNull(),
    shopifyCreatedAt: timestamp("shopify_created_at"),
    shopifyUpdatedAt: timestamp("shopify_updated_at"),
}, (t) => ({
    storeIdx: index("idx_variants_store").on(t.storeId),
    productIdx: index("idx_variants_product").on(t.productId),
    shopifyIdIdx: index("idx_variants_shopify_id").on(t.shopifyId),
    uniqueConstraint: unique("uq_variants_store_shopify").on(t.storeId, t.shopifyId),
}));

export type Variant = typeof variants.$inferSelect;
export type NewVariant = typeof variants.$inferInsert;