CREATE TABLE "sales" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "seller_id" uuid NOT NULL REFERENCES "sellers"("id"), "sale_date" text NOT NULL, "sale_location" text, "sold_price_minor" integer NOT NULL, "currency" text NOT NULL, "platform_fees_minor" integer DEFAULT 0 NOT NULL, "payment_processing_fees_minor" integer DEFAULT 0 NOT NULL, "shipping_cost_minor" integer DEFAULT 0 NOT NULL, "taxes_minor" integer DEFAULT 0 NOT NULL, "other_fees_minor" integer DEFAULT 0 NOT NULL, "buyer_name" text, "buyer_contact" text, "notes" text, "created_at" timestamp with time zone DEFAULT now() NOT NULL, "updated_at" timestamp with time zone DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "sale_items" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "sale_id" uuid NOT NULL REFERENCES "sales"("id"), "inventory_item_id" uuid NOT NULL REFERENCES "inventory_items"("id"), "sold_price_minor" integer NOT NULL, "cost_basis_minor" integer NOT NULL ); --> statement-breakpoint CREATE UNIQUE INDEX "sale_items_inventory_item_id_unique" ON "sale_items" USING btree ("inventory_item_id"); --> statement-breakpoint CREATE INDEX "sale_items_sale_id_index" ON "sale_items" USING btree ("sale_id");