exodus-framework 2.1.1008 → 2.1.1010
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.
@@ -20,6 +20,7 @@ declare class DatabaseService extends Service {
|
|
20
20
|
}): Promise<boolean>;
|
21
21
|
private createConnectionByHost;
|
22
22
|
getTenantIds(): Promise<string[]>;
|
23
|
+
getAllTenants(): Promise<EnvDBHost[]>;
|
23
24
|
getTenantInformation(tenantId: string): Promise<EnvDBHost>;
|
24
25
|
private loadEntity;
|
25
26
|
getEntity<M extends ServiceModel<Model>>(model: StaticServiceModel<M>, tenantId: string): Promise<ModelStatic<M>>;
|
@@ -27,9 +28,9 @@ declare class DatabaseService extends Service {
|
|
27
28
|
createDB(hostId: string, name: string): Promise<boolean>;
|
28
29
|
deleteDB(hostId: string, name: string): Promise<boolean>;
|
29
30
|
hasDB(hostId: string, name: string): Promise<boolean>;
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
execTenantMigrates(connection: Sequelize): Promise<void>;
|
32
|
+
execCoreMigrates(connection: Sequelize): Promise<void>;
|
33
|
+
execServiceMigrate(): Promise<void>;
|
33
34
|
}
|
34
35
|
export default DatabaseService;
|
35
36
|
//# 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;I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IA+BrC,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAmBrC,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAwBlC,kBAAkB,CAAC,UAAU,EAAE,SAAS;IAoBxC,gBAAgB,CAAC,UAAU,EAAE,SAAS;IAoBtC,kBAAkB;CAehC;AAED,eAAe,eAAe,CAAC"}
|
package/lib/services/database.js
CHANGED
@@ -33,9 +33,20 @@ class DatabaseService extends _app.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
|
+
const tenants = await this.getAllTenants();
|
41
|
+
this.log(`⌚ Iniciando migração de ${tenants.length} tenants...`, 'warning');
|
42
|
+
for (const tenant of tenants) {
|
43
|
+
const sequelize = await this.getConnection(tenant.envUuid);
|
44
|
+
if (sequelize) {
|
45
|
+
this.log(`⌚ Executando migração no tenant ${tenant.envToken} | ${tenant.envUuid}`, '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
|
}
|
@@ -148,6 +159,10 @@ class DatabaseService extends _app.Service {
|
|
148
159
|
});
|
149
160
|
return tenants.map(t => t.envUuid);
|
150
161
|
}
|
162
|
+
async getAllTenants() {
|
163
|
+
const tenants = await _models.EnvDBHost.findAll();
|
164
|
+
return tenants;
|
165
|
+
}
|
151
166
|
async getTenantInformation(tenantId) {
|
152
167
|
const relation = await _models.EnvDBHost.findOne({
|
153
168
|
where: {
|
@@ -188,8 +203,8 @@ class DatabaseService extends _app.Service {
|
|
188
203
|
await connection.query(`CREATE DATABASE ${dbQueryName};`);
|
189
204
|
this.log(`Database "${dbQueryName}" has been created.`);
|
190
205
|
await connection.query(`USE ${dbQueryName};`);
|
191
|
-
await this.
|
192
|
-
await this.
|
206
|
+
await this.execCoreMigrates(connection);
|
207
|
+
await this.execTenantMigrates(connection);
|
193
208
|
return true;
|
194
209
|
} else {
|
195
210
|
this.log(`Database "${dbQueryName}" already exists.`);
|
@@ -244,11 +259,11 @@ class DatabaseService extends _app.Service {
|
|
244
259
|
* @param {Sequelize} connection
|
245
260
|
* @memberof DatabaseService
|
246
261
|
*/
|
247
|
-
async
|
262
|
+
async execTenantMigrates(connection) {
|
248
263
|
const migrations = _app.Core.settings.getDatabase().migrationsPath;
|
249
264
|
const umzung = new _umzug.Umzug({
|
250
265
|
migrations: {
|
251
|
-
glob: `${migrations}/*.js`
|
266
|
+
glob: `${migrations}/*.{js,ts}`
|
252
267
|
},
|
253
268
|
context: connection.getQueryInterface(),
|
254
269
|
storage: new _umzug.SequelizeStorage({
|
@@ -265,7 +280,7 @@ class DatabaseService extends _app.Service {
|
|
265
280
|
* @param {Sequelize} connection
|
266
281
|
* @memberof DatabaseService
|
267
282
|
*/
|
268
|
-
async
|
283
|
+
async execCoreMigrates(connection) {
|
269
284
|
const migrations = _path.default.resolve(__dirname, '../models/migrations');
|
270
285
|
const umzung = new _umzug.Umzug({
|
271
286
|
migrations: {
|
@@ -285,7 +300,7 @@ class DatabaseService extends _app.Service {
|
|
285
300
|
*
|
286
301
|
* @memberof DatabaseService
|
287
302
|
*/
|
288
|
-
async
|
303
|
+
async execServiceMigrate() {
|
289
304
|
const path = `${_app.Core.settings.getDatabase().migrationsPath}/main`;
|
290
305
|
(0, _fs.mkdirSync)(path, {
|
291
306
|
recursive: true
|