Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanniser committed Oct 18, 2024
2 parents 4e97afa + bc49880 commit 1cac9d5
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions src/db/schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { integer, numeric, pgTable, serial, text } from "drizzle-orm/pg-core";
import { sql } from "drizzle-orm";
import {
index,
integer,
numeric,
pgTable,
serial,
text,
} from "drizzle-orm/pg-core";
import { relations } from "drizzle-orm";

export const collections = pgTable("collections", {
Expand Down Expand Up @@ -38,15 +46,24 @@ export const subcategories = pgTable("subcategories", {

export type Subcategory = typeof subcategories.$inferSelect;

export const products = pgTable("products", {
slug: text("slug").notNull().primaryKey(),
name: text("name").notNull(),
description: text("description").notNull(),
price: numeric("price").notNull(),
subcategory_slug: text("subcategory_slug")
.notNull()
.references(() => subcategories.slug, { onDelete: "cascade" }),
});
export const products = pgTable(
"products",
{
slug: text("slug").notNull().primaryKey(),
name: text("name").notNull(),
description: text("description").notNull(),
price: numeric("price").notNull(),
subcategory_slug: text("subcategory_slug")
.notNull()
.references(() => subcategories.slug, { onDelete: "cascade" }),
},
(table) => ({
nameSearchIndex: index("name_search_index").using(
"gin",
sql`to_tsvector('english', ${table.name})`,
),
}),
);

export type Product = typeof products.$inferSelect;

Expand Down

0 comments on commit 1cac9d5

Please sign in to comment.