File size: 2,818 Bytes
1067b6f | 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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | // schema.ts
import { InferModel } from "drizzle-orm";
import {
boolean,
decimal,
int,
json,
mysqlTable,
serial,
text,
uniqueIndex,
varchar,
} from "drizzle-orm/mysql-core";
export const stores = mysqlTable(
"stores",
{
id: serial("id").primaryKey(),
name: varchar("store_name", { length: 40 }),
industry: text("industry"),
description: text("description"),
slug: varchar("slug", { length: 50 }),
},
(table) => {
return {
storeNameIndex: uniqueIndex("store_name_index").on(table.name),
storeSlugIndex: uniqueIndex("store_slug_index").on(table.slug),
};
}
);
export type Store = InferModel<typeof stores>;
export const products = mysqlTable("products", {
id: serial("id").primaryKey(),
name: text("name"),
price: decimal("price", { precision: 10, scale: 2 }).default("0"),
description: text("description"),
inventory: decimal("inventory").default("0"),
images: json("images"),
storeId: int("store_id"),
});
export type Product = InferModel<typeof products>;
export const carts = mysqlTable("carts", {
id: serial("id").primaryKey(),
items: json("items"),
paymentIntentId: text("payment_intent_id"),
clientSecret: text("client_secret"),
isClosed: boolean("is_closed").default(false),
});
export type Cart = InferModel<typeof carts>;
export const payments = mysqlTable("payments", {
id: serial("id").primaryKey(),
storeId: int("store_id"),
stripeAccountId: text("stripe_account_id"),
stripeAccountCreatedAt: int("stripe_account_created_at"),
stripeAccountExpiresAt: int("stripe_account_expires_at"),
details_submitted: boolean("details_submitted").default(false),
});
export type Payment = InferModel<typeof payments>;
export const orders = mysqlTable(
"orders",
{
id: serial("id").primaryKey(),
prettyOrderId: int("pretty_order_id"),
storeId: int("store_id"),
items: json("items"),
total: decimal("total", { precision: 10, scale: 2 }).default("0"),
stripePaymentIntentId: varchar("stripe_payment_intent_id", { length: 256 }), // text field is valid for uniqueIndex in MySQL
stripePaymentIntentStatus: text("stripe_payment_intent_status"),
name: text("name"),
email: text("email"),
createdAt: int("created_at"),
addressId: int("address"),
},
(table) => {
return {
stripePaymentIntentIdIndex: uniqueIndex(
"stripe_payment_intent_id_index"
).on(table.stripePaymentIntentId),
};
}
);
export type Order = InferModel<typeof orders>;
export const addresses = mysqlTable("addresses", {
id: serial("id").primaryKey(),
line1: text("line1"),
line2: text("line2"),
city: text("city"),
state: text("state"),
postal_code: text("postal_code"),
country: text("country"),
});
export type Address = InferModel<typeof addresses>;
|