exodus-framework 2.0.956 → 2.0.959
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/app/settings.js
CHANGED
@@ -73,11 +73,11 @@ class CoreSettings {
|
|
73
73
|
return;
|
74
74
|
},
|
75
75
|
pool: {
|
76
|
-
max:
|
76
|
+
max: 5,
|
77
77
|
// Número máximo de conexões no pool
|
78
|
-
min:
|
78
|
+
min: 1,
|
79
79
|
// Número mínimo de conexões no pool
|
80
|
-
acquire:
|
80
|
+
acquire: 20000,
|
81
81
|
// Tempo máximo (em ms) para adquirir uma conexão do pool
|
82
82
|
idle: 10000 // Tempo máximo (em ms) que uma conexão pode ficar inativa
|
83
83
|
}
|
@@ -11,11 +11,19 @@ declare class DatabaseService extends Service {
|
|
11
11
|
private initConnection;
|
12
12
|
createConnection(host: string, port: number, database: string, username: string, password: string, dialect: Dialect): Promise<Sequelize>;
|
13
13
|
getConnection(tenantId: string): Promise<Sequelize>;
|
14
|
+
testConnection(data: {
|
15
|
+
host: string;
|
16
|
+
port: number;
|
17
|
+
username: string;
|
18
|
+
password: string;
|
19
|
+
dialect: Dialect;
|
20
|
+
}): Promise<boolean>;
|
14
21
|
getTenantIds(): Promise<string[]>;
|
15
22
|
getTenantInformation(tenantId: string): Promise<EnvDBHost>;
|
16
23
|
private loadEntity;
|
17
24
|
getEntity<M extends ServiceModel<Model>>(model: StaticServiceModel<M>, tenantId: string): Promise<ModelStatic<M>>;
|
18
25
|
private normalizeDatabaseName;
|
26
|
+
createDB(hostUuid: string, name: string): Promise<boolean>;
|
19
27
|
}
|
20
28
|
export default DatabaseService;
|
21
29
|
//# 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,CA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AI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,OAAO,CAAC;KAClB;IA4BY,YAAY;IAKZ,oBAAoB,CAAC,QAAQ,EAAE,MAAM;YAMpC,UAAU;IASX,SAAS,CAAC,CAAC,SAAS,YAAY,CAAC,KAAK,CAAC,EAClD,KAAK,EAAE,kBAAkB,CAAC,CAAC,CAAC,EAC5B,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAU1B,OAAO,CAAC,qBAAqB;IAIvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;CAqD9C;AAED,eAAe,eAAe,CAAC"}
|
package/lib/services/database.js
CHANGED
@@ -93,6 +93,28 @@ class DatabaseService extends _app.Service {
|
|
93
93
|
}
|
94
94
|
return this.connections.get(tenantId);
|
95
95
|
}
|
96
|
+
async testConnection(data) {
|
97
|
+
const sequelize = new _sequelize.Sequelize({
|
98
|
+
host: data.host,
|
99
|
+
port: data.port,
|
100
|
+
username: data.username,
|
101
|
+
password: data.password,
|
102
|
+
dialect: data.dialect,
|
103
|
+
timezone: '-03:00',
|
104
|
+
pool: _app.Core.settings.getDatabase().service.pool,
|
105
|
+
logging: _app.Core.settings.getDatabase().service.log
|
106
|
+
});
|
107
|
+
return new Promise(resolve => {
|
108
|
+
sequelize.authenticate().then(async () => {
|
109
|
+
resolve(true);
|
110
|
+
}).catch(reason => {
|
111
|
+
new _app.ErrorHandler('teste de conexão falhou', reason);
|
112
|
+
resolve(false);
|
113
|
+
}).finally(() => {
|
114
|
+
sequelize.close();
|
115
|
+
});
|
116
|
+
});
|
117
|
+
}
|
96
118
|
|
97
119
|
//* Environment
|
98
120
|
async getTenantIds() {
|
@@ -132,5 +154,44 @@ class DatabaseService extends _app.Service {
|
|
132
154
|
normalizeDatabaseName(envToken) {
|
133
155
|
return `${_app.Core.settings.getDatabase().main.database}_${envToken}`;
|
134
156
|
}
|
157
|
+
async createDB(hostUuid, name) {
|
158
|
+
const host = await _models.DatabaseHost.findByPk(hostUuid);
|
159
|
+
if (!host) {
|
160
|
+
this.log('Database host information not found: ' + hostUuid);
|
161
|
+
return false;
|
162
|
+
}
|
163
|
+
const dbQueryName = `${_app.Core.settings.getDatabase().main.database}_${name}`;
|
164
|
+
const splitedInfo = host.host.split(':');
|
165
|
+
const address = splitedInfo[0];
|
166
|
+
const port = Number(splitedInfo[1]);
|
167
|
+
const key = await _security.default.getService().loadKeyByStr(host.credential);
|
168
|
+
const data = await _security.default.getService().verifySignature(host.password, key);
|
169
|
+
if (!data) {
|
170
|
+
throw new Error(`Não foi possível descriptografar as credenciais de conexão para hostUuid: ${hostUuid}`);
|
171
|
+
}
|
172
|
+
const password = data.payload;
|
173
|
+
const connection = await this.createConnection(address, port, undefined,
|
174
|
+
//! apenas retornar a conexão
|
175
|
+
host.username, password, host.dialect);
|
176
|
+
if (connection) {
|
177
|
+
try {
|
178
|
+
const [results] = await connection.query(`SHOW DATABASES LIKE '${dbQueryName}';`);
|
179
|
+
if (results.length === 0) {
|
180
|
+
// Se o banco de dados não existir, cria-o
|
181
|
+
await connection.query(`CREATE DATABASE ${dbQueryName};`);
|
182
|
+
this.log(`Database "${dbQueryName}" has been created.`);
|
183
|
+
return true;
|
184
|
+
} else {
|
185
|
+
this.log(`Database "${dbQueryName}" already exists.`);
|
186
|
+
return false;
|
187
|
+
}
|
188
|
+
} catch (error) {
|
189
|
+
new _app.ErrorHandler('Erro on creating database', error);
|
190
|
+
} finally {
|
191
|
+
connection.close();
|
192
|
+
}
|
193
|
+
}
|
194
|
+
return false;
|
195
|
+
}
|
135
196
|
}
|
136
197
|
var _default = exports.default = DatabaseService;
|