exodus-framework 2.1.1011 → 2.1.1013
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.
@@ -10,7 +10,7 @@ declare class DatabaseService extends Service {
|
|
10
10
|
onStartFail(): Promise<void>;
|
11
11
|
private initConnection;
|
12
12
|
createConnection(host: string, port: number, database: string, username: string, password: string, dialect: Dialect): Promise<Sequelize>;
|
13
|
-
getConnection(tenantId: string): Promise<Sequelize>;
|
13
|
+
getConnection(tenantId: string, migrate?: boolean): Promise<Sequelize>;
|
14
14
|
testConnection(data: {
|
15
15
|
host: string;
|
16
16
|
port: number;
|
@@ -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,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(`⌚ Iniciando migração de ${tenants.length} tenants...`, 'warning');
|
42
42
|
for (const tenant of tenants) {
|
43
|
-
const sequelize = await this.getConnection(tenant.envUuid);
|
43
|
+
const sequelize = await this.getConnection(tenant.envUuid, false);
|
44
44
|
if (sequelize) {
|
45
45
|
this.log(`⌚ Executando migração no tenant ${tenant.envToken} | ${tenant.envUuid}`, 'warning');
|
46
46
|
await this.execTenantMigrates(sequelize);
|
47
|
+
this.log(`✅ Tenant migrado com sucesso ${tenant.envToken} | ${tenant.envUuid}`, 'success');
|
47
48
|
}
|
48
49
|
}
|
49
50
|
}
|
@@ -59,7 +60,7 @@ class DatabaseService extends _app.Service {
|
|
59
60
|
}
|
60
61
|
|
61
62
|
//* Connection
|
62
|
-
async initConnection(tenantId) {
|
63
|
+
async initConnection(tenantId, migrate = true) {
|
63
64
|
const tenantInfo = await this.getTenantInformation(tenantId);
|
64
65
|
if (!tenantInfo) {
|
65
66
|
throw new Error(`Não é possível inicia a conexão para o tenant ${tenantId}, a relação EnvDB não foi localizada`);
|
@@ -79,8 +80,10 @@ class DatabaseService extends _app.Service {
|
|
79
80
|
}
|
80
81
|
const password = data.payload;
|
81
82
|
const connection = await this.createConnection(address, port, database, dbHost.username, password, dbHost.dialect);
|
82
|
-
|
83
|
-
|
83
|
+
if (migrate) {
|
84
|
+
await this.execCoreMigrates(connection); //para incluir recursos gerenciados pelo core para o tenant/service
|
85
|
+
await this.execTenantMigrates(connection);
|
86
|
+
}
|
84
87
|
this.connections.set(tenantId, connection);
|
85
88
|
this.log(`Conexão para o tenant ${tenantId} foi criada com sucesso`, 'success');
|
86
89
|
}
|
@@ -107,9 +110,9 @@ class DatabaseService extends _app.Service {
|
|
107
110
|
return null;
|
108
111
|
}
|
109
112
|
}
|
110
|
-
async getConnection(tenantId) {
|
113
|
+
async getConnection(tenantId, migrate = true) {
|
111
114
|
if (!this.connections.has(tenantId)) {
|
112
|
-
await this.initConnection(tenantId);
|
115
|
+
await this.initConnection(tenantId, migrate);
|
113
116
|
}
|
114
117
|
return this.connections.get(tenantId);
|
115
118
|
}
|