110 lines
5.6 KiB
SQL
110 lines
5.6 KiB
SQL
-- A synthetic global catalogue to develop against.
|
|
--
|
|
-- INVENTED DATA, exactly like `nearledb/02-seed.sql` and for the same reason:
|
|
-- the real catalogue is somebody else's scrape of real retailers, and a dump of
|
|
-- it does not belong on a laptop inside a git repository.
|
|
--
|
|
-- ── Why this file has to exist ──────────────────────────────────────────────
|
|
--
|
|
-- `init/cataloguedb/` was empty, so a local stack had a catalogue DATABASE with
|
|
-- no catalogue in it. Every `brand_*` table was missing, `getbrands` answered
|
|
-- 500, and the whole catalogue-import path — the global catalogue screen, the
|
|
-- import flow, `importcatalogueproduct` — could not be exercised locally at
|
|
-- all. It is a documented feature with its own integration doc and it had no
|
|
-- local coverage whatsoever.
|
|
--
|
|
-- ── The shape ───────────────────────────────────────────────────────────────
|
|
--
|
|
-- Brands are discovered from `information_schema` by table name, so a table
|
|
-- called `brand_<something>` IS a brand; there is no registry to add it to.
|
|
-- `catalogueCoreColumns` requires only `id` and `product_name` — everything
|
|
-- else is selected when present and replaced with NULL when absent, so a
|
|
-- partial table degrades rather than disappearing. These two are written full
|
|
-- so that the degraded path is a deliberate test, not the only thing available:
|
|
-- `brand_testbrand` has every column, and `brand_sparsebrand` deliberately has
|
|
-- only the core two plus a price, to exercise `columnsFor`.
|
|
--
|
|
-- `image_id` is the durable key across re-scrapes — catalogue ids are not
|
|
-- stable and `models.Products.Imageid` is what the import stores — so every
|
|
-- product here has one and they are distinct.
|
|
|
|
CREATE EXTENSION IF NOT EXISTS vector;
|
|
|
|
-- ── A brand with the full column set ────────────────────────────────────────
|
|
CREATE TABLE IF NOT EXISTS brand_testbrand (
|
|
id BIGSERIAL PRIMARY KEY,
|
|
product_name TEXT NOT NULL,
|
|
title TEXT,
|
|
description TEXT,
|
|
category TEXT,
|
|
image_id TEXT,
|
|
size TEXT,
|
|
variant_key TEXT,
|
|
product_sku TEXT,
|
|
sku_source TEXT,
|
|
-- A RANGE, not a price. The global catalogue carries what retailers were
|
|
-- seen charging; the shop sets its own price at import time, which is why
|
|
-- the console collects one before an import can be enabled.
|
|
price_range TEXT,
|
|
providers TEXT[],
|
|
fssai_license TEXT,
|
|
highlights TEXT[],
|
|
nutrients TEXT[],
|
|
search_query TEXT,
|
|
image_url TEXT,
|
|
image_urls TEXT[],
|
|
created_at TIMESTAMPTZ DEFAULT NOW(),
|
|
updated_at TIMESTAMPTZ DEFAULT NOW()
|
|
);
|
|
|
|
INSERT INTO brand_testbrand
|
|
(product_name, title, description, category, image_id, size, variant_key,
|
|
product_sku, sku_source, price_range, providers, fssai_license,
|
|
highlights, nutrients, search_query, image_url, image_urls)
|
|
VALUES
|
|
('Testbrand Basmati Rice 5kg', 'Testbrand Basmati Rice', 'Long grain basmati, aged twelve months.',
|
|
'Rice & Grains', 'IMG-TB-RICE-5K', '5 kg', 'rice-5kg', 'TB-RICE-5K', 'scrape',
|
|
'380-420', ARRAY['bigbasket','amazon'], '12345678901234',
|
|
ARRAY['Aged 12 months','Extra long grain'], ARRAY['Energy 350kcal','Protein 7g'],
|
|
'basmati rice 5kg', 'https://placehold.co/300x300?text=Rice5kg',
|
|
ARRAY['https://placehold.co/300x300?text=Rice5kg','https://placehold.co/300x300?text=Rice5kg-back']),
|
|
|
|
('Testbrand Basmati Rice 1kg', 'Testbrand Basmati Rice', 'Long grain basmati, aged twelve months.',
|
|
'Rice & Grains', 'IMG-TB-RICE-1K', '1 kg', 'rice-1kg', 'TB-RICE-1K', 'scrape',
|
|
'85-99', ARRAY['bigbasket'], '12345678901234',
|
|
ARRAY['Aged 12 months'], ARRAY['Energy 350kcal','Protein 7g'],
|
|
'basmati rice 1kg', 'https://placehold.co/300x300?text=Rice1kg',
|
|
ARRAY['https://placehold.co/300x300?text=Rice1kg']),
|
|
|
|
('Testbrand Sunflower Oil 1L', 'Testbrand Sunflower Oil', 'Refined sunflower oil, light and neutral.',
|
|
'Oils & Ghee', 'IMG-TB-OIL-1L', '1 L', 'oil-1l', 'TB-OIL-1L', 'scrape',
|
|
'150-185', ARRAY['bigbasket','jiomart'], '99999999999999',
|
|
ARRAY['Vitamin E','Light frying'], ARRAY['Energy 900kcal','Fat 100g'],
|
|
'sunflower oil 1 litre', 'https://placehold.co/300x300?text=Oil1L',
|
|
ARRAY['https://placehold.co/300x300?text=Oil1L']),
|
|
|
|
-- No images at all. `ImportCatalogueProduct` only sets `productimages` when
|
|
-- the product has photos, so this row is the one that proves an import still
|
|
-- works when it does not — the case that used to hit the jsonb empty-string
|
|
-- failure in `products`.
|
|
('Testbrand Salt 1kg', 'Testbrand Iodised Salt', 'Free-flowing iodised salt.',
|
|
'Everyday', 'IMG-TB-SALT-1K', '1 kg', 'salt-1kg', 'TB-SALT-1K', 'scrape',
|
|
'20-28', ARRAY['jiomart'], NULL,
|
|
NULL, NULL, 'iodised salt 1kg', NULL, NULL);
|
|
|
|
-- ── A brand with only the core columns ──────────────────────────────────────
|
|
--
|
|
-- Discovery used to demand all eighteen columns, which made a table like this
|
|
-- INVISIBLE rather than merely thin — 16 of 35 live brands were unreachable
|
|
-- from this side for exactly that reason. Keeping one here means the
|
|
-- degraded-but-listed path is covered by the seed and stays covered.
|
|
CREATE TABLE IF NOT EXISTS brand_sparsebrand (
|
|
id BIGSERIAL PRIMARY KEY,
|
|
product_name TEXT NOT NULL,
|
|
price_range TEXT
|
|
);
|
|
|
|
INSERT INTO brand_sparsebrand (product_name, price_range) VALUES
|
|
('Sparsebrand Biscuits 100g', '20-30'),
|
|
('Sparsebrand Tea 250g', '110-140');
|