| 37203 |
amit |
1 |
-- =====================================================================
|
|
|
2 |
-- External API v2: category specs, client->category exposure,
|
|
|
3 |
-- brand identifier. Apply BEFORE deploying the build that maps them.
|
|
|
4 |
-- =====================================================================
|
|
|
5 |
|
|
|
6 |
-- 1. Category spec vocabulary (keys governed per category) -------------
|
|
|
7 |
CREATE TABLE catalog.category_spec_definition (
|
|
|
8 |
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
|
9 |
category_id INT NOT NULL,
|
|
|
10 |
spec_key VARCHAR(50) NOT NULL COMMENT 'machine key, e.g. ram',
|
|
|
11 |
display_label VARCHAR(100) NOT NULL,
|
|
|
12 |
position TINYINT NOT NULL COMMENT 'maps to SpecValue<N> upload column, 1-based',
|
|
|
13 |
active TINYINT(1) NOT NULL DEFAULT 1,
|
|
|
14 |
create_timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
|
15 |
update_timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
|
16 |
PRIMARY KEY (id),
|
|
|
17 |
UNIQUE KEY uq_cat_spec (category_id, spec_key),
|
|
|
18 |
UNIQUE KEY uq_cat_pos (category_id, position)
|
|
|
19 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
|
20 |
|
|
|
21 |
INSERT INTO catalog.category_spec_definition (category_id, spec_key, display_label, position) VALUES
|
|
|
22 |
(10006, 'ram', 'RAM', 1),
|
|
|
23 |
(10006, 'memory', 'Internal Storage', 2),
|
|
|
24 |
(10007, 'ram', 'RAM', 1),
|
|
|
25 |
(10007, 'memory', 'Internal Storage', 2);
|
|
|
26 |
|
|
|
27 |
-- 2. Client -> category exposure (mirrors fofo.api_client_store) -------
|
|
|
28 |
CREATE TABLE fofo.api_client_category (
|
|
|
29 |
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
|
30 |
api_client_id INT UNSIGNED NOT NULL,
|
|
|
31 |
category_id INT NOT NULL,
|
|
|
32 |
create_timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
|
33 |
PRIMARY KEY (id),
|
|
|
34 |
UNIQUE KEY uq_client_category (api_client_id, category_id)
|
|
|
35 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
|
36 |
|
|
|
37 |
-- COOKIEE = api_client id 1
|
|
|
38 |
INSERT INTO fofo.api_client_category (api_client_id, category_id) VALUES (1, 10006), (1, 10007);
|
|
|
39 |
|
|
|
40 |
-- 3. Brand identifier per SKU (optional, bulk-uploader supplied) -------
|
|
|
41 |
ALTER TABLE catalog.item ADD COLUMN brand_identifier VARCHAR(100) NULL;
|
|
|
42 |
|
|
|
43 |
-- 4. Mongo categoryId backfill -----------------------------------------
|
|
|
44 |
-- Docs without categoryId are INVISIBLE to the category-scoped
|
|
|
45 |
-- catalogMaster; run this right after deploy. Generates one updateOne
|
|
|
46 |
-- per doc; pipe the output into the mongo shell on the content Mongo
|
|
|
47 |
-- (prod content Mongo is on shop2020, NOT 192.168.142.217).
|
|
|
48 |
--
|
|
|
49 |
-- mysql -N -e "SELECT CONCAT('db.siteContent.updateOne({_id:', c.id,
|
|
|
50 |
-- '},{\$set:{categoryId:NumberInt(', c.category_id, ')}});')
|
|
|
51 |
-- FROM catalog.catalog c" > /tmp/mongo_category_backfill.js
|
|
|
52 |
-- mongo <content-db> /tmp/mongo_category_backfill.js
|
|
|
53 |
--
|
|
|
54 |
-- NumberInt is REQUIRED: NumberLong would break Gson doc parsing.
|
|
|
55 |
-- categorySpecs derivation for existing 10006/10007 docs is done via the
|
|
|
56 |
-- one-time endpoint POST /content/specs/derive?categoryId=... (see
|
|
|
57 |
-- CategorySpecDerivationService).
|