@autofleet/sadot 0.3.0-beta.8 → 0.3.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.
Files changed (75) hide show
  1. package/dist/index.js +1 -0
  2. package/dist/index.js.map +1 -1
  3. package/dist/models/index.js +22 -28
  4. package/dist/models/index.js.map +1 -1
  5. package/dist/repository/value.js +6 -13
  6. package/dist/repository/value.js.map +1 -1
  7. package/dist/tsconfig.tsbuildinfo +1 -1
  8. package/dist/utils/db/index.js +8 -0
  9. package/dist/utils/db/index.js.map +1 -1
  10. package/package.json +1 -1
  11. package/src/index.ts +3 -1
  12. package/src/models/index.ts +27 -33
  13. package/src/repository/value.ts +0 -8
  14. package/src/utils/db/index.ts +7 -0
  15. package/coverage/clover.xml +0 -811
  16. package/coverage/coverage-final.json +0 -35
  17. package/coverage/lcov-report/base.css +0 -224
  18. package/coverage/lcov-report/block-navigation.js +0 -87
  19. package/coverage/lcov-report/favicon.png +0 -0
  20. package/coverage/lcov-report/index.html +0 -341
  21. package/coverage/lcov-report/prettify.css +0 -1
  22. package/coverage/lcov-report/prettify.js +0 -2
  23. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  24. package/coverage/lcov-report/sorter.js +0 -196
  25. package/coverage/lcov-report/src/api/index.html +0 -116
  26. package/coverage/lcov-report/src/api/index.ts.html +0 -112
  27. package/coverage/lcov-report/src/api/v1/definition/index.html +0 -131
  28. package/coverage/lcov-report/src/api/v1/definition/index.ts.html +0 -394
  29. package/coverage/lcov-report/src/api/v1/definition/validations.ts.html +0 -190
  30. package/coverage/lcov-report/src/api/v1/errors.ts.html +0 -133
  31. package/coverage/lcov-report/src/api/v1/index.html +0 -131
  32. package/coverage/lcov-report/src/api/v1/index.ts.html +0 -112
  33. package/coverage/lcov-report/src/errors/index.html +0 -116
  34. package/coverage/lcov-report/src/errors/index.ts.html +0 -211
  35. package/coverage/lcov-report/src/events/index.html +0 -116
  36. package/coverage/lcov-report/src/events/index.ts.html +0 -235
  37. package/coverage/lcov-report/src/hooks/create.ts.html +0 -238
  38. package/coverage/lcov-report/src/hooks/enrich.ts.html +0 -442
  39. package/coverage/lcov-report/src/hooks/find.ts.html +0 -166
  40. package/coverage/lcov-report/src/hooks/index.html +0 -191
  41. package/coverage/lcov-report/src/hooks/index.ts.html +0 -130
  42. package/coverage/lcov-report/src/hooks/update.ts.html +0 -202
  43. package/coverage/lcov-report/src/hooks/workaround.ts.html +0 -226
  44. package/coverage/lcov-report/src/index.html +0 -116
  45. package/coverage/lcov-report/src/index.ts.html +0 -382
  46. package/coverage/lcov-report/src/models/CustomFieldDefinition.ts.html +0 -505
  47. package/coverage/lcov-report/src/models/CustomFieldValue.ts.html +0 -427
  48. package/coverage/lcov-report/src/models/index.html +0 -146
  49. package/coverage/lcov-report/src/models/index.ts.html +0 -289
  50. package/coverage/lcov-report/src/models/tests/AssociatedTestModel.ts.html +0 -256
  51. package/coverage/lcov-report/src/models/tests/TestModel.ts.html +0 -232
  52. package/coverage/lcov-report/src/models/tests/index.html +0 -131
  53. package/coverage/lcov-report/src/repository/definition.ts.html +0 -418
  54. package/coverage/lcov-report/src/repository/index.html +0 -131
  55. package/coverage/lcov-report/src/repository/value.ts.html +0 -406
  56. package/coverage/lcov-report/src/tests/api/index.html +0 -116
  57. package/coverage/lcov-report/src/tests/api/test-api.ts.html +0 -199
  58. package/coverage/lcov-report/src/tests/helpers/database-config.ts.html +0 -127
  59. package/coverage/lcov-report/src/tests/helpers/index.html +0 -131
  60. package/coverage/lcov-report/src/tests/helpers/index.ts.html +0 -130
  61. package/coverage/lcov-report/src/tests/mocks/definition.mock.ts.html +0 -292
  62. package/coverage/lcov-report/src/tests/mocks/events.mock.ts.html +0 -139
  63. package/coverage/lcov-report/src/tests/mocks/index.html +0 -146
  64. package/coverage/lcov-report/src/tests/mocks/testModel.ts.html +0 -196
  65. package/coverage/lcov-report/src/utils/db/index.html +0 -116
  66. package/coverage/lcov-report/src/utils/db/index.ts.html +0 -127
  67. package/coverage/lcov-report/src/utils/logger/index.html +0 -116
  68. package/coverage/lcov-report/src/utils/logger/index.ts.html +0 -103
  69. package/coverage/lcov-report/src/utils/validations/custom-fields.ts.html +0 -112
  70. package/coverage/lcov-report/src/utils/validations/custom.ts.html +0 -202
  71. package/coverage/lcov-report/src/utils/validations/index.html +0 -176
  72. package/coverage/lcov-report/src/utils/validations/index.ts.html +0 -142
  73. package/coverage/lcov-report/src/utils/validations/type.ts.html +0 -220
  74. package/coverage/lcov-report/src/utils/validations/validators.ts.html +0 -187
  75. package/coverage/lcov.info +0 -1577
@@ -41,41 +41,35 @@ const initTables = async (sequelize: Sequelize, getUser): Promise<void> => {
41
41
 
42
42
  logger.info('custom-fields: models added');
43
43
 
44
- try {
45
- const SequelizeMeta = sequelize.define(
46
- 'SequelizeMeta',
47
- {
48
- name: {
49
- type: DataTypes.STRING,
50
- allowNull: false,
51
- unique: true,
52
- primaryKey: true,
53
- autoIncrement: false,
54
- },
55
- },
56
- {
57
- tableName: 'SequelizeMeta',
58
- timestamps: true,
59
- schema: 'public',
44
+ const SequelizeMeta = sequelize.define(
45
+ 'SequelizeMeta',
46
+ {
47
+ name: {
48
+ type: DataTypes.STRING,
49
+ allowNull: false,
50
+ unique: true,
51
+ primaryKey: true,
52
+ autoIncrement: false,
60
53
  },
61
- );
62
- const migrations = await SequelizeMeta.findAll();
63
- const currentSadotSchemaVersion = migrations
64
- .reverse().find((m: any) => m.name.includes(SADOT_MIGRATION_PREFIX));
54
+ },
55
+ {
56
+ tableName: 'SequelizeMeta',
57
+ timestamps: false,
58
+ schema: 'public',
59
+ },
60
+ );
61
+ const migrations = await SequelizeMeta.findAll({ raw: true });
62
+ const currentSadotSchemaVersion = migrations
63
+ .reverse().find((m: any) => m.name.includes(SADOT_MIGRATION_PREFIX));
65
64
 
66
- console.log('ANKRI', migrations);
67
- console.log('ANKRI2', currentSadotSchemaVersion);
68
-
69
- if (
70
- !currentSadotSchemaVersion
71
- || (currentSadotSchemaVersion as any).name !== CUSTOM_FIELDS_SCHEMA_VERSION
72
- ) {
73
- await CustomFieldDefinition.sync({ alter: true });
74
- await CustomFieldValue.sync({ alter: true });
75
- logger.info('custom-fields: models synced');
76
- }
77
- } catch (err) {
78
- console.log('ANKRI ERROR', err.message);
65
+ if (
66
+ !currentSadotSchemaVersion
67
+ || (currentSadotSchemaVersion as any).name !== CUSTOM_FIELDS_SCHEMA_VERSION
68
+ ) {
69
+ await CustomFieldDefinition.sync({ alter: true });
70
+ await CustomFieldValue.sync({ alter: true });
71
+ await SequelizeMeta.create({ name: CUSTOM_FIELDS_SCHEMA_VERSION });
72
+ logger.info('custom-fields: models synced');
79
73
  }
80
74
  };
81
75
 
@@ -79,20 +79,12 @@ export const updateValues = async (
79
79
  customFieldDefinitionId: fieldDefinitions.find((def) => def.name === name).id,
80
80
  }));
81
81
 
82
- return CustomFieldValue.bulkCreate(values, {
83
- fields: ['modelId', 'value', 'updatedAt', 'customFieldDefinitionId'],
84
- updateOnDuplicate: ['value', 'updatedAt'],
85
- transaction: options.transaction,
86
- });
87
-
88
- /*
89
82
  return Promise.all(values.map(async (value) => {
90
83
  const [cfv] = await CustomFieldValue.upsert(value, {
91
84
  transaction: options.transaction,
92
85
  });
93
86
  return cfv;
94
87
  }));
95
- */
96
88
  };
97
89
 
98
90
  export const deleteValue = (
@@ -1,4 +1,5 @@
1
1
  import { Sequelize } from 'sequelize-typescript';
2
+ import { QueryTypes } from 'sequelize';
2
3
 
3
4
  export default (databaseConfig: any): Sequelize => {
4
5
  const ENV_DEV = 'test';
@@ -12,3 +13,9 @@ export default (databaseConfig: any): Sequelize => {
12
13
  }
13
14
  return sequelize;
14
15
  };
16
+
17
+ export const createSequelizeMeta = (sequelize: Sequelize) => sequelize.query(`
18
+ CREATE TABLE IF NOT EXISTS "SequelizeMeta" (
19
+ name character varying(255) PRIMARY KEY
20
+ );
21
+ `, { type: QueryTypes.SELECT });