@pintahub/database-schemas 4.8.1 → 5.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pintahub/database-schemas",
3
- "version": "4.8.1",
3
+ "version": "5.2.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,44 @@
1
+ const {Schema} = require('mongoose')
2
+
3
+
4
+
5
+ /** Product image with dimensions and upload status */
6
+ const RelatedProduct = new Schema({
7
+ /** @ref Store */
8
+ store: {
9
+ type: Schema.Types.ObjectId,
10
+ required: true,
11
+ },
12
+
13
+ /** @ref Product */
14
+ product: {
15
+ type: Schema.Types.ObjectId,
16
+ required: true,
17
+ },
18
+
19
+ /** @ref Product — list of related product IDs */
20
+ related_ids: {
21
+ type: [Schema.Types.ObjectId],
22
+ default: [],
23
+ },
24
+
25
+ /** Whether there are more related products beyond `related_ids` */
26
+ more_products: {
27
+ type: Boolean,
28
+ default: false,
29
+ },
30
+
31
+ /** Record creation timestamp — TTL: document expires 3 days after this value */
32
+ created_at: {
33
+ type: Date,
34
+ default: Date.now,
35
+ expires: '3d',
36
+ }
37
+ })
38
+
39
+ RelatedProduct.index({
40
+ store: 1,
41
+ product: 1,
42
+ })
43
+
44
+ module.exports = RelatedProduct
@@ -6,21 +6,18 @@ const StoreEvent = new Schema({
6
6
  /** @ref Store */
7
7
  store: {
8
8
  type: Schema.Types.ObjectId,
9
- index: true,
10
9
  required: true,
11
10
  },
12
11
 
13
12
  /** @ref Product — related product (if applicable) */
14
13
  product: {
15
14
  type: Schema.Types.ObjectId,
16
- index: true,
17
15
  },
18
16
 
19
17
  /** Visitor session identifier */
20
18
  session_id: {
21
19
  type: String,
22
20
  trim: true,
23
- index: true,
24
21
  },
25
22
 
26
23
  /** Event name, e.g. 'page_view', 'add_to_cart', 'purchase' */
@@ -28,7 +25,6 @@ const StoreEvent = new Schema({
28
25
  type: String,
29
26
  trim: true,
30
27
  lowercase: true,
31
- index: true,
32
28
  },
33
29
 
34
30
  /** URL */
@@ -46,7 +42,6 @@ const StoreEvent = new Schema({
46
42
  country: {
47
43
  type: String,
48
44
  trim: true,
49
- index: true,
50
45
  uppercase: true,
51
46
  },
52
47
 
@@ -73,16 +68,20 @@ const StoreEvent = new Schema({
73
68
  referrer_domain: {
74
69
  type: String,
75
70
  trim: true,
76
- index: true,
77
71
  },
78
72
 
79
73
  /** Record creation timestamp */
80
74
  created_at: {
81
75
  type: Date,
82
76
  default: Date.now,
83
- index: true,
84
77
  }
85
78
  })
86
79
 
80
+ // Primary — cover admin /stats/* queries (store + name + time range)
81
+ StoreEvent.index({store: 1, name: 1, created_at: -1})
82
+
83
+ // Product-specific — for productViewsCount
84
+ StoreEvent.index({store: 1, product: 1, name: 1, created_at: -1})
85
+
87
86
 
88
87
  module.exports = StoreEvent