exodus-framework 2.0.995 → 2.0.997
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/lib/models/migrations/00-logs.d.ts +4 -0
- package/lib/models/migrations/00-logs.d.ts.map +1 -0
- package/lib/models/migrations/00-logs.js +69 -0
- package/lib/models/migrations/00-reports.d.ts +4 -0
- package/lib/models/migrations/00-reports.d.ts.map +1 -0
- package/lib/models/migrations/00-reports.js +69 -0
- package/lib/models/migrations/00-system.d.ts +4 -0
- package/lib/models/migrations/00-system.d.ts.map +1 -0
- package/lib/models/migrations/00-system.js +56 -0
- package/lib/services/database.d.ts +2 -1
- package/lib/services/database.d.ts.map +1 -1
- package/lib/services/database.js +18 -2
- package/lib/utils/database.d.ts +5 -1
- package/lib/utils/database.d.ts.map +1 -1
- package/lib/utils/database.js +15 -15
- package/package.json +1 -1
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"00-logs.d.ts","sourceRoot":"","sources":["../../../src/models/migrations/00-logs.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAKjD,wBAAsB,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,cAAc,iBAyDnD;AAED,wBAAsB,IAAI,CAAC,EAAE,OAAO,EAAE,EAAE,cAAc,iBAErD"}
|
@@ -0,0 +1,69 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.down = down;
|
7
|
+
exports.up = up;
|
8
|
+
var _sequelize = require("sequelize");
|
9
|
+
var _utils = require("../../utils");
|
10
|
+
const tablename = 'logs';
|
11
|
+
async function up({
|
12
|
+
context
|
13
|
+
}) {
|
14
|
+
await context.createTable(tablename, {
|
15
|
+
uuid: {
|
16
|
+
type: _sequelize.DataTypes.UUID,
|
17
|
+
defaultValue: _sequelize.DataTypes.UUIDV4,
|
18
|
+
primaryKey: true,
|
19
|
+
allowNull: false,
|
20
|
+
autoIncrement: false
|
21
|
+
},
|
22
|
+
happenedAt: {
|
23
|
+
type: _sequelize.DataTypes.DATE,
|
24
|
+
allowNull: false
|
25
|
+
},
|
26
|
+
category: {
|
27
|
+
type: _sequelize.DataTypes.STRING(100),
|
28
|
+
allowNull: false
|
29
|
+
},
|
30
|
+
origin: {
|
31
|
+
type: _sequelize.DataTypes.STRING(100),
|
32
|
+
allowNull: false
|
33
|
+
},
|
34
|
+
action: {
|
35
|
+
type: _sequelize.DataTypes.STRING(100),
|
36
|
+
allowNull: false
|
37
|
+
},
|
38
|
+
comments: {
|
39
|
+
type: _sequelize.DataTypes.STRING(255),
|
40
|
+
allowNull: true
|
41
|
+
},
|
42
|
+
data: {
|
43
|
+
type: _sequelize.DataTypes.JSON,
|
44
|
+
defaultValue: {},
|
45
|
+
allowNull: true
|
46
|
+
},
|
47
|
+
params: {
|
48
|
+
type: _sequelize.DataTypes.JSON,
|
49
|
+
defaultValue: {},
|
50
|
+
allowNull: true
|
51
|
+
},
|
52
|
+
createdAt: _sequelize.DataTypes.DATE,
|
53
|
+
updatedAt: _sequelize.DataTypes.DATE,
|
54
|
+
deletedAt: _sequelize.DataTypes.DATE
|
55
|
+
});
|
56
|
+
const indexes = [{
|
57
|
+
fields: ['category']
|
58
|
+
}, {
|
59
|
+
fields: ['origin']
|
60
|
+
}, {
|
61
|
+
fields: ['action']
|
62
|
+
}];
|
63
|
+
await (0, _utils.InsertIndexes)(context, tablename, indexes);
|
64
|
+
}
|
65
|
+
async function down({
|
66
|
+
context
|
67
|
+
}) {
|
68
|
+
await context.dropTable(tablename);
|
69
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"00-reports.d.ts","sourceRoot":"","sources":["../../../src/models/migrations/00-reports.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAKjD,wBAAsB,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,cAAc,iBAyDnD;AAED,wBAAsB,IAAI,CAAC,EAAE,OAAO,EAAE,EAAE,cAAc,iBAErD"}
|
@@ -0,0 +1,69 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.down = down;
|
7
|
+
exports.up = up;
|
8
|
+
var _sequelize = require("sequelize");
|
9
|
+
var _utils = require("../../utils");
|
10
|
+
const tablename = 'reports';
|
11
|
+
async function up({
|
12
|
+
context
|
13
|
+
}) {
|
14
|
+
await context.createTable(tablename, {
|
15
|
+
uuid: {
|
16
|
+
type: _sequelize.DataTypes.UUID,
|
17
|
+
defaultValue: _sequelize.DataTypes.UUIDV4,
|
18
|
+
primaryKey: true,
|
19
|
+
allowNull: false,
|
20
|
+
autoIncrement: false
|
21
|
+
},
|
22
|
+
category: {
|
23
|
+
type: _sequelize.DataTypes.STRING(100),
|
24
|
+
allowNull: false
|
25
|
+
},
|
26
|
+
origin: {
|
27
|
+
type: _sequelize.DataTypes.STRING(100),
|
28
|
+
allowNull: false
|
29
|
+
},
|
30
|
+
description: {
|
31
|
+
type: _sequelize.DataTypes.STRING(255),
|
32
|
+
allowNull: true
|
33
|
+
},
|
34
|
+
file: {
|
35
|
+
type: _sequelize.DataTypes.STRING(255),
|
36
|
+
allowNull: true
|
37
|
+
},
|
38
|
+
total: {
|
39
|
+
type: _sequelize.DataTypes.INTEGER(),
|
40
|
+
allowNull: true
|
41
|
+
},
|
42
|
+
params: {
|
43
|
+
type: _sequelize.DataTypes.JSON,
|
44
|
+
defaultValue: {},
|
45
|
+
allowNull: true
|
46
|
+
},
|
47
|
+
status: {
|
48
|
+
type: _sequelize.DataTypes.ENUM('PENDING', 'COMPLETED'),
|
49
|
+
allowNull: false,
|
50
|
+
defaultValue: 'PENDING'
|
51
|
+
},
|
52
|
+
createdAt: _sequelize.DataTypes.DATE,
|
53
|
+
updatedAt: _sequelize.DataTypes.DATE,
|
54
|
+
deletedAt: _sequelize.DataTypes.DATE
|
55
|
+
});
|
56
|
+
const indexes = [{
|
57
|
+
fields: ['category']
|
58
|
+
}, {
|
59
|
+
fields: ['description']
|
60
|
+
}, {
|
61
|
+
fields: ['file']
|
62
|
+
}];
|
63
|
+
await (0, _utils.InsertIndexes)(context, tablename, indexes);
|
64
|
+
}
|
65
|
+
async function down({
|
66
|
+
context
|
67
|
+
}) {
|
68
|
+
await context.dropTable(tablename);
|
69
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"00-system.d.ts","sourceRoot":"","sources":["../../../src/models/migrations/00-system.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAKjD,wBAAsB,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,cAAc,iBA4CnD;AAED,wBAAsB,IAAI,CAAC,EAAE,OAAO,EAAE,EAAE,cAAc,iBAErD"}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.down = down;
|
7
|
+
exports.up = up;
|
8
|
+
var _sequelize = require("sequelize");
|
9
|
+
var _utils = require("../../utils");
|
10
|
+
const tablename = 'system';
|
11
|
+
async function up({
|
12
|
+
context
|
13
|
+
}) {
|
14
|
+
await context.createTable(tablename, {
|
15
|
+
uuid: {
|
16
|
+
type: _sequelize.DataTypes.UUID,
|
17
|
+
defaultValue: _sequelize.DataTypes.UUIDV4,
|
18
|
+
primaryKey: true,
|
19
|
+
allowNull: false,
|
20
|
+
autoIncrement: false
|
21
|
+
},
|
22
|
+
key: {
|
23
|
+
type: _sequelize.DataTypes.STRING(100),
|
24
|
+
allowNull: false
|
25
|
+
},
|
26
|
+
value: {
|
27
|
+
type: _sequelize.DataTypes.STRING(255),
|
28
|
+
allowNull: false
|
29
|
+
},
|
30
|
+
comments: {
|
31
|
+
type: _sequelize.DataTypes.STRING(255),
|
32
|
+
allowNull: true
|
33
|
+
},
|
34
|
+
data: {
|
35
|
+
type: _sequelize.DataTypes.JSON,
|
36
|
+
defaultValue: {},
|
37
|
+
allowNull: true
|
38
|
+
},
|
39
|
+
createdAt: _sequelize.DataTypes.DATE,
|
40
|
+
updatedAt: _sequelize.DataTypes.DATE,
|
41
|
+
deletedAt: _sequelize.DataTypes.DATE
|
42
|
+
});
|
43
|
+
const indexes = [{
|
44
|
+
fields: ['key']
|
45
|
+
}, {
|
46
|
+
fields: ['value']
|
47
|
+
}, {
|
48
|
+
fields: ['comments']
|
49
|
+
}];
|
50
|
+
await (0, _utils.InsertIndexes)(context, tablename, indexes);
|
51
|
+
}
|
52
|
+
async function down({
|
53
|
+
context
|
54
|
+
}) {
|
55
|
+
await context.dropTable(tablename);
|
56
|
+
}
|
@@ -27,7 +27,8 @@ declare class DatabaseService extends Service {
|
|
27
27
|
createDB(hostId: string, name: string): Promise<boolean>;
|
28
28
|
deleteDB(hostId: string, name: string): Promise<boolean>;
|
29
29
|
hasDB(hostId: string, name: string): Promise<boolean>;
|
30
|
-
|
30
|
+
migrateServiceEntities(connection: Sequelize): Promise<void>;
|
31
|
+
migrateCoreEntities(connection: Sequelize): Promise<void>;
|
31
32
|
}
|
32
33
|
export default DatabaseService;
|
33
34
|
//# sourceMappingURL=database.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/services/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACnE,OAAO,EAAsB,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAgB,SAAS,EAAE,MAAM,WAAW,CAAC;
|
1
|
+
{"version":3,"file":"database.d.ts","sour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MAAM;IAmBrC,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAkBlC,sBAAsB,CAAC,UAAU,EAAE,SAAS;IAa5C,mBAAmB,CAAC,UAAU,EAAE,SAAS;CAavD;AAED,eAAe,eAAe,CAAC"}
|
package/lib/services/database.js
CHANGED
@@ -10,6 +10,7 @@ var _models = require("../models");
|
|
10
10
|
var _utils = require("../utils");
|
11
11
|
var _security = _interopRequireDefault(require("./security"));
|
12
12
|
var _umzug = require("umzug");
|
13
|
+
var _path = _interopRequireDefault(require("path"));
|
13
14
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
14
15
|
class DatabaseService extends _app.Service {
|
15
16
|
entities;
|
@@ -63,7 +64,8 @@ class DatabaseService extends _app.Service {
|
|
63
64
|
}
|
64
65
|
const password = data.payload;
|
65
66
|
const connection = await this.createConnection(address, port, database, dbHost.username, password, dbHost.dialect);
|
66
|
-
await this.
|
67
|
+
await this.migrateCoreEntities(connection);
|
68
|
+
await this.migrateServiceEntities(connection);
|
67
69
|
this.connections.set(tenantId, connection);
|
68
70
|
this.log(`Conexão para o tenant ${tenantId} foi criada com sucesso`, 'success');
|
69
71
|
}
|
@@ -228,7 +230,7 @@ class DatabaseService extends _app.Service {
|
|
228
230
|
return false;
|
229
231
|
}
|
230
232
|
}
|
231
|
-
async
|
233
|
+
async migrateServiceEntities(connection) {
|
232
234
|
const umzung = new _umzug.Umzug({
|
233
235
|
migrations: {
|
234
236
|
glob: `${_app.Core.settings.getDatabase().migrationsPath}/*.js`
|
@@ -241,5 +243,19 @@ class DatabaseService extends _app.Service {
|
|
241
243
|
});
|
242
244
|
await umzung.up();
|
243
245
|
}
|
246
|
+
async migrateCoreEntities(connection) {
|
247
|
+
const migrations = _path.default.resolve(__dirname, '../models/migrations');
|
248
|
+
const umzung = new _umzug.Umzug({
|
249
|
+
migrations: {
|
250
|
+
glob: `${migrations}/*.js`
|
251
|
+
},
|
252
|
+
context: connection.getQueryInterface(),
|
253
|
+
storage: new _umzug.SequelizeStorage({
|
254
|
+
sequelize: connection
|
255
|
+
}),
|
256
|
+
logger: console
|
257
|
+
});
|
258
|
+
await umzung.up();
|
259
|
+
}
|
244
260
|
}
|
245
261
|
var _default = exports.default = DatabaseService;
|
package/lib/utils/database.d.ts
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
import { Sequelize, WhereOptions } from 'sequelize';
|
2
|
-
import { IRequestFilterCondition, LogicalCondition } from '../contracts';
|
2
|
+
import { IRequestFilterCondition, LogicalCondition, UmzugMigration } from '../contracts';
|
3
3
|
export declare const mainDb: Sequelize;
|
4
4
|
export declare function processFilters<D>(filters?: Partial<Record<keyof D, IRequestFilterCondition<D>> | LogicalCondition<D>>): WhereOptions<D>;
|
5
|
+
export declare function InsertIndexes(context: UmzugMigration['context'], tableName: string, indexes: {
|
6
|
+
fields: string[];
|
7
|
+
unique?: boolean;
|
8
|
+
}[]): Promise<void>;
|
5
9
|
//# sourceMappingURL=database.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/utils/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,SAAS,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEjE,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;
|
1
|
+
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/utils/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,SAAS,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEjE,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAGzF,eAAO,MAAM,MAAM,WASjB,CAAC;AAgFH,wBAAgB,cAAc,CAAC,CAAC,EAC9B,OAAO,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,uBAAuB,CAAC,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC,GACnF,YAAY,CAAC,CAAC,CAAC,CAwCjB;AAED,wBAAsB,aAAa,CACjC,OAAO,EAAE,cAAc,CAAC,SAAS,CAAC,EAClC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE;IAAE,MAAM,EAAE,MAAM,EAAE,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,EAAE,iBAalD"}
|
package/lib/utils/database.js
CHANGED
@@ -3,10 +3,12 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
+
exports.InsertIndexes = InsertIndexes;
|
6
7
|
exports.mainDb = void 0;
|
7
8
|
exports.processFilters = processFilters;
|
8
9
|
var _sequelize = require("sequelize");
|
9
10
|
var _core = _interopRequireDefault(require("../app/core"));
|
11
|
+
var _error = require("../app/error");
|
10
12
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
11
13
|
const mainDb = exports.mainDb = new _sequelize.Sequelize({
|
12
14
|
database: _core.default.settings.getDatabase().main.database,
|
@@ -20,21 +22,6 @@ const mainDb = exports.mainDb = new _sequelize.Sequelize({
|
|
20
22
|
timezone: '-03:00',
|
21
23
|
logging: _core.default.settings.getDatabase().service.log
|
22
24
|
});
|
23
|
-
|
24
|
-
//!nunca foi usado
|
25
|
-
/* export const masterDB = new Sequelize({
|
26
|
-
database: Core.settings.getDatabase().master.database,
|
27
|
-
dialect: Core.settings.getDatabase().master.dialect,
|
28
|
-
username: Core.settings.getDatabase().master.username,
|
29
|
-
password: Core.settings.getDatabase().master.password,
|
30
|
-
pool: Core.settings.getDatabase().master.pool,
|
31
|
-
define: {
|
32
|
-
timestamps: true
|
33
|
-
},
|
34
|
-
timezone: '-03:00',
|
35
|
-
logging: Core.settings.getDatabase().service.log
|
36
|
-
}); */
|
37
|
-
|
38
25
|
function processCondition(cond) {
|
39
26
|
if ('or' in cond) {
|
40
27
|
return {
|
@@ -154,4 +141,17 @@ function processFilters(filters) {
|
|
154
141
|
}
|
155
142
|
});
|
156
143
|
return where;
|
144
|
+
}
|
145
|
+
async function InsertIndexes(context, tableName, indexes) {
|
146
|
+
for (const index of indexes) {
|
147
|
+
try {
|
148
|
+
await context.addIndex(tableName, index.fields, {
|
149
|
+
name: `${tableName}_${index.fields.join('_')}`,
|
150
|
+
unique: index.unique
|
151
|
+
});
|
152
|
+
} catch (error) {
|
153
|
+
new _error.ErrorHandler('tentativa de adicionar index falhou', error);
|
154
|
+
console.log('tentativa de adicionar index falhou');
|
155
|
+
}
|
156
|
+
}
|
157
157
|
}
|