forked from sadmann7/skateshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
179 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,11 @@ | ||
import { env } from "@/env.js" | ||
import { type Config } from "drizzle-kit" | ||
|
||
import { dbPrefix } from "@/lib/constants" | ||
|
||
export default { | ||
schema: "./src/db/schema/index.ts", | ||
dialect: "postgresql", | ||
out: "./drizzle", | ||
dbCredentials: { | ||
url: env.DATABASE_URL, | ||
}, | ||
tablesFilter: [`${dbPrefix}_*`], | ||
} satisfies Config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { relations } from "drizzle-orm" | ||
import { index, pgTable, varchar } from "drizzle-orm/pg-core" | ||
|
||
import { products } from "./products" | ||
import { tags } from "./tags" | ||
import { lifecycleDates } from "./utils" | ||
|
||
export const productTags = pgTable( | ||
"product_tags", | ||
{ | ||
productId: varchar("product_id", { length: 30 }) | ||
.references(() => products.id, { onDelete: "cascade" }) | ||
.notNull(), | ||
tagId: varchar("tag_id", { length: 30 }) | ||
.references(() => tags.id, { onDelete: "cascade" }) | ||
.notNull(), | ||
...lifecycleDates, | ||
}, | ||
(table) => ({ | ||
productTagIdx: index("product_tags_product_id_tag_id_idx").on( | ||
table.productId, | ||
table.tagId | ||
), | ||
}) | ||
) | ||
|
||
export const productTagsRelations = relations(productTags, ({ one }) => ({ | ||
product: one(products, { | ||
fields: [productTags.productId], | ||
references: [products.id], | ||
}), | ||
tag: one(tags, { fields: [productTags.tagId], references: [tags.id] }), | ||
})) | ||
|
||
export type ProductTag = typeof productTags.$inferSelect | ||
export type NewProductTag = typeof productTags.$inferInsert |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { relations } from "drizzle-orm" | ||
import { decimal, index, integer, pgTable, varchar } from "drizzle-orm/pg-core" | ||
|
||
import { generateId } from "@/lib/id" | ||
|
||
import { products } from "./products" | ||
import { lifecycleDates } from "./utils" | ||
|
||
export const productVariants = pgTable( | ||
"product_variants", | ||
{ | ||
id: varchar("id", { length: 30 }) | ||
.$defaultFn(() => generateId()) | ||
.primaryKey(), | ||
productId: varchar("product_id", { length: 30 }) | ||
.references(() => products.id, { onDelete: "cascade" }) | ||
.notNull(), | ||
name: varchar("name", { length: 256 }).notNull(), | ||
price: decimal("price", { precision: 10, scale: 2 }).notNull().default("0"), | ||
quantity: integer("quantity").notNull().default(0), | ||
...lifecycleDates, | ||
}, | ||
(table) => ({ | ||
productIdIdx: index("product_variants_product_id_idx").on(table.productId), | ||
}) | ||
) | ||
|
||
export const productVariantsRelations = relations( | ||
productVariants, | ||
({ one }) => ({ | ||
product: one(products, { | ||
fields: [productVariants.productId], | ||
references: [products.id], | ||
}), | ||
}) | ||
) | ||
|
||
export type ProductVariant = typeof productVariants.$inferSelect | ||
export type NewProductVariant = typeof productVariants.$inferInsert |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { relations } from "drizzle-orm" | ||
import { index, pgTable, varchar } from "drizzle-orm/pg-core" | ||
|
||
import { generateId } from "@/lib/id" | ||
|
||
import { products } from "./products" | ||
import { stores } from "./stores" | ||
|
||
export const tags = pgTable( | ||
"tags", | ||
{ | ||
id: varchar("id", { length: 30 }) | ||
.$defaultFn(() => generateId()) | ||
.primaryKey(), | ||
name: varchar("name", { length: 50 }).notNull(), | ||
color: varchar("color", { length: 50 }).notNull().default("#000000"), | ||
storeId: varchar("store_id", { length: 30 }) | ||
.references(() => stores.id, { onDelete: "cascade" }) | ||
.notNull(), | ||
}, | ||
(table) => ({ | ||
storeIdIdx: index("tags_store_id_idx").on(table.storeId), | ||
}) | ||
) | ||
|
||
export const tagsRelations = relations(tags, ({ one, many }) => ({ | ||
store: one(stores, { fields: [tags.storeId], references: [stores.id] }), | ||
products: many(products, { | ||
relationName: "productTags", | ||
}), | ||
})) | ||
|
||
export type Tag = typeof tags.$inferSelect | ||
export type NewTag = typeof tags.$inferInsert |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.