| 37203 |
amit |
1 |
-- =====================================================================
|
|
|
2 |
-- External API v2: category specs, client->category exposure,
|
|
|
3 |
-- brand identifier. Apply BEFORE deploying the build that maps them.
|
| 37284 |
amit |
4 |
--
|
|
|
5 |
-- STATUS: sections 1-5 + Mongo categoryId backfill APPLIED ON PROD
|
|
|
6 |
-- (hadb1 + shop2020 content Mongo) 2026-08-04..10. Staging (saholic-test)
|
|
|
7 |
-- NOT applied — run this file there before any staging deploy of >= r37204.
|
|
|
8 |
-- Spec-value derivation (POST /content/specs/derive?categoryId=10006/10007)
|
|
|
9 |
-- still pending on prod.
|
| 37203 |
amit |
10 |
-- =====================================================================
|
|
|
11 |
|
|
|
12 |
-- 1. Category spec vocabulary (keys governed per category) -------------
|
|
|
13 |
CREATE TABLE catalog.category_spec_definition (
|
|
|
14 |
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
|
15 |
category_id INT NOT NULL,
|
|
|
16 |
spec_key VARCHAR(50) NOT NULL COMMENT 'machine key, e.g. ram',
|
|
|
17 |
display_label VARCHAR(100) NOT NULL,
|
|
|
18 |
position TINYINT NOT NULL COMMENT 'maps to SpecValue<N> upload column, 1-based',
|
|
|
19 |
active TINYINT(1) NOT NULL DEFAULT 1,
|
|
|
20 |
create_timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
|
21 |
update_timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
|
22 |
PRIMARY KEY (id),
|
|
|
23 |
UNIQUE KEY uq_cat_spec (category_id, spec_key),
|
|
|
24 |
UNIQUE KEY uq_cat_pos (category_id, position)
|
|
|
25 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
|
26 |
|
|
|
27 |
INSERT INTO catalog.category_spec_definition (category_id, spec_key, display_label, position) VALUES
|
|
|
28 |
(10006, 'ram', 'RAM', 1),
|
|
|
29 |
(10006, 'memory', 'Internal Storage', 2),
|
|
|
30 |
(10007, 'ram', 'RAM', 1),
|
|
|
31 |
(10007, 'memory', 'Internal Storage', 2);
|
|
|
32 |
|
|
|
33 |
-- 2. Client -> category exposure (mirrors fofo.api_client_store) -------
|
|
|
34 |
CREATE TABLE fofo.api_client_category (
|
|
|
35 |
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
|
36 |
api_client_id INT UNSIGNED NOT NULL,
|
|
|
37 |
category_id INT NOT NULL,
|
|
|
38 |
create_timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
|
39 |
PRIMARY KEY (id),
|
|
|
40 |
UNIQUE KEY uq_client_category (api_client_id, category_id)
|
|
|
41 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
|
42 |
|
|
|
43 |
-- COOKIEE = api_client id 1
|
|
|
44 |
INSERT INTO fofo.api_client_category (api_client_id, category_id) VALUES (1, 10006), (1, 10007);
|
|
|
45 |
|
|
|
46 |
-- 3. Brand identifier per SKU (optional, bulk-uploader supplied) -------
|
|
|
47 |
ALTER TABLE catalog.item ADD COLUMN brand_identifier VARCHAR(100) NULL;
|
|
|
48 |
|
|
|
49 |
-- 4. Mongo categoryId backfill -----------------------------------------
|
|
|
50 |
-- Docs without categoryId are INVISIBLE to the category-scoped
|
|
|
51 |
-- catalogMaster; run this right after deploy. Generates one updateOne
|
|
|
52 |
-- per doc; pipe the output into the mongo shell on the content Mongo
|
|
|
53 |
-- (prod content Mongo is on shop2020, NOT 192.168.142.217).
|
|
|
54 |
--
|
| 37284 |
amit |
55 |
-- mysql -N -e "SELECT CONCAT('db.siteContent.update({_id:', c.id,
|
| 37203 |
amit |
56 |
-- '},{\$set:{categoryId:NumberInt(', c.category_id, ')}});')
|
|
|
57 |
-- FROM catalog.catalog c" > /tmp/mongo_category_backfill.js
|
|
|
58 |
-- mongo <content-db> /tmp/mongo_category_backfill.js
|
|
|
59 |
--
|
| 37284 |
amit |
60 |
-- NOTE: legacy update(), NOT updateOne() — the prod mongo shell (3.x on
|
|
|
61 |
-- shop2020) has no updateOne on DBCollection; updateOne fails mid-script.
|
|
|
62 |
--
|
| 37203 |
amit |
63 |
-- NumberInt is REQUIRED: NumberLong would break Gson doc parsing.
|
|
|
64 |
-- categorySpecs derivation for existing 10006/10007 docs is done via the
|
|
|
65 |
-- one-time endpoint POST /content/specs/derive?categoryId=... (see
|
|
|
66 |
-- CategorySpecDerivationService).
|
| 37221 |
amit |
67 |
|
|
|
68 |
-- 5. FOFO sidebar menu: Technology > External API Clients ---------------
|
|
|
69 |
-- Read-only admin screen (/apiClientAccess, action_class api-client-access)
|
|
|
70 |
-- showing api_client rows with their store + category mappings.
|
|
|
71 |
-- Granted to Technology (cs.ticket_category 8, all escalation levels) and
|
|
|
72 |
-- HO admin (Business Intelligence 19, escalation 3).
|
|
|
73 |
-- APPLIED ON PROD hadb1 2026-08-04.
|
|
|
74 |
INSERT INTO auth.menu (display_text, description, parent_menu_id, sequence, action_class)
|
|
|
75 |
VALUES ('External API Clients', 'API clients with mapped stores and categories', 184, 10, 'api-client-access');
|
|
|
76 |
|
|
|
77 |
SET @menu_id = LAST_INSERT_ID();
|
|
|
78 |
INSERT INTO auth.menu_category (menu_id, category_id, escalation_type) VALUES
|
|
|
79 |
(@menu_id, 8, '0'), (@menu_id, 8, '1'), (@menu_id, 8, '2'), (@menu_id, 8, '3'),
|
|
|
80 |
(@menu_id, 19, '3');
|