export const products = pgTable('products', {
id: serial().primaryKey(),
name: text().notNull(),
slug: text().notNull().unique(),
// VDE: SKU-Code, Cla-Val: Model
model: text().notNull(),
brand: text().notNull(),
// VDE Product does not have a description
description: text(),
categoryId: integer('category_id').notNull(),
keySpecs: json('key_specs').$type<Record<string, string>>().notNull().default({}),
specifications: json().$type<Record<string, string>>().notNull().default({}),
createdAt: timestamp('created_at', { precision: 3, mode: 'date' }).notNull().defaultNow(),
updatedAt: timestamp('updated_at', { precision: 3, mode: 'date' })
.notNull()
.defaultNow()
.$onUpdateFn(() => new Date())
})
export const productsRelations = relations(products, ({ one, many }) => ({
category: one(categories, {
fields: [products.categoryId],
references: [categories.id]
}),
images: many(images, {
relationName: 'productImages',
condition
})
}))
export const products = pgTable('products', {
id: serial().primaryKey(),
name: text().notNull(),
slug: text().notNull().unique(),
// VDE: SKU-Code, Cla-Val: Model
model: text().notNull(),
brand: text().notNull(),
// VDE Product does not have a description
description: text(),
categoryId: integer('category_id').notNull(),
keySpecs: json('key_specs').$type<Record<string, string>>().notNull().default({}),
specifications: json().$type<Record<string, string>>().notNull().default({}),
createdAt: timestamp('created_at', { precision: 3, mode: 'date' }).notNull().defaultNow(),
updatedAt: timestamp('updated_at', { precision: 3, mode: 'date' })
.notNull()
.defaultNow()
.$onUpdateFn(() => new Date())
})
export const productsRelations = relations(products, ({ one, many }) => ({
category: one(categories, {
fields: [products.categoryId],
references: [categories.id]
}),
images: many(images, {
relationName: 'productImages',
condition
})
}))