@managesome/eposmatic-toolkit 0.4.30 → 0.4.31

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.
@@ -6,6 +6,7 @@ import { MATERIALIZED_TENANT_REPORTS_ITERATIONS_COLLECTION_NAME, MATERIALIZED_TE
6
6
  import { MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_COLLECTION_NAME, MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_INDEX_OPTIONS, } from '../../schemas/models/materialized_tenant_sales_overview_reports';
7
7
  import { MATERIALIZED_REPORT_DRILLDOWN_ROWS_COLLECTION_NAME, MATERIALIZED_REPORT_DRILLDOWN_ROWS_INDEX_OPTIONS, MATERIALIZED_REPORT_DRILLDOWN_SCOPES_COLLECTION_NAME, MATERIALIZED_REPORT_DRILLDOWN_SCOPES_INDEX_OPTIONS, } from '../../schemas/models/materialized_report_drilldown_rows';
8
8
  import { TENANT_CALENDAR_COLLECTION_NAME, TENANT_CALENDAR_INDEX_OPTIONS } from '../../schemas/models/tenant_calendar';
9
+ import { TENANT_ACTIVE_JOBS_COLLECTION_NAME, TENANT_ACTIVE_JOBS_INDEX_OPTIONS, } from '../../schemas/models/tenant_active_jobs';
9
10
  /**
10
11
  * BOOTSTRAP the indexes the materialized reads/writes assume.
11
12
  *
@@ -28,6 +29,7 @@ const INDEXES = {
28
29
  [MATERIALIZED_REPORT_DRILLDOWN_ROWS_COLLECTION_NAME]: MATERIALIZED_REPORT_DRILLDOWN_ROWS_INDEX_OPTIONS,
29
30
  [MATERIALIZED_REPORT_DRILLDOWN_SCOPES_COLLECTION_NAME]: MATERIALIZED_REPORT_DRILLDOWN_SCOPES_INDEX_OPTIONS,
30
31
  [TENANT_CALENDAR_COLLECTION_NAME]: TENANT_CALENDAR_INDEX_OPTIONS,
32
+ [TENANT_ACTIVE_JOBS_COLLECTION_NAME]: TENANT_ACTIVE_JOBS_INDEX_OPTIONS,
31
33
  };
32
34
  export const MATERIALIZED_REPORT_INDEX_COLLECTIONS = Object.keys(INDEXES);
33
35
  export async function ensureMaterializedReportIndexes(connection, options = {}) {
@@ -42,6 +44,23 @@ export async function ensureMaterializedReportIndexes(connection, options = {})
42
44
  }
43
45
  const collection = db.collection(collectionName);
44
46
  const indexes = definitions.filter((definition) => definition.name !== '_id_');
47
+ // One-time migration for the old discount-entry identity index. A page
48
+ // design cannot coexist with a unique index that omits `page`.
49
+ if (collectionName === MATERIALIZED_TENANT_DISCOUNT_ENTRIES_COLLECTION_NAME) {
50
+ const existing = await collection
51
+ .listIndexes()
52
+ .toArray()
53
+ .catch(() => []);
54
+ const legacy = existing.find((index) => index.name === 'tenant_id__scope_context__scope_field__day_index' ||
55
+ (index.unique === true &&
56
+ index.key?.tenant_id === 1 &&
57
+ index.key?.scope_context === 1 &&
58
+ index.key?.scope_field === 1 &&
59
+ index.key?.day_index === 1 &&
60
+ index.key?.page == null));
61
+ if (legacy != null)
62
+ await collection.dropIndex(legacy.name);
63
+ }
45
64
  try {
46
65
  await collection.createIndexes(indexes);
47
66
  }
@@ -83,3 +83,10 @@ export const TENANT_ACTIVE_JOBS_COLLECTION_INDEXES = {
83
83
  _id: { _id: 1 }, // Unique Index
84
84
  tenant_id: { tenant_id: 1 }, // Unique Index — one document per tenant
85
85
  };
86
+ export const TENANT_ACTIVE_JOBS_INDEX_OPTIONS = [
87
+ {
88
+ key: TENANT_ACTIVE_JOBS_COLLECTION_INDEXES.tenant_id,
89
+ name: 'tenant_id',
90
+ unique: true,
91
+ },
92
+ ];
@@ -10,6 +10,7 @@ const materialized_tenant_reports_iterations_1 = require("../../schemas/models/m
10
10
  const materialized_tenant_sales_overview_reports_1 = require("../../schemas/models/materialized_tenant_sales_overview_reports");
11
11
  const materialized_report_drilldown_rows_1 = require("../../schemas/models/materialized_report_drilldown_rows");
12
12
  const tenant_calendar_1 = require("../../schemas/models/tenant_calendar");
13
+ const tenant_active_jobs_1 = require("../../schemas/models/tenant_active_jobs");
13
14
  /**
14
15
  * BOOTSTRAP the indexes the materialized reads/writes assume.
15
16
  *
@@ -32,6 +33,7 @@ const INDEXES = {
32
33
  [materialized_report_drilldown_rows_1.MATERIALIZED_REPORT_DRILLDOWN_ROWS_COLLECTION_NAME]: materialized_report_drilldown_rows_1.MATERIALIZED_REPORT_DRILLDOWN_ROWS_INDEX_OPTIONS,
33
34
  [materialized_report_drilldown_rows_1.MATERIALIZED_REPORT_DRILLDOWN_SCOPES_COLLECTION_NAME]: materialized_report_drilldown_rows_1.MATERIALIZED_REPORT_DRILLDOWN_SCOPES_INDEX_OPTIONS,
34
35
  [tenant_calendar_1.TENANT_CALENDAR_COLLECTION_NAME]: tenant_calendar_1.TENANT_CALENDAR_INDEX_OPTIONS,
36
+ [tenant_active_jobs_1.TENANT_ACTIVE_JOBS_COLLECTION_NAME]: tenant_active_jobs_1.TENANT_ACTIVE_JOBS_INDEX_OPTIONS,
35
37
  };
36
38
  exports.MATERIALIZED_REPORT_INDEX_COLLECTIONS = Object.keys(INDEXES);
37
39
  async function ensureMaterializedReportIndexes(connection, options = {}) {
@@ -46,6 +48,23 @@ async function ensureMaterializedReportIndexes(connection, options = {}) {
46
48
  }
47
49
  const collection = db.collection(collectionName);
48
50
  const indexes = definitions.filter((definition) => definition.name !== '_id_');
51
+ // One-time migration for the old discount-entry identity index. A page
52
+ // design cannot coexist with a unique index that omits `page`.
53
+ if (collectionName === materialized_tenant_discount_entries_1.MATERIALIZED_TENANT_DISCOUNT_ENTRIES_COLLECTION_NAME) {
54
+ const existing = await collection
55
+ .listIndexes()
56
+ .toArray()
57
+ .catch(() => []);
58
+ const legacy = existing.find((index) => index.name === 'tenant_id__scope_context__scope_field__day_index' ||
59
+ (index.unique === true &&
60
+ index.key?.tenant_id === 1 &&
61
+ index.key?.scope_context === 1 &&
62
+ index.key?.scope_field === 1 &&
63
+ index.key?.day_index === 1 &&
64
+ index.key?.page == null));
65
+ if (legacy != null)
66
+ await collection.dropIndex(legacy.name);
67
+ }
49
68
  try {
50
69
  await collection.createIndexes(indexes);
51
70
  }
@@ -74,3 +74,10 @@ export declare const TENANT_ACTIVE_JOBS_COLLECTION_INDEXES: {
74
74
  tenant_id: number;
75
75
  };
76
76
  };
77
+ export declare const TENANT_ACTIVE_JOBS_INDEX_OPTIONS: {
78
+ key: {
79
+ tenant_id: number;
80
+ };
81
+ name: string;
82
+ unique: boolean;
83
+ }[];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TENANT_ACTIVE_JOBS_COLLECTION_INDEXES = exports.TENANT_ACTIVE_JOBS_COLLECTION_NAME = exports.TenantActiveJobSchema = void 0;
3
+ exports.TENANT_ACTIVE_JOBS_INDEX_OPTIONS = exports.TENANT_ACTIVE_JOBS_COLLECTION_INDEXES = exports.TENANT_ACTIVE_JOBS_COLLECTION_NAME = exports.TenantActiveJobSchema = void 0;
4
4
  const mongoose_1 = require("mongoose");
5
5
  const constants_1 = require("../../constants");
6
6
  exports.TenantActiveJobSchema = new mongoose_1.Schema({
@@ -86,3 +86,10 @@ exports.TENANT_ACTIVE_JOBS_COLLECTION_INDEXES = {
86
86
  _id: { _id: 1 }, // Unique Index
87
87
  tenant_id: { tenant_id: 1 }, // Unique Index — one document per tenant
88
88
  };
89
+ exports.TENANT_ACTIVE_JOBS_INDEX_OPTIONS = [
90
+ {
91
+ key: exports.TENANT_ACTIVE_JOBS_COLLECTION_INDEXES.tenant_id,
92
+ name: 'tenant_id',
93
+ unique: true,
94
+ },
95
+ ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.4.30",
3
+ "version": "0.4.31",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",