feat: add cart, cartItem, etc. db tables and initial home page form #92
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/order-management"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
PR Review: feat: add cart, cartItem, etc. db tables and initial home page form
🔴 Critical Issues
1.
ordertable has no primary keyFile:
src/lib/server/database/tables/order.tsThe
ordertable definition has noidcolumn — it only hascartId,counter,discount, andcreatedAt. An order should have a primary key to be uniquely identifiable.The migration SQL files (0007 and 0008) also lack an
idcolumn.2.
cartItemValue.productOptionIdFK referencesproductinstead ofproductOptionBoth migration 0007 and 0008 have this incorrect FK:
This should reference
productOption.id, notproduct.id. The Drizzle snapshot confirms:3. Migration 0007 has incorrect FK references (self-referencing
order)Migration 0007 creates the
ordertable with a self-referencing FK:This is a self-reference on a table that has no
idcolumn. It should referencecart.id. Similarly,cartItem.cartIdreferencesorder.idinstead ofcart.id.Migration 0008 partially fixes this by recreating the tables, but the initial migration is still incorrect and would fail on a fresh database if
cartdoesn't exist yet (which it doesn't in migration 0007).🟡 Medium Issues
4.
getSchema()inProductOptionClienthas no default returnFile:
src/lib/entities/products/option/client.tsIf a new option type is added in the future without updating this switch, the method silently returns
undefined, which could cause runtime errors in the form schema.5.
getPrice()returns inconsistent typesFile:
src/lib/entities/products/option/client.tsThe method returns
nullin some branches and0in others. This inconsistency could cause issues for callers expecting a consistent return type. Consider always returningnumber | nulland using0only where it makes semantic sense.6. Duplicate
list-columnCSS class across 5 filesThe
.list-columnutility is duplicated in:src/routes/+page.sveltesrc/routes/admin/printers/+page.sveltesrc/routes/admin/printers/[printerId]/+page.sveltesrc/routes/admin/products/+page.sveltesrc/routes/admin/products/[categoryId]/+page.sveltesrc/routes/admin/products/[categoryId]/[productId]/+page.svelteThis should be defined once in
src/assets/tailwind.cssas a@utility(likebg-defaultandtext-defaultalready are).7.
orders/+page.svelteis an empty stubFile:
src/routes/orders/+page.svelteContains only
requireUser()with no UI. This creates a route that exists but does nothing. Either implement the functionality or remove the file.8. Product options removed from
AddProductFormThe
AddProductFormOption.sveltecomponent and the dynamic options-adding functionality were removed fromAddProductForm.svelte. This means admins can no longer add options when creating products. If this was intentional, the PR description should explain why, and there should be a follow-up task to restore this functionality.ℹ️ Notes
9.
@referenceand@applyCSS warningsThe
svelte-checkwarnings about@referenceand@applybeing "unknown at rules" are false positives — Tailwind v4 uses these directives and they work correctly at runtime.10. Biome internal crash
Biome crashed with an internal error (
index out of bounds), but this is a Biome bug, not a code issue. It still checked 193 files before crashing.Summary
order, wrong FK oncartItemValue, self-referencing FK in migration 0007getSchema(), inconsistent return types ingetPrice(), duplicate CSS, empty orders page, removed product optionsI recommend addressing the critical issues before merging, particularly the missing primary key on the
ordertable and the incorrect FK references, as these would cause data integrity issues in production.@ -0,0 +3,4 @@`counter` integer NOT NULL,`discount` numeric NOT NULL,`createdAt` text NOT NULL,FOREIGN KEY (`cartId`) REFERENCES `order`(`id`) ON UPDATE cascade ON DELETE restrictMigration 0007 creates
orderwith a self-referencing FK toorder.id, but the table has noidcolumn. The FK should referencecart.id, butcartdoesn't exist in migration 0007. Consider creatingcartfirst in migration 0007, or reordering migrations.@ -5,2 +5,4 @@export class ProductOptionClient extends Serializable<ProductOptionData> {getSchema() {switch (this.data.data.type) {No default return when type is neither 'boolean' nor 'choice'. If a new type is added, this silently returns
undefined.@ -0,0 +12,4 @@.notNull().references(() => product.id, { onDelete: "restrict", onUpdate: "cascade" }),cartItemId: text()FK references
product.idbut should referenceproductOption.id. The column isproductOptionIdand should point to theproductOptiontable.@ -0,0 +2,4 @@import type { CartId } from "#lib/entities/cart/id.ts";import { timestamp } from "./_utils.ts";import cart from "./cart.ts";The
ordertable has noidcolumn. It should have a primary key for unique identification. Consider adding:id: text().$type<OrderId>().primaryKey().$default(() => randomUUID() as OrderId)@ -9,0 +77,4 @@<style>@reference "#assets/tailwind.css";Consider defining this as a
@utilityinsrc/assets/tailwind.cssinstead of duplicating across 6 files.@ -0,0 +1,5 @@<script lang="ts">This page is an empty stub — just
requireUser()with no UI. Either implement it or remove the route.