@nymbalhq/platform 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-74KODSYJ.js +2564 -0
- package/dist/chunk-74KODSYJ.js.map +1 -0
- package/dist/chunk-PW6ILJF7.js +740 -0
- package/dist/chunk-PW6ILJF7.js.map +1 -0
- package/dist/chunk-PZ5AY32C.js +10 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/db/schema/index.d.ts +10125 -0
- package/dist/db/schema/index.js +10 -0
- package/dist/db/schema/index.js.map +1 -0
- package/dist/index.d.ts +1372 -0
- package/dist/index.js +6652 -0
- package/dist/index.js.map +1 -0
- package/dist/register-IVFYBJSX.js +8 -0
- package/dist/register-IVFYBJSX.js.map +1 -0
- package/drizzle.config.postgres.ts +10 -0
- package/drizzle.config.sqlite.ts +10 -0
- package/migrations/postgres/0000_tearful_longshot.sql +166 -0
- package/migrations/postgres/0001_neat_zeigeist.sql +1 -0
- package/migrations/postgres/0002_sloppy_mad_thinker.sql +20 -0
- package/migrations/postgres/0003_violet_violations.sql +15 -0
- package/migrations/postgres/0004_white_reavers.sql +15 -0
- package/migrations/postgres/0005_natural_nico_minoru.sql +12 -0
- package/migrations/postgres/0006_minor_dragon_man.sql +28 -0
- package/migrations/postgres/meta/0000_snapshot.json +1172 -0
- package/migrations/postgres/meta/0001_snapshot.json +1187 -0
- package/migrations/postgres/meta/0002_snapshot.json +1325 -0
- package/migrations/postgres/meta/0003_snapshot.json +1432 -0
- package/migrations/postgres/meta/0004_snapshot.json +1439 -0
- package/migrations/postgres/meta/0005_snapshot.json +1461 -0
- package/migrations/postgres/meta/0006_snapshot.json +1598 -0
- package/migrations/postgres/meta/_journal.json +55 -0
- package/migrations/sqlite/0000_glorious_vision.sql +166 -0
- package/migrations/sqlite/0001_tricky_glorian.sql +1 -0
- package/migrations/sqlite/0002_puzzling_epoch.sql +19 -0
- package/migrations/sqlite/0003_fantastic_captain_stacy.sql +15 -0
- package/migrations/sqlite/0004_remarkable_shriek.sql +12 -0
- package/migrations/sqlite/0005_conscious_speedball.sql +13 -0
- package/migrations/sqlite/0006_flat_psylocke.sql +28 -0
- package/migrations/sqlite/meta/0000_snapshot.json +1093 -0
- package/migrations/sqlite/meta/0001_snapshot.json +1100 -0
- package/migrations/sqlite/meta/0002_snapshot.json +1222 -0
- package/migrations/sqlite/meta/0003_snapshot.json +1320 -0
- package/migrations/sqlite/meta/0004_snapshot.json +1328 -0
- package/migrations/sqlite/meta/0005_snapshot.json +1343 -0
- package/migrations/sqlite/meta/0006_snapshot.json +1470 -0
- package/migrations/sqlite/meta/_journal.json +55 -0
- package/package.json +69 -3
- package/README.md +0 -3
|
@@ -0,0 +1,740 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./chunk-PZ5AY32C.js";
|
|
4
|
+
|
|
5
|
+
// src/db/schema/sqlite.ts
|
|
6
|
+
var sqlite_exports = {};
|
|
7
|
+
__export(sqlite_exports, {
|
|
8
|
+
carts: () => carts,
|
|
9
|
+
categories: () => categories,
|
|
10
|
+
customers: () => customers,
|
|
11
|
+
events: () => events,
|
|
12
|
+
inventoryReservations: () => inventoryReservations,
|
|
13
|
+
orderHistory: () => orderHistory,
|
|
14
|
+
orderRefunds: () => orderRefunds,
|
|
15
|
+
orderSequences: () => orderSequences,
|
|
16
|
+
orders: () => orders,
|
|
17
|
+
processedEvents: () => processedEvents,
|
|
18
|
+
productCategories: () => productCategories,
|
|
19
|
+
products: () => products,
|
|
20
|
+
refreshTokens: () => refreshTokens,
|
|
21
|
+
reviews: () => reviews,
|
|
22
|
+
schema: () => schema,
|
|
23
|
+
stockAdjustments: () => stockAdjustments,
|
|
24
|
+
variants: () => variants
|
|
25
|
+
});
|
|
26
|
+
import { sql } from "drizzle-orm";
|
|
27
|
+
import { sqliteTable, text, integer, uniqueIndex, index, primaryKey } from "drizzle-orm/sqlite-core";
|
|
28
|
+
var categories = sqliteTable(
|
|
29
|
+
"categories",
|
|
30
|
+
{
|
|
31
|
+
id: text("id").primaryKey(),
|
|
32
|
+
parentId: text("parent_id"),
|
|
33
|
+
slug: text("slug").notNull(),
|
|
34
|
+
name: text("name").notNull(),
|
|
35
|
+
description: text("description").notNull().default(""),
|
|
36
|
+
position: integer("position").notNull().default(0),
|
|
37
|
+
createdAt: text("created_at").notNull()
|
|
38
|
+
},
|
|
39
|
+
(t) => ({
|
|
40
|
+
slugUnique: uniqueIndex("categories_slug_unique").on(t.slug),
|
|
41
|
+
parentIdx: index("categories_parent_idx").on(t.parentId)
|
|
42
|
+
})
|
|
43
|
+
);
|
|
44
|
+
var products = sqliteTable(
|
|
45
|
+
"products",
|
|
46
|
+
{
|
|
47
|
+
id: text("id").primaryKey(),
|
|
48
|
+
slug: text("slug").notNull(),
|
|
49
|
+
name: text("name").notNull(),
|
|
50
|
+
description: text("description").notNull().default(""),
|
|
51
|
+
shortDescription: text("short_description").notNull().default(""),
|
|
52
|
+
status: text("status", { enum: ["draft", "active", "archived"] }).notNull().default("draft"),
|
|
53
|
+
type: text("type", { enum: ["simple", "variable"] }).notNull().default("simple"),
|
|
54
|
+
seoTitle: text("seo_title").notNull().default(""),
|
|
55
|
+
seoDescription: text("seo_description").notNull().default(""),
|
|
56
|
+
media: text("media").notNull().default("[]"),
|
|
57
|
+
metadata: text("metadata").notNull().default("{}"),
|
|
58
|
+
createdAt: text("created_at").notNull(),
|
|
59
|
+
updatedAt: text("updated_at").notNull()
|
|
60
|
+
},
|
|
61
|
+
(t) => ({
|
|
62
|
+
slugUnique: uniqueIndex("products_slug_unique").on(t.slug),
|
|
63
|
+
statusIdx: index("products_status_idx").on(t.status)
|
|
64
|
+
})
|
|
65
|
+
);
|
|
66
|
+
var variants = sqliteTable(
|
|
67
|
+
"variants",
|
|
68
|
+
{
|
|
69
|
+
id: text("id").primaryKey(),
|
|
70
|
+
productId: text("product_id").notNull(),
|
|
71
|
+
sku: text("sku").notNull(),
|
|
72
|
+
name: text("name").notNull().default(""),
|
|
73
|
+
priceMinor: integer("price_minor").notNull(),
|
|
74
|
+
compareAtPriceMinor: integer("compare_at_price_minor"),
|
|
75
|
+
weightGrams: integer("weight_grams"),
|
|
76
|
+
dimensions: text("dimensions"),
|
|
77
|
+
stock: integer("stock").notNull().default(0),
|
|
78
|
+
lowStockThreshold: integer("low_stock_threshold").notNull().default(0),
|
|
79
|
+
options: text("options").notNull().default("[]"),
|
|
80
|
+
status: text("status", { enum: ["active", "inactive"] }).notNull().default("active"),
|
|
81
|
+
createdAt: text("created_at").notNull(),
|
|
82
|
+
updatedAt: text("updated_at").notNull()
|
|
83
|
+
},
|
|
84
|
+
(t) => ({
|
|
85
|
+
skuUnique: uniqueIndex("variants_sku_unique").on(t.sku),
|
|
86
|
+
productIdx: index("variants_product_idx").on(t.productId)
|
|
87
|
+
})
|
|
88
|
+
);
|
|
89
|
+
var productCategories = sqliteTable(
|
|
90
|
+
"product_categories",
|
|
91
|
+
{
|
|
92
|
+
productId: text("product_id").notNull(),
|
|
93
|
+
categoryId: text("category_id").notNull()
|
|
94
|
+
},
|
|
95
|
+
(t) => ({
|
|
96
|
+
pk: primaryKey({ columns: [t.productId, t.categoryId] }),
|
|
97
|
+
categoryIdx: index("product_categories_category_idx").on(t.categoryId)
|
|
98
|
+
})
|
|
99
|
+
);
|
|
100
|
+
var customers = sqliteTable(
|
|
101
|
+
"customers",
|
|
102
|
+
{
|
|
103
|
+
id: text("id").primaryKey(),
|
|
104
|
+
email: text("email").notNull(),
|
|
105
|
+
passwordHash: text("password_hash").notNull(),
|
|
106
|
+
firstName: text("first_name").notNull().default(""),
|
|
107
|
+
lastName: text("last_name").notNull().default(""),
|
|
108
|
+
phone: text("phone").notNull().default(""),
|
|
109
|
+
addresses: text("addresses").notNull().default("[]"),
|
|
110
|
+
orderCount: integer("order_count").notNull().default(0),
|
|
111
|
+
totalSpentMinor: integer("total_spent_minor").notNull().default(0),
|
|
112
|
+
metadata: text("metadata").notNull().default("{}"),
|
|
113
|
+
roles: text("roles").notNull().default('["customer"]'),
|
|
114
|
+
requiresPasswordReset: integer("requires_password_reset", { mode: "boolean" }).notNull().default(false),
|
|
115
|
+
createdAt: text("created_at").notNull(),
|
|
116
|
+
updatedAt: text("updated_at").notNull()
|
|
117
|
+
},
|
|
118
|
+
(t) => ({
|
|
119
|
+
emailUnique: uniqueIndex("customers_email_unique").on(t.email)
|
|
120
|
+
})
|
|
121
|
+
);
|
|
122
|
+
var refreshTokens = sqliteTable(
|
|
123
|
+
"refresh_tokens",
|
|
124
|
+
{
|
|
125
|
+
id: text("id").primaryKey(),
|
|
126
|
+
customerId: text("customer_id").notNull(),
|
|
127
|
+
tokenHash: text("token_hash").notNull(),
|
|
128
|
+
revokedAt: text("revoked_at"),
|
|
129
|
+
replacedByJti: text("replaced_by_jti"),
|
|
130
|
+
expiresAt: text("expires_at").notNull(),
|
|
131
|
+
createdAt: text("created_at").notNull()
|
|
132
|
+
},
|
|
133
|
+
(t) => ({
|
|
134
|
+
customerIdx: index("refresh_tokens_customer_idx").on(t.customerId)
|
|
135
|
+
})
|
|
136
|
+
);
|
|
137
|
+
var orders = sqliteTable(
|
|
138
|
+
"orders",
|
|
139
|
+
{
|
|
140
|
+
id: text("id").primaryKey(),
|
|
141
|
+
orderNumber: text("order_number").notNull(),
|
|
142
|
+
sequence: integer("sequence").notNull(),
|
|
143
|
+
customerId: text("customer_id"),
|
|
144
|
+
status: text("status", {
|
|
145
|
+
enum: [
|
|
146
|
+
"pending",
|
|
147
|
+
"confirmed",
|
|
148
|
+
"processing",
|
|
149
|
+
"shipped",
|
|
150
|
+
"delivered",
|
|
151
|
+
"cancelled",
|
|
152
|
+
"refunded",
|
|
153
|
+
"partially_refunded"
|
|
154
|
+
]
|
|
155
|
+
}).notNull().default("pending"),
|
|
156
|
+
email: text("email").notNull(),
|
|
157
|
+
billingAddress: text("billing_address").notNull(),
|
|
158
|
+
shippingAddress: text("shipping_address").notNull(),
|
|
159
|
+
lineItems: text("line_items").notNull(),
|
|
160
|
+
subtotalMinor: integer("subtotal_minor").notNull(),
|
|
161
|
+
taxTotalMinor: integer("tax_total_minor").notNull().default(0),
|
|
162
|
+
shippingTotalMinor: integer("shipping_total_minor").notNull().default(0),
|
|
163
|
+
discountTotalMinor: integer("discount_total_minor").notNull().default(0),
|
|
164
|
+
totalMinor: integer("total_minor").notNull(),
|
|
165
|
+
currency: text("currency").notNull(),
|
|
166
|
+
notes: text("notes").notNull().default(""),
|
|
167
|
+
metadata: text("metadata").notNull().default("{}"),
|
|
168
|
+
paymentIntentId: text("payment_intent_id"),
|
|
169
|
+
/** The cart the order was placed from; null for imported orders. */
|
|
170
|
+
cartToken: text("cart_token"),
|
|
171
|
+
capturedMinor: integer("captured_minor").notNull().default(0),
|
|
172
|
+
capturedAt: text("captured_at"),
|
|
173
|
+
/** Σ of the succeeded `order_refunds`, written in the transaction that settles each. */
|
|
174
|
+
refundedMinor: integer("refunded_minor").notNull().default(0),
|
|
175
|
+
captureMethod: text("capture_method", { enum: ["provider", "manual", "import"] }),
|
|
176
|
+
createdAt: text("created_at").notNull(),
|
|
177
|
+
updatedAt: text("updated_at").notNull()
|
|
178
|
+
},
|
|
179
|
+
(t) => ({
|
|
180
|
+
numberUnique: uniqueIndex("orders_number_unique").on(t.orderNumber),
|
|
181
|
+
sequenceUnique: uniqueIndex("orders_sequence_unique").on(t.sequence),
|
|
182
|
+
customerIdx: index("orders_customer_idx").on(t.customerId),
|
|
183
|
+
statusIdx: index("orders_status_idx").on(t.status),
|
|
184
|
+
paymentIntentIdx: index("orders_payment_intent_idx").on(t.paymentIntentId),
|
|
185
|
+
// One pending order per cart, whatever the checkout's lock does.
|
|
186
|
+
pendingCartUnique: uniqueIndex("orders_pending_cart_unique").on(t.cartToken).where(sql`status = 'pending'`)
|
|
187
|
+
})
|
|
188
|
+
);
|
|
189
|
+
var orderHistory = sqliteTable(
|
|
190
|
+
"order_history",
|
|
191
|
+
{
|
|
192
|
+
id: text("id").primaryKey(),
|
|
193
|
+
orderId: text("order_id").notNull(),
|
|
194
|
+
fromStatus: text("from_status"),
|
|
195
|
+
toStatus: text("to_status").notNull(),
|
|
196
|
+
actor: text("actor").notNull(),
|
|
197
|
+
note: text("note").notNull().default(""),
|
|
198
|
+
timestamp: text("timestamp").notNull()
|
|
199
|
+
},
|
|
200
|
+
(t) => ({
|
|
201
|
+
orderIdx: index("order_history_order_idx").on(t.orderId)
|
|
202
|
+
})
|
|
203
|
+
);
|
|
204
|
+
var orderRefunds = sqliteTable(
|
|
205
|
+
"order_refunds",
|
|
206
|
+
{
|
|
207
|
+
id: text("id").primaryKey(),
|
|
208
|
+
orderId: text("order_id").notNull(),
|
|
209
|
+
amountMinor: integer("amount_minor").notNull(),
|
|
210
|
+
currency: text("currency").notNull(),
|
|
211
|
+
providerRefundId: text("provider_refund_id"),
|
|
212
|
+
status: text("status", { enum: ["pending", "succeeded", "failed"] }).notNull().default("pending"),
|
|
213
|
+
reason: text("reason"),
|
|
214
|
+
actor: text("actor").notNull(),
|
|
215
|
+
createdAt: text("created_at").notNull(),
|
|
216
|
+
/** The client's key for one refund request: a repeat of it on the order answers the refund it made. */
|
|
217
|
+
requestId: text("request_id")
|
|
218
|
+
},
|
|
219
|
+
(t) => ({
|
|
220
|
+
orderIdx: index("order_refunds_order_idx").on(t.orderId),
|
|
221
|
+
requestIdx: uniqueIndex("order_refunds_order_request_idx").on(t.orderId, t.requestId)
|
|
222
|
+
})
|
|
223
|
+
);
|
|
224
|
+
var orderSequences = sqliteTable("order_sequences", {
|
|
225
|
+
id: integer("id").primaryKey(),
|
|
226
|
+
nextValue: integer("next_value").notNull()
|
|
227
|
+
});
|
|
228
|
+
var inventoryReservations = sqliteTable(
|
|
229
|
+
"inventory_reservations",
|
|
230
|
+
{
|
|
231
|
+
reservationId: text("reservation_id").primaryKey(),
|
|
232
|
+
variantId: text("variant_id").notNull(),
|
|
233
|
+
qty: integer("qty").notNull(),
|
|
234
|
+
orderRef: text("order_ref"),
|
|
235
|
+
expiresAt: text("expires_at").notNull(),
|
|
236
|
+
createdAt: text("created_at").notNull()
|
|
237
|
+
},
|
|
238
|
+
(t) => ({
|
|
239
|
+
variantIdx: index("inv_reservations_variant_idx").on(t.variantId),
|
|
240
|
+
expiresIdx: index("inv_reservations_expires_idx").on(t.expiresAt)
|
|
241
|
+
})
|
|
242
|
+
);
|
|
243
|
+
var stockAdjustments = sqliteTable(
|
|
244
|
+
"stock_adjustments",
|
|
245
|
+
{
|
|
246
|
+
id: text("id").primaryKey(),
|
|
247
|
+
variantId: text("variant_id").notNull(),
|
|
248
|
+
adjustment: integer("adjustment").notNull(),
|
|
249
|
+
reason: text("reason", {
|
|
250
|
+
enum: ["sale", "return", "manual", "import", "reservation-commit", "reservation-release"]
|
|
251
|
+
}).notNull(),
|
|
252
|
+
actor: text("actor").notNull(),
|
|
253
|
+
previousQty: integer("previous_qty").notNull(),
|
|
254
|
+
newQty: integer("new_qty").notNull(),
|
|
255
|
+
timestamp: text("timestamp").notNull()
|
|
256
|
+
},
|
|
257
|
+
(t) => ({
|
|
258
|
+
variantIdx: index("stock_adjustments_variant_idx").on(t.variantId)
|
|
259
|
+
})
|
|
260
|
+
);
|
|
261
|
+
var reviews = sqliteTable(
|
|
262
|
+
"reviews",
|
|
263
|
+
{
|
|
264
|
+
id: text("id").primaryKey(),
|
|
265
|
+
productId: text("product_id").notNull(),
|
|
266
|
+
customerId: text("customer_id"),
|
|
267
|
+
orderId: text("order_id"),
|
|
268
|
+
rating: integer("rating").notNull(),
|
|
269
|
+
title: text("title").notNull().default(""),
|
|
270
|
+
body: text("body").notNull().default(""),
|
|
271
|
+
moderationStatus: text("moderation_status", {
|
|
272
|
+
enum: ["pending", "approved", "rejected"]
|
|
273
|
+
}).notNull().default("pending"),
|
|
274
|
+
submittedAt: text("submitted_at").notNull(),
|
|
275
|
+
moderatedAt: text("moderated_at"),
|
|
276
|
+
moderatedBy: text("moderated_by")
|
|
277
|
+
},
|
|
278
|
+
(t) => ({
|
|
279
|
+
productIdx: index("reviews_product_idx").on(t.productId),
|
|
280
|
+
statusIdx: index("reviews_status_idx").on(t.moderationStatus)
|
|
281
|
+
})
|
|
282
|
+
);
|
|
283
|
+
var carts = sqliteTable(
|
|
284
|
+
"carts",
|
|
285
|
+
{
|
|
286
|
+
token: text("token").primaryKey(),
|
|
287
|
+
customerId: text("customer_id"),
|
|
288
|
+
currency: text("currency").notNull(),
|
|
289
|
+
items: text("items").notNull().default("[]"),
|
|
290
|
+
lineCount: integer("line_count").notNull().default(0),
|
|
291
|
+
subtotalMinor: integer("subtotal_minor").notNull().default(0),
|
|
292
|
+
expiresAt: text("expires_at").notNull(),
|
|
293
|
+
createdAt: text("created_at").notNull(),
|
|
294
|
+
updatedAt: text("updated_at").notNull(),
|
|
295
|
+
/** Set by the abandonment sweeper's claim; every cart write clears it, starting a new inactivity period. */
|
|
296
|
+
abandonedNotifiedAt: text("abandoned_notified_at")
|
|
297
|
+
},
|
|
298
|
+
(t) => ({
|
|
299
|
+
expiresIdx: index("carts_expires_idx").on(t.expiresAt),
|
|
300
|
+
updatedIdx: index("carts_updated_idx").on(t.updatedAt)
|
|
301
|
+
})
|
|
302
|
+
);
|
|
303
|
+
var events = sqliteTable(
|
|
304
|
+
"events",
|
|
305
|
+
{
|
|
306
|
+
seq: integer("seq").primaryKey({ autoIncrement: true }),
|
|
307
|
+
id: text("id").notNull(),
|
|
308
|
+
type: text("type").notNull(),
|
|
309
|
+
envelope: text("envelope").notNull(),
|
|
310
|
+
createdAt: text("created_at").notNull(),
|
|
311
|
+
deliveredAt: text("delivered_at"),
|
|
312
|
+
attempts: integer("attempts").notNull().default(0),
|
|
313
|
+
deadAt: text("dead_at")
|
|
314
|
+
},
|
|
315
|
+
(t) => ({
|
|
316
|
+
idUnique: uniqueIndex("events_id_unique").on(t.id),
|
|
317
|
+
undeliveredIdx: index("events_undelivered_idx").on(t.deliveredAt, t.seq)
|
|
318
|
+
})
|
|
319
|
+
);
|
|
320
|
+
var processedEvents = sqliteTable(
|
|
321
|
+
"processed_events",
|
|
322
|
+
{
|
|
323
|
+
handlerName: text("handler_name").notNull(),
|
|
324
|
+
eventId: text("event_id").notNull(),
|
|
325
|
+
processedAt: text("processed_at").notNull()
|
|
326
|
+
},
|
|
327
|
+
(t) => ({
|
|
328
|
+
pk: primaryKey({ columns: [t.handlerName, t.eventId] })
|
|
329
|
+
})
|
|
330
|
+
);
|
|
331
|
+
var schema = {
|
|
332
|
+
categories,
|
|
333
|
+
products,
|
|
334
|
+
variants,
|
|
335
|
+
productCategories,
|
|
336
|
+
customers,
|
|
337
|
+
refreshTokens,
|
|
338
|
+
orders,
|
|
339
|
+
orderHistory,
|
|
340
|
+
orderSequences,
|
|
341
|
+
inventoryReservations,
|
|
342
|
+
stockAdjustments,
|
|
343
|
+
reviews,
|
|
344
|
+
carts,
|
|
345
|
+
events,
|
|
346
|
+
processedEvents
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
// src/db/schema/postgres.ts
|
|
350
|
+
var postgres_exports = {};
|
|
351
|
+
__export(postgres_exports, {
|
|
352
|
+
carts: () => carts2,
|
|
353
|
+
categories: () => categories2,
|
|
354
|
+
customers: () => customers2,
|
|
355
|
+
events: () => events2,
|
|
356
|
+
inventoryReservations: () => inventoryReservations2,
|
|
357
|
+
orderHistory: () => orderHistory2,
|
|
358
|
+
orderRefunds: () => orderRefunds2,
|
|
359
|
+
orderSequences: () => orderSequences2,
|
|
360
|
+
orders: () => orders2,
|
|
361
|
+
processedEvents: () => processedEvents2,
|
|
362
|
+
productCategories: () => productCategories2,
|
|
363
|
+
products: () => products2,
|
|
364
|
+
refreshTokens: () => refreshTokens2,
|
|
365
|
+
reviews: () => reviews2,
|
|
366
|
+
schema: () => schema2,
|
|
367
|
+
stockAdjustments: () => stockAdjustments2,
|
|
368
|
+
variants: () => variants2
|
|
369
|
+
});
|
|
370
|
+
import { sql as sql2 } from "drizzle-orm";
|
|
371
|
+
import {
|
|
372
|
+
pgTable,
|
|
373
|
+
bigserial,
|
|
374
|
+
text as text2,
|
|
375
|
+
integer as integer2,
|
|
376
|
+
timestamp,
|
|
377
|
+
jsonb,
|
|
378
|
+
boolean,
|
|
379
|
+
uniqueIndex as uniqueIndex2,
|
|
380
|
+
index as index2,
|
|
381
|
+
primaryKey as primaryKey2
|
|
382
|
+
} from "drizzle-orm/pg-core";
|
|
383
|
+
var categories2 = pgTable(
|
|
384
|
+
"categories",
|
|
385
|
+
{
|
|
386
|
+
id: text2("id").primaryKey(),
|
|
387
|
+
parentId: text2("parent_id"),
|
|
388
|
+
slug: text2("slug").notNull(),
|
|
389
|
+
name: text2("name").notNull(),
|
|
390
|
+
description: text2("description").notNull().default(""),
|
|
391
|
+
position: integer2("position").notNull().default(0),
|
|
392
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull()
|
|
393
|
+
},
|
|
394
|
+
(t) => ({
|
|
395
|
+
slugUnique: uniqueIndex2("categories_slug_unique").on(t.slug),
|
|
396
|
+
parentIdx: index2("categories_parent_idx").on(t.parentId)
|
|
397
|
+
})
|
|
398
|
+
);
|
|
399
|
+
var products2 = pgTable(
|
|
400
|
+
"products",
|
|
401
|
+
{
|
|
402
|
+
id: text2("id").primaryKey(),
|
|
403
|
+
slug: text2("slug").notNull(),
|
|
404
|
+
name: text2("name").notNull(),
|
|
405
|
+
description: text2("description").notNull().default(""),
|
|
406
|
+
shortDescription: text2("short_description").notNull().default(""),
|
|
407
|
+
status: text2("status", { enum: ["draft", "active", "archived"] }).notNull().default("draft"),
|
|
408
|
+
type: text2("type", { enum: ["simple", "variable"] }).notNull().default("simple"),
|
|
409
|
+
seoTitle: text2("seo_title").notNull().default(""),
|
|
410
|
+
seoDescription: text2("seo_description").notNull().default(""),
|
|
411
|
+
media: jsonb("media").notNull().default([]),
|
|
412
|
+
metadata: jsonb("metadata").notNull().default({}),
|
|
413
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
|
|
414
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull()
|
|
415
|
+
},
|
|
416
|
+
(t) => ({
|
|
417
|
+
slugUnique: uniqueIndex2("products_slug_unique").on(t.slug),
|
|
418
|
+
statusIdx: index2("products_status_idx").on(t.status)
|
|
419
|
+
})
|
|
420
|
+
);
|
|
421
|
+
var variants2 = pgTable(
|
|
422
|
+
"variants",
|
|
423
|
+
{
|
|
424
|
+
id: text2("id").primaryKey(),
|
|
425
|
+
productId: text2("product_id").notNull(),
|
|
426
|
+
sku: text2("sku").notNull(),
|
|
427
|
+
name: text2("name").notNull().default(""),
|
|
428
|
+
priceMinor: integer2("price_minor").notNull(),
|
|
429
|
+
compareAtPriceMinor: integer2("compare_at_price_minor"),
|
|
430
|
+
weightGrams: integer2("weight_grams"),
|
|
431
|
+
dimensions: jsonb("dimensions"),
|
|
432
|
+
stock: integer2("stock").notNull().default(0),
|
|
433
|
+
lowStockThreshold: integer2("low_stock_threshold").notNull().default(0),
|
|
434
|
+
options: jsonb("options").notNull().default([]),
|
|
435
|
+
status: text2("status", { enum: ["active", "inactive"] }).notNull().default("active"),
|
|
436
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
|
|
437
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull()
|
|
438
|
+
},
|
|
439
|
+
(t) => ({
|
|
440
|
+
skuUnique: uniqueIndex2("variants_sku_unique").on(t.sku),
|
|
441
|
+
productIdx: index2("variants_product_idx").on(t.productId)
|
|
442
|
+
})
|
|
443
|
+
);
|
|
444
|
+
var productCategories2 = pgTable(
|
|
445
|
+
"product_categories",
|
|
446
|
+
{
|
|
447
|
+
productId: text2("product_id").notNull(),
|
|
448
|
+
categoryId: text2("category_id").notNull()
|
|
449
|
+
},
|
|
450
|
+
(t) => ({
|
|
451
|
+
pk: primaryKey2({ columns: [t.productId, t.categoryId] }),
|
|
452
|
+
categoryIdx: index2("product_categories_category_idx").on(t.categoryId)
|
|
453
|
+
})
|
|
454
|
+
);
|
|
455
|
+
var customers2 = pgTable(
|
|
456
|
+
"customers",
|
|
457
|
+
{
|
|
458
|
+
id: text2("id").primaryKey(),
|
|
459
|
+
email: text2("email").notNull(),
|
|
460
|
+
passwordHash: text2("password_hash").notNull(),
|
|
461
|
+
firstName: text2("first_name").notNull().default(""),
|
|
462
|
+
lastName: text2("last_name").notNull().default(""),
|
|
463
|
+
phone: text2("phone").notNull().default(""),
|
|
464
|
+
addresses: jsonb("addresses").notNull().default([]),
|
|
465
|
+
orderCount: integer2("order_count").notNull().default(0),
|
|
466
|
+
totalSpentMinor: integer2("total_spent_minor").notNull().default(0),
|
|
467
|
+
metadata: jsonb("metadata").notNull().default({}),
|
|
468
|
+
roles: jsonb("roles").notNull().default(["customer"]),
|
|
469
|
+
requiresPasswordReset: boolean("requires_password_reset").notNull().default(false),
|
|
470
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
|
|
471
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull()
|
|
472
|
+
},
|
|
473
|
+
(t) => ({
|
|
474
|
+
emailUnique: uniqueIndex2("customers_email_unique").on(t.email)
|
|
475
|
+
})
|
|
476
|
+
);
|
|
477
|
+
var refreshTokens2 = pgTable(
|
|
478
|
+
"refresh_tokens",
|
|
479
|
+
{
|
|
480
|
+
id: text2("id").primaryKey(),
|
|
481
|
+
customerId: text2("customer_id").notNull(),
|
|
482
|
+
tokenHash: text2("token_hash").notNull(),
|
|
483
|
+
revokedAt: timestamp("revoked_at", { withTimezone: true }),
|
|
484
|
+
replacedByJti: text2("replaced_by_jti"),
|
|
485
|
+
expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
|
|
486
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull()
|
|
487
|
+
},
|
|
488
|
+
(t) => ({
|
|
489
|
+
customerIdx: index2("refresh_tokens_customer_idx").on(t.customerId)
|
|
490
|
+
})
|
|
491
|
+
);
|
|
492
|
+
var orders2 = pgTable(
|
|
493
|
+
"orders",
|
|
494
|
+
{
|
|
495
|
+
id: text2("id").primaryKey(),
|
|
496
|
+
orderNumber: text2("order_number").notNull(),
|
|
497
|
+
sequence: integer2("sequence").notNull(),
|
|
498
|
+
customerId: text2("customer_id"),
|
|
499
|
+
status: text2("status", {
|
|
500
|
+
enum: [
|
|
501
|
+
"pending",
|
|
502
|
+
"confirmed",
|
|
503
|
+
"processing",
|
|
504
|
+
"shipped",
|
|
505
|
+
"delivered",
|
|
506
|
+
"cancelled",
|
|
507
|
+
"refunded",
|
|
508
|
+
"partially_refunded"
|
|
509
|
+
]
|
|
510
|
+
}).notNull().default("pending"),
|
|
511
|
+
email: text2("email").notNull(),
|
|
512
|
+
billingAddress: jsonb("billing_address").notNull(),
|
|
513
|
+
shippingAddress: jsonb("shipping_address").notNull(),
|
|
514
|
+
lineItems: jsonb("line_items").notNull(),
|
|
515
|
+
subtotalMinor: integer2("subtotal_minor").notNull(),
|
|
516
|
+
taxTotalMinor: integer2("tax_total_minor").notNull().default(0),
|
|
517
|
+
shippingTotalMinor: integer2("shipping_total_minor").notNull().default(0),
|
|
518
|
+
discountTotalMinor: integer2("discount_total_minor").notNull().default(0),
|
|
519
|
+
totalMinor: integer2("total_minor").notNull(),
|
|
520
|
+
currency: text2("currency").notNull(),
|
|
521
|
+
notes: text2("notes").notNull().default(""),
|
|
522
|
+
metadata: jsonb("metadata").notNull().default({}),
|
|
523
|
+
paymentIntentId: text2("payment_intent_id"),
|
|
524
|
+
/** The cart the order was placed from; null for imported orders. */
|
|
525
|
+
cartToken: text2("cart_token"),
|
|
526
|
+
capturedMinor: integer2("captured_minor").notNull().default(0),
|
|
527
|
+
capturedAt: timestamp("captured_at", { withTimezone: true }),
|
|
528
|
+
/** Σ of the succeeded `order_refunds`, written in the transaction that settles each. */
|
|
529
|
+
refundedMinor: integer2("refunded_minor").notNull().default(0),
|
|
530
|
+
captureMethod: text2("capture_method", { enum: ["provider", "manual", "import"] }),
|
|
531
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
|
|
532
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull()
|
|
533
|
+
},
|
|
534
|
+
(t) => ({
|
|
535
|
+
numberUnique: uniqueIndex2("orders_number_unique").on(t.orderNumber),
|
|
536
|
+
sequenceUnique: uniqueIndex2("orders_sequence_unique").on(t.sequence),
|
|
537
|
+
customerIdx: index2("orders_customer_idx").on(t.customerId),
|
|
538
|
+
statusIdx: index2("orders_status_idx").on(t.status),
|
|
539
|
+
paymentIntentIdx: index2("orders_payment_intent_idx").on(t.paymentIntentId),
|
|
540
|
+
// One pending order per cart, whatever the checkout's lock does.
|
|
541
|
+
pendingCartUnique: uniqueIndex2("orders_pending_cart_unique").on(t.cartToken).where(sql2`status = 'pending'`)
|
|
542
|
+
})
|
|
543
|
+
);
|
|
544
|
+
var orderHistory2 = pgTable(
|
|
545
|
+
"order_history",
|
|
546
|
+
{
|
|
547
|
+
id: text2("id").primaryKey(),
|
|
548
|
+
orderId: text2("order_id").notNull(),
|
|
549
|
+
fromStatus: text2("from_status"),
|
|
550
|
+
toStatus: text2("to_status").notNull(),
|
|
551
|
+
actor: text2("actor").notNull(),
|
|
552
|
+
note: text2("note").notNull().default(""),
|
|
553
|
+
timestamp: timestamp("timestamp", { withTimezone: true }).notNull()
|
|
554
|
+
},
|
|
555
|
+
(t) => ({
|
|
556
|
+
orderIdx: index2("order_history_order_idx").on(t.orderId)
|
|
557
|
+
})
|
|
558
|
+
);
|
|
559
|
+
var orderRefunds2 = pgTable(
|
|
560
|
+
"order_refunds",
|
|
561
|
+
{
|
|
562
|
+
id: text2("id").primaryKey(),
|
|
563
|
+
orderId: text2("order_id").notNull(),
|
|
564
|
+
amountMinor: integer2("amount_minor").notNull(),
|
|
565
|
+
currency: text2("currency").notNull(),
|
|
566
|
+
providerRefundId: text2("provider_refund_id"),
|
|
567
|
+
status: text2("status", { enum: ["pending", "succeeded", "failed"] }).notNull().default("pending"),
|
|
568
|
+
reason: text2("reason"),
|
|
569
|
+
actor: text2("actor").notNull(),
|
|
570
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
|
|
571
|
+
/** The client's key for one refund request: a repeat of it on the order answers the refund it made. */
|
|
572
|
+
requestId: text2("request_id")
|
|
573
|
+
},
|
|
574
|
+
(t) => ({
|
|
575
|
+
orderIdx: index2("order_refunds_order_idx").on(t.orderId),
|
|
576
|
+
requestIdx: uniqueIndex2("order_refunds_order_request_idx").on(t.orderId, t.requestId)
|
|
577
|
+
})
|
|
578
|
+
);
|
|
579
|
+
var orderSequences2 = pgTable("order_sequences", {
|
|
580
|
+
id: integer2("id").primaryKey(),
|
|
581
|
+
nextValue: integer2("next_value").notNull()
|
|
582
|
+
});
|
|
583
|
+
var inventoryReservations2 = pgTable(
|
|
584
|
+
"inventory_reservations",
|
|
585
|
+
{
|
|
586
|
+
reservationId: text2("reservation_id").primaryKey(),
|
|
587
|
+
variantId: text2("variant_id").notNull(),
|
|
588
|
+
qty: integer2("qty").notNull(),
|
|
589
|
+
orderRef: text2("order_ref"),
|
|
590
|
+
expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
|
|
591
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull()
|
|
592
|
+
},
|
|
593
|
+
(t) => ({
|
|
594
|
+
variantIdx: index2("inv_reservations_variant_idx").on(t.variantId),
|
|
595
|
+
expiresIdx: index2("inv_reservations_expires_idx").on(t.expiresAt)
|
|
596
|
+
})
|
|
597
|
+
);
|
|
598
|
+
var stockAdjustments2 = pgTable(
|
|
599
|
+
"stock_adjustments",
|
|
600
|
+
{
|
|
601
|
+
id: text2("id").primaryKey(),
|
|
602
|
+
variantId: text2("variant_id").notNull(),
|
|
603
|
+
adjustment: integer2("adjustment").notNull(),
|
|
604
|
+
reason: text2("reason", {
|
|
605
|
+
enum: ["sale", "return", "manual", "import", "reservation-commit", "reservation-release"]
|
|
606
|
+
}).notNull(),
|
|
607
|
+
actor: text2("actor").notNull(),
|
|
608
|
+
previousQty: integer2("previous_qty").notNull(),
|
|
609
|
+
newQty: integer2("new_qty").notNull(),
|
|
610
|
+
timestamp: timestamp("timestamp", { withTimezone: true }).notNull()
|
|
611
|
+
},
|
|
612
|
+
(t) => ({
|
|
613
|
+
variantIdx: index2("stock_adjustments_variant_idx").on(t.variantId)
|
|
614
|
+
})
|
|
615
|
+
);
|
|
616
|
+
var reviews2 = pgTable(
|
|
617
|
+
"reviews",
|
|
618
|
+
{
|
|
619
|
+
id: text2("id").primaryKey(),
|
|
620
|
+
productId: text2("product_id").notNull(),
|
|
621
|
+
customerId: text2("customer_id"),
|
|
622
|
+
orderId: text2("order_id"),
|
|
623
|
+
rating: integer2("rating").notNull(),
|
|
624
|
+
title: text2("title").notNull().default(""),
|
|
625
|
+
body: text2("body").notNull().default(""),
|
|
626
|
+
moderationStatus: text2("moderation_status", {
|
|
627
|
+
enum: ["pending", "approved", "rejected"]
|
|
628
|
+
}).notNull().default("pending"),
|
|
629
|
+
submittedAt: timestamp("submitted_at", { withTimezone: true }).notNull(),
|
|
630
|
+
moderatedAt: timestamp("moderated_at", { withTimezone: true }),
|
|
631
|
+
moderatedBy: text2("moderated_by")
|
|
632
|
+
},
|
|
633
|
+
(t) => ({
|
|
634
|
+
productIdx: index2("reviews_product_idx").on(t.productId),
|
|
635
|
+
statusIdx: index2("reviews_status_idx").on(t.moderationStatus)
|
|
636
|
+
})
|
|
637
|
+
);
|
|
638
|
+
var carts2 = pgTable(
|
|
639
|
+
"carts",
|
|
640
|
+
{
|
|
641
|
+
token: text2("token").primaryKey(),
|
|
642
|
+
customerId: text2("customer_id"),
|
|
643
|
+
currency: text2("currency").notNull(),
|
|
644
|
+
items: jsonb("items").notNull().default([]),
|
|
645
|
+
lineCount: integer2("line_count").notNull().default(0),
|
|
646
|
+
subtotalMinor: integer2("subtotal_minor").notNull().default(0),
|
|
647
|
+
expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
|
|
648
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
|
|
649
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull(),
|
|
650
|
+
/** Set by the abandonment sweeper's claim; every cart write clears it, starting a new inactivity period. */
|
|
651
|
+
abandonedNotifiedAt: timestamp("abandoned_notified_at", { withTimezone: true })
|
|
652
|
+
},
|
|
653
|
+
(t) => ({
|
|
654
|
+
expiresIdx: index2("carts_expires_idx").on(t.expiresAt),
|
|
655
|
+
updatedIdx: index2("carts_updated_idx").on(t.updatedAt)
|
|
656
|
+
})
|
|
657
|
+
);
|
|
658
|
+
var events2 = pgTable(
|
|
659
|
+
"events",
|
|
660
|
+
{
|
|
661
|
+
seq: bigserial("seq", { mode: "number" }).primaryKey(),
|
|
662
|
+
id: text2("id").notNull(),
|
|
663
|
+
type: text2("type").notNull(),
|
|
664
|
+
envelope: jsonb("envelope").notNull(),
|
|
665
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
|
|
666
|
+
deliveredAt: timestamp("delivered_at", { withTimezone: true }),
|
|
667
|
+
attempts: integer2("attempts").notNull().default(0),
|
|
668
|
+
deadAt: timestamp("dead_at", { withTimezone: true })
|
|
669
|
+
},
|
|
670
|
+
(t) => ({
|
|
671
|
+
idUnique: uniqueIndex2("events_id_unique").on(t.id),
|
|
672
|
+
undeliveredIdx: index2("events_undelivered_idx").on(t.deliveredAt, t.seq)
|
|
673
|
+
})
|
|
674
|
+
);
|
|
675
|
+
var processedEvents2 = pgTable(
|
|
676
|
+
"processed_events",
|
|
677
|
+
{
|
|
678
|
+
handlerName: text2("handler_name").notNull(),
|
|
679
|
+
eventId: text2("event_id").notNull(),
|
|
680
|
+
processedAt: timestamp("processed_at", { withTimezone: true }).notNull()
|
|
681
|
+
},
|
|
682
|
+
(t) => ({
|
|
683
|
+
pk: primaryKey2({ columns: [t.handlerName, t.eventId] })
|
|
684
|
+
})
|
|
685
|
+
);
|
|
686
|
+
var schema2 = {
|
|
687
|
+
categories: categories2,
|
|
688
|
+
products: products2,
|
|
689
|
+
variants: variants2,
|
|
690
|
+
productCategories: productCategories2,
|
|
691
|
+
customers: customers2,
|
|
692
|
+
refreshTokens: refreshTokens2,
|
|
693
|
+
orders: orders2,
|
|
694
|
+
orderHistory: orderHistory2,
|
|
695
|
+
orderSequences: orderSequences2,
|
|
696
|
+
inventoryReservations: inventoryReservations2,
|
|
697
|
+
stockAdjustments: stockAdjustments2,
|
|
698
|
+
reviews: reviews2,
|
|
699
|
+
carts: carts2,
|
|
700
|
+
events: events2,
|
|
701
|
+
processedEvents: processedEvents2
|
|
702
|
+
};
|
|
703
|
+
|
|
704
|
+
export {
|
|
705
|
+
categories,
|
|
706
|
+
products,
|
|
707
|
+
variants,
|
|
708
|
+
productCategories,
|
|
709
|
+
customers,
|
|
710
|
+
refreshTokens,
|
|
711
|
+
orders,
|
|
712
|
+
orderHistory,
|
|
713
|
+
orderRefunds,
|
|
714
|
+
orderSequences,
|
|
715
|
+
inventoryReservations,
|
|
716
|
+
stockAdjustments,
|
|
717
|
+
reviews,
|
|
718
|
+
carts,
|
|
719
|
+
events,
|
|
720
|
+
processedEvents,
|
|
721
|
+
sqlite_exports,
|
|
722
|
+
categories2,
|
|
723
|
+
products2,
|
|
724
|
+
variants2,
|
|
725
|
+
productCategories2,
|
|
726
|
+
customers2,
|
|
727
|
+
refreshTokens2,
|
|
728
|
+
orders2,
|
|
729
|
+
orderHistory2,
|
|
730
|
+
orderRefunds2,
|
|
731
|
+
orderSequences2,
|
|
732
|
+
inventoryReservations2,
|
|
733
|
+
stockAdjustments2,
|
|
734
|
+
reviews2,
|
|
735
|
+
carts2,
|
|
736
|
+
events2,
|
|
737
|
+
processedEvents2,
|
|
738
|
+
postgres_exports
|
|
739
|
+
};
|
|
740
|
+
//# sourceMappingURL=chunk-PW6ILJF7.js.map
|