exodus-framework 2.1.1036 → 2.1.1037
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.
@@ -34,7 +34,7 @@ declare class DatabaseService extends Service {
|
|
34
34
|
* @param {Sequelize} connection
|
35
35
|
* @memberof DatabaseService
|
36
36
|
*/
|
37
|
-
execTenantMigrates(connection: Sequelize): Promise<void>;
|
37
|
+
execTenantMigrates(connection: Sequelize, downgrades?: string[]): Promise<void>;
|
38
38
|
/**
|
39
39
|
* Usado para acionar migrações especificas do core
|
40
40
|
*
|
@@ -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,EAAgB,SAAS,EAAE,MAAM,WAAW,CAAC;AAKpD,cAAM,eAAgB,SAAQ,OAAO;IACnC,OAAO,CAAC,QAAQ,CAAgC;IAChD,OAAO,CAAC,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|
async onStart() {
|
28
28
|
this.log(`⌛️ Connecting Sequelize to database: ${this.currentStartAttempts}/${this.maxStartAttempts}`);
|
29
29
|
try {
|
30
|
+
const downgrades = process.env.DB_TENANT_DOWNGRADE_MIGRATES ? process.env.DB_TENANT_DOWNGRADE_MIGRATES.split(',').map(m => m.trim()) : [];
|
30
31
|
await _utils.mainDb.authenticate();
|
31
32
|
await _utils.mainDb.sync({
|
32
33
|
alter: true
|
33
34
|
});
|
34
35
|
await this.execServiceMigrate();
|
35
|
-
await this.execTenantMigrates(_utils.mainDb);
|
36
|
+
await this.execTenantMigrates(_utils.mainDb, downgrades);
|
36
37
|
this.log('✅ Connected service database sucessfully', 'success');
|
37
38
|
if (process.env.DB_INIT_WITH_MIGRATE === 'true') {
|
38
39
|
const tenants = await this.getAllTenants();
|
@@ -41,7 +42,7 @@ class DatabaseService extends _app.Service {
|
|
41
42
|
const sequelize = await this.getConnection(tenant.envUuid, false);
|
42
43
|
if (sequelize) {
|
43
44
|
this.log(`⌚ Executando migração no tenant ${tenant.envToken} | ${tenant.envUuid}`, 'warning');
|
44
|
-
await this.execTenantMigrates(sequelize);
|
45
|
+
await this.execTenantMigrates(sequelize, downgrades);
|
45
46
|
this.log(`✅ Tenant migrado com sucesso ${tenant.envToken} | ${tenant.envUuid}`, 'success');
|
46
47
|
}
|
47
48
|
}
|
@@ -248,7 +249,7 @@ class DatabaseService extends _app.Service {
|
|
248
249
|
* @param {Sequelize} connection
|
249
250
|
* @memberof DatabaseService
|
250
251
|
*/
|
251
|
-
async execTenantMigrates(connection) {
|
252
|
+
async execTenantMigrates(connection, downgrades = []) {
|
252
253
|
const migrations = _app.Core.settings.getDatabase().migrationsPath;
|
253
254
|
const umzung = new _umzug.Umzug({
|
254
255
|
migrations: {
|
@@ -260,6 +261,14 @@ class DatabaseService extends _app.Service {
|
|
260
261
|
}),
|
261
262
|
logger: console
|
262
263
|
});
|
264
|
+
if (downgrades.length > 0) {
|
265
|
+
for (const down of downgrades) {
|
266
|
+
this.log(`⚠️ Downgrade migration: ${down}`, 'warning');
|
267
|
+
await umzung.down({
|
268
|
+
to: down
|
269
|
+
});
|
270
|
+
}
|
271
|
+
}
|
263
272
|
await umzung.up();
|
264
273
|
}
|
265
274
|
|