Subversion Repositories SmartDukaan

Rev

Rev 37203 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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).
37221 amit 58
 
59
-- 5. FOFO sidebar menu: Technology > External API Clients ---------------
60
-- Read-only admin screen (/apiClientAccess, action_class api-client-access)
61
-- showing api_client rows with their store + category mappings.
62
-- Granted to Technology (cs.ticket_category 8, all escalation levels) and
63
-- HO admin (Business Intelligence 19, escalation 3).
64
-- APPLIED ON PROD hadb1 2026-08-04.
65
INSERT INTO auth.menu (display_text, description, parent_menu_id, sequence, action_class)
66
VALUES ('External API Clients', 'API clients with mapped stores and categories', 184, 10, 'api-client-access');
67
 
68
SET @menu_id = LAST_INSERT_ID();
69
INSERT INTO auth.menu_category (menu_id, category_id, escalation_type) VALUES
70
  (@menu_id, 8, '0'), (@menu_id, 8, '1'), (@menu_id, 8, '2'), (@menu_id, 8, '3'),
71
  (@menu_id, 19, '3');