export const purchaseOrderLineItem = createTable(
"purchase_order_line_item",
{
id: varchar("id", { length: 21 }).primaryKey().notNull(),
length: numeric("length").notNull(),
width: numeric("width"),
quantity: integer("quantity").notNull(),
lineItemCost: numeric("line_item_cost").notNull(),
purchaseOrderId: varchar("purchase_order_id", { length: 21 })
.notNull()
.references(() => purchaseOrder.id),
productId: text("product_id")
.notNull()
.references(() => product.id),
},
(table) => {
return {
uniqueProductIdLengthWidthForSamePOKey: uniqueIndex(
"product_id_length_width_purchase_order_id_key",
).on(table.productId, table.length, table.width, table.purchaseOrderId),
quantityMinZero: check("quantity_min_zero", gt(table.quantity, 0)),
};
},
);
export const purchaseOrderLineItem = createTable(
"purchase_order_line_item",
{
id: varchar("id", { length: 21 }).primaryKey().notNull(),
length: numeric("length").notNull(),
width: numeric("width"),
quantity: integer("quantity").notNull(),
lineItemCost: numeric("line_item_cost").notNull(),
purchaseOrderId: varchar("purchase_order_id", { length: 21 })
.notNull()
.references(() => purchaseOrder.id),
productId: text("product_id")
.notNull()
.references(() => product.id),
},
(table) => {
return {
uniqueProductIdLengthWidthForSamePOKey: uniqueIndex(
"product_id_length_width_purchase_order_id_key",
).on(table.productId, table.length, table.width, table.purchaseOrderId),
quantityMinZero: check("quantity_min_zero", gt(table.quantity, 0)),
};
},
);