exodus-framework 2.1.1008 → 2.1.1009
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.
@@ -27,9 +27,9 @@ 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
|
-
|
31
|
-
|
32
|
-
|
30
|
+
execTenantMigrates(connection: Sequelize): Promise<void>;
|
31
|
+
execCoreMigrates(connection: Sequelize): Promise<void>;
|
32
|
+
execServiceMigrate(): Promise<void>;
|
33
33
|
}
|
34
34
|
export default DatabaseService;
|
35
35
|
//# sourceMappingURL=database.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/services/database.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEnE,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;AAKpD,cAAM,eAAgB,SAAQ,OAAO;IACnC,OAAO,CAAC,QAAQ,CAAgC;IAChD,OAAO,CAAC,WAAW,CAAyB;IAE/B,aAAa;IAWb,OAAO;
|
1
|
+
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/services/database.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEnE,OAAO,EAAsB,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAg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Service {
|
|
33
33
|
await _utils.mainDb.sync({
|
34
34
|
alter: true
|
35
35
|
});
|
36
|
-
await this.
|
37
|
-
await this.
|
36
|
+
await this.execServiceMigrate(); // migrar atualizações do serviço
|
37
|
+
await this.execTenantMigrates(_utils.mainDb); //migrar atualizações do tenant para o serviço principal (este ainda é usado como serviço/tenant para supersu)
|
38
38
|
this.log('✅ Connected service database sucessfully', 'success');
|
39
|
+
if (process.env.DB_INIT_WITH_MIGRATE === 'true') {
|
40
|
+
this.log('⌚ Migrando entidades do serviço...', 'warning');
|
41
|
+
const tenants = await this.getTenantIds();
|
42
|
+
for (const tenantId of tenants) {
|
43
|
+
const sequelize = await this.getConnection(tenantId);
|
44
|
+
if (sequelize) {
|
45
|
+
this.log(`⌚ Migrando entidades do tenant ${tenantId}...`, 'warning');
|
46
|
+
await this.execTenantMigrates(sequelize);
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}
|
39
50
|
return true;
|
40
51
|
} catch (error) {
|
41
52
|
_logger.default.logger().error(error, `Not connected Sequelize to database`);
|
@@ -68,8 +79,8 @@ class DatabaseService extends _app.Service {
|
|
68
79
|
}
|
69
80
|
const password = data.payload;
|
70
81
|
const connection = await this.createConnection(address, port, database, dbHost.username, password, dbHost.dialect);
|
71
|
-
await this.
|
72
|
-
await this.
|
82
|
+
await this.execCoreMigrates(connection);
|
83
|
+
await this.execTenantMigrates(connection);
|
73
84
|
this.connections.set(tenantId, connection);
|
74
85
|
this.log(`Conexão para o tenant ${tenantId} foi criada com sucesso`, 'success');
|
75
86
|
}
|
@@ -188,8 +199,8 @@ class DatabaseService extends _app.Service {
|
|
188
199
|
await connection.query(`CREATE DATABASE ${dbQueryName};`);
|
189
200
|
this.log(`Database "${dbQueryName}" has been created.`);
|
190
201
|
await connection.query(`USE ${dbQueryName};`);
|
191
|
-
await this.
|
192
|
-
await this.
|
202
|
+
await this.execCoreMigrates(connection);
|
203
|
+
await this.execTenantMigrates(connection);
|
193
204
|
return true;
|
194
205
|
} else {
|
195
206
|
this.log(`Database "${dbQueryName}" already exists.`);
|
@@ -244,7 +255,7 @@ class DatabaseService extends _app.Service {
|
|
244
255
|
* @param {Sequelize} connection
|
245
256
|
* @memberof DatabaseService
|
246
257
|
*/
|
247
|
-
async
|
258
|
+
async execTenantMigrates(connection) {
|
248
259
|
const migrations = _app.Core.settings.getDatabase().migrationsPath;
|
249
260
|
const umzung = new _umzug.Umzug({
|
250
261
|
migrations: {
|
@@ -265,7 +276,7 @@ class DatabaseService extends _app.Service {
|
|
265
276
|
* @param {Sequelize} connection
|
266
277
|
* @memberof DatabaseService
|
267
278
|
*/
|
268
|
-
async
|
279
|
+
async execCoreMigrates(connection) {
|
269
280
|
const migrations = _path.default.resolve(__dirname, '../models/migrations');
|
270
281
|
const umzung = new _umzug.Umzug({
|
271
282
|
migrations: {
|
@@ -285,7 +296,7 @@ class DatabaseService extends _app.Service {
|
|
285
296
|
*
|
286
297
|
* @memberof DatabaseService
|
287
298
|
*/
|
288
|
-
async
|
299
|
+
async execServiceMigrate() {
|
289
300
|
const path = `${_app.Core.settings.getDatabase().migrationsPath}/main`;
|
290
301
|
(0, _fs.mkdirSync)(path, {
|
291
302
|
recursive: true
|