CREATE TABLE "shops" (
  "id" SERIAL,
  "name" text
);

CREATE TABLE "products" (
  "id" integer PRIMARY KEY NOT NULL,
  "shop_id" integer NOT NULL,
  "slug" text NOT NULL,
  "description" text,
  "status" prod_status NOT NULL,
  "pinned_at" timestamp,
  "created_at" timestamp NOT NULL DEFAULT (CURRENT_TIMESTAMP),
  "updated_at" timestamp NOT NULL DEFAULT (CURRENT_TIMESTAMP),
  "desc_tsv" tsvector,
  "listed_at" timestamp NOT NULL DEFAULT (CURRENT_TIMESTAMP)
);

CREATE UNIQUE INDEX "products_slug_unique" ON "products" USING BTREE ("slug");

CREATE INDEX "products_created_at_ix" ON "products" USING BTREE ("created_at");

CREATE INDEX "products_gin_ix" ON "products" USING GIN ("desc_tsv");

CREATE INDEX "products_gin_ix_published_ty_karld" ON "products" USING GIN ("desc_tsv");

CREATE INDEX "products_listed_at_ix" ON "products" USING BTREE ("listed_at");

CREATE INDEX "products_listed_at_reverse_ix" ON "products" USING BTREE ("listed_at");

CREATE INDEX "products_pinned_at_created_at_index" ON "products" USING BTREE ("pinned_at", "created_at");

CREATE INDEX "products_pinned_at_ix" ON "products" USING BTREE ("pinned_at");

CREATE INDEX "products_pinned_at_listed_at_ix" ON "products" USING BTREE ("pinned_at", "listed_at");

CREATE INDEX "products_pinned_at_listed_at_reverse_ix" ON "products" USING BTREE ("pinned_at", "listed_at");

CREATE INDEX "products_pinned_at_reverse_ix" ON "products" USING BTREE ("pinned_at", "created_at");

CREATE INDEX "products_shop_id_index" ON "products" USING BTREE ("shop_id");

CREATE INDEX "products_status_index" ON "products" USING BTREE ("status");

CREATE INDEX "products_status_shop_id_index" ON "products" USING BTREE ("status", "shop_id");

ALTER TABLE "products" ADD FOREIGN KEY ("shop_id") REFERENCES "shops" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

