-- Current sql file was generated after introspecting the database -- If you want to run this migration please uncomment this code before executing migrations /* CREATE TABLE "pgmigrations" ( "id" serial PRIMARY KEY NOT NULL, "name" varchar(255) NOT NULL, "run_on" timestamp NOT NULL ); --> statement-breakpoint CREATE TABLE "admin_settings" ( "key" text PRIMARY KEY NOT NULL, "value" text NOT NULL, "updated_at" timestamp with time zone DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "item_images" ( "id" serial PRIMARY KEY NOT NULL, "item_id" integer NOT NULL, "image_path" text NOT NULL, "sort_order" integer DEFAULT 0 NOT NULL, "created_at" timestamp with time zone DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "shipping_addresses" ( "id" serial PRIMARY KEY NOT NULL, "customer_id" integer NOT NULL, "full_name" text NOT NULL, "address_line1" text NOT NULL, "address_line2" text, "city" text NOT NULL, "state" text NOT NULL, "postal_code" text NOT NULL, "country" text DEFAULT 'US' NOT NULL, "is_default" boolean DEFAULT false NOT NULL, "usps_validated" boolean DEFAULT false NOT NULL, "usps_standardized" jsonb, "created_at" timestamp with time zone DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "items" ( "id" serial PRIMARY KEY NOT NULL, "name" text NOT NULL, "description" text, "price_cents" integer NOT NULL, "status" text DEFAULT 'pending' NOT NULL, "reserved_until" timestamp with time zone, "sold_at" timestamp with time zone, "paypal_order_id" text, "created_at" timestamp with time zone DEFAULT now() NOT NULL, "category_id" integer ); --> statement-breakpoint CREATE TABLE "tags" ( "id" serial PRIMARY KEY NOT NULL, "name" text NOT NULL, "color" text NOT NULL, "created_at" timestamp with time zone DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "categories" ( "id" serial PRIMARY KEY NOT NULL, "name" text NOT NULL, "parent_id" integer, "sort_order" integer DEFAULT 0 NOT NULL, "created_at" timestamp with time zone DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "orders" ( "id" serial PRIMARY KEY NOT NULL, "item_id" integer, "customer_id" integer, "checkout_id" integer, "processor" text NOT NULL, "processor_order_id" text, "amount_cents" integer, "status" text, "raw_event" jsonb, "created_at" timestamp with time zone DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "cart_items" ( "id" serial PRIMARY KEY NOT NULL, "cart_id" integer NOT NULL, "item_id" integer NOT NULL, "added_at" timestamp with time zone DEFAULT now() NOT NULL, "expires_at" timestamp with time zone NOT NULL, "last_reminder_sent_at" timestamp with time zone, CONSTRAINT "cart_items_item_id_key" UNIQUE("item_id") ); --> statement-breakpoint CREATE TABLE "carts" ( "id" serial PRIMARY KEY NOT NULL, "customer_id" integer NOT NULL, "created_at" timestamp with time zone DEFAULT now() NOT NULL, "updated_at" timestamp with time zone DEFAULT now() NOT NULL, CONSTRAINT "carts_customer_id_key" UNIQUE("customer_id") ); --> statement-breakpoint CREATE TABLE "customer_tokens" ( "token" text PRIMARY KEY NOT NULL, "customer_id" integer NOT NULL, "kind" text NOT NULL, "expires_at" timestamp with time zone NOT NULL, "created_at" timestamp with time zone DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "checkouts" ( "id" serial PRIMARY KEY NOT NULL, "customer_id" integer, "shipping_address_id" integer, "processor" text NOT NULL, "processor_order_id" text, "amount_cents" integer, "status" text DEFAULT 'pending' NOT NULL, "raw_event" jsonb, "created_at" timestamp with time zone DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "customer_sessions" ( "token" text PRIMARY KEY NOT NULL, "customer_id" integer NOT NULL, "expires_at" timestamp with time zone NOT NULL, "created_at" timestamp with time zone DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "customers" ( "id" serial PRIMARY KEY NOT NULL, "email" text NOT NULL, "password_hash" text NOT NULL, "email_verified" boolean DEFAULT false NOT NULL, "marketing_consent" boolean DEFAULT false NOT NULL, "marketing_consent_at" timestamp with time zone, "marketing_consent_text" text, "unsubscribe_token" text NOT NULL, "created_at" timestamp with time zone DEFAULT now() NOT NULL, "disabled_at" timestamp with time zone, "favorite_alerts" boolean DEFAULT false NOT NULL, "favorite_alerts_at" timestamp with time zone, "favorite_alerts_text" text, "first_name" text, "last_name" text, CONSTRAINT "customers_email_key" UNIQUE("email"), CONSTRAINT "customers_unsubscribe_token_key" UNIQUE("unsubscribe_token") ); --> statement-breakpoint CREATE TABLE "item_tags" ( "item_id" integer NOT NULL, "tag_id" integer NOT NULL, CONSTRAINT "item_tags_pkey" PRIMARY KEY("item_id","tag_id") ); --> statement-breakpoint CREATE TABLE "favorites" ( "customer_id" integer NOT NULL, "item_id" integer NOT NULL, "created_at" timestamp with time zone DEFAULT now() NOT NULL, CONSTRAINT "favorites_pkey" PRIMARY KEY("customer_id","item_id") ); --> statement-breakpoint CREATE TABLE "checkout_items" ( "checkout_id" integer NOT NULL, "item_id" integer NOT NULL, "price_cents" integer NOT NULL, CONSTRAINT "checkout_items_pkey" PRIMARY KEY("checkout_id","item_id") ); --> statement-breakpoint ALTER TABLE "item_images" ADD CONSTRAINT "item_images_item_id_fkey" FOREIGN KEY ("item_id") REFERENCES "public"."items"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "shipping_addresses" ADD CONSTRAINT "shipping_addresses_customer_id_fkey" FOREIGN KEY ("customer_id") REFERENCES "public"."customers"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "items" ADD CONSTRAINT "items_category_id_fkey" FOREIGN KEY ("category_id") REFERENCES "public"."categories"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint ALTER TABLE "categories" ADD CONSTRAINT "categories_parent_id_fkey" FOREIGN KEY ("parent_id") REFERENCES "public"."categories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "orders" ADD CONSTRAINT "orders_item_id_fkey" FOREIGN KEY ("item_id") REFERENCES "public"."items"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "orders" ADD CONSTRAINT "orders_customer_id_fkey" FOREIGN KEY ("customer_id") REFERENCES "public"."customers"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint ALTER TABLE "orders" ADD CONSTRAINT "orders_checkout_id_fkey" FOREIGN KEY ("checkout_id") REFERENCES "public"."checkouts"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint ALTER TABLE "cart_items" ADD CONSTRAINT "cart_items_cart_id_fkey" FOREIGN KEY ("cart_id") REFERENCES "public"."carts"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "cart_items" ADD CONSTRAINT "cart_items_item_id_fkey" FOREIGN KEY ("item_id") REFERENCES "public"."items"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "carts" ADD CONSTRAINT "carts_customer_id_fkey" FOREIGN KEY ("customer_id") REFERENCES "public"."customers"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "customer_tokens" ADD CONSTRAINT "customer_tokens_customer_id_fkey" FOREIGN KEY ("customer_id") REFERENCES "public"."customers"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "checkouts" ADD CONSTRAINT "checkouts_customer_id_fkey" FOREIGN KEY ("customer_id") REFERENCES "public"."customers"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint ALTER TABLE "checkouts" ADD CONSTRAINT "checkouts_shipping_address_id_fkey" FOREIGN KEY ("shipping_address_id") REFERENCES "public"."shipping_addresses"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint ALTER TABLE "customer_sessions" ADD CONSTRAINT "customer_sessions_customer_id_fkey" FOREIGN KEY ("customer_id") REFERENCES "public"."customers"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "item_tags" ADD CONSTRAINT "item_tags_item_id_fkey" FOREIGN KEY ("item_id") REFERENCES "public"."items"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "item_tags" ADD CONSTRAINT "item_tags_tag_id_fkey" FOREIGN KEY ("tag_id") REFERENCES "public"."tags"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "favorites" ADD CONSTRAINT "favorites_customer_id_fkey" FOREIGN KEY ("customer_id") REFERENCES "public"."customers"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "favorites" ADD CONSTRAINT "favorites_item_id_fkey" FOREIGN KEY ("item_id") REFERENCES "public"."items"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "checkout_items" ADD CONSTRAINT "checkout_items_checkout_id_fkey" FOREIGN KEY ("checkout_id") REFERENCES "public"."checkouts"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "checkout_items" ADD CONSTRAINT "checkout_items_item_id_fkey" FOREIGN KEY ("item_id") REFERENCES "public"."items"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint CREATE INDEX "items_category_id_idx" ON "items" USING btree ("category_id" int4_ops);--> statement-breakpoint CREATE UNIQUE INDEX "tags_name_uniq" ON "tags" USING btree (lower(name) text_ops);--> statement-breakpoint CREATE UNIQUE INDEX "categories_child_name_uniq" ON "categories" USING btree (parent_id text_ops,lower(name) int4_ops) WHERE (parent_id IS NOT NULL);--> statement-breakpoint CREATE INDEX "categories_parent_id_idx" ON "categories" USING btree ("parent_id" int4_ops);--> statement-breakpoint CREATE UNIQUE INDEX "categories_root_name_uniq" ON "categories" USING btree (lower(name) text_ops) WHERE (parent_id IS NULL);--> statement-breakpoint CREATE INDEX "customers_disabled_at_idx" ON "customers" USING btree ("disabled_at" timestamptz_ops) WHERE (disabled_at IS NOT NULL);--> statement-breakpoint CREATE INDEX "item_tags_tag_id_idx" ON "item_tags" USING btree ("tag_id" int4_ops);--> statement-breakpoint CREATE INDEX "favorites_item_id_idx" ON "favorites" USING btree ("item_id" int4_ops); */