@crowdin/app-project-module 0.101.0 → 0.102.0
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/out/storage/index.js
CHANGED
|
@@ -70,7 +70,7 @@ function initialize(config) {
|
|
|
70
70
|
dumpDirectory = config.dbFolder;
|
|
71
71
|
createDumpForMigration(config);
|
|
72
72
|
}
|
|
73
|
-
storage = new postgre_1.PostgreStorage(config
|
|
73
|
+
storage = new postgre_1.PostgreStorage(config, dumpDirectory);
|
|
74
74
|
}
|
|
75
75
|
else if (config.mysqlConfig) {
|
|
76
76
|
(0, logger_1.log)('Using MySQL database');
|
package/out/storage/postgre.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Client } from 'pg';
|
|
2
2
|
import { Storage } from '.';
|
|
3
|
-
import { CrowdinCredentials } from '../types';
|
|
3
|
+
import { Config, UnauthorizedConfig, CrowdinCredentials } from '../types';
|
|
4
4
|
import { IntegrationConfig, IntegrationCredentials, IntegrationFilesSnapshot, IntegrationSyncSettings, IntegrationWebhooks } from '../modules/integration/types';
|
|
5
5
|
import { CreateJobParams, GetActiveJobsParams, GetJobParams, GetFileTranslationCacheByLanguageParams, Job, TranslationCache, UpdateJobParams, UpdateTranslationCacheParams, GetFileTranslationCache, UnsyncedFiles, GetUnsyncedFiles, IntegrationSyncedData, GetAllJobsParams } from '../modules/integration/util/types';
|
|
6
6
|
import { UserErrors } from './types';
|
|
@@ -24,6 +24,7 @@ interface TableIndexes {
|
|
|
24
24
|
export declare class PostgreStorage implements Storage {
|
|
25
25
|
private config;
|
|
26
26
|
private directoryPath;
|
|
27
|
+
private migrationLockId;
|
|
27
28
|
private _res?;
|
|
28
29
|
private _rej?;
|
|
29
30
|
private dbPromise;
|
|
@@ -42,7 +43,8 @@ export declare class PostgreStorage implements Storage {
|
|
|
42
43
|
synced_data: string;
|
|
43
44
|
};
|
|
44
45
|
tableIndexes: TableIndexes;
|
|
45
|
-
constructor(config:
|
|
46
|
+
constructor(config: Config | UnauthorizedConfig, directoryPath: string | null);
|
|
47
|
+
private generateLockId;
|
|
46
48
|
executeQuery<T>(command: (client: Client) => Promise<T>): Promise<T>;
|
|
47
49
|
private hasDumpFiles;
|
|
48
50
|
migrate(): Promise<void>;
|
package/out/storage/postgre.js
CHANGED
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
exports.PostgreStorage = void 0;
|
|
18
18
|
const pg_1 = require("pg");
|
|
19
19
|
const uuid_1 = require("uuid");
|
|
20
|
+
const crypto_1 = require("crypto");
|
|
20
21
|
const types_1 = require("../types");
|
|
21
22
|
const types_2 = require("../modules/integration/util/types");
|
|
22
23
|
const util_1 = require("../util");
|
|
@@ -171,8 +172,15 @@ class PostgreStorage {
|
|
|
171
172
|
idx_crowdin: '(crowdin_id)',
|
|
172
173
|
},
|
|
173
174
|
};
|
|
174
|
-
this.config = config;
|
|
175
|
+
this.config = config.postgreConfig;
|
|
175
176
|
this.directoryPath = directoryPath;
|
|
177
|
+
this.migrationLockId = this.generateLockId(config.name);
|
|
178
|
+
}
|
|
179
|
+
generateLockId(str) {
|
|
180
|
+
// Create MD5 hash of the string
|
|
181
|
+
const hash = (0, crypto_1.createHash)('md5').update(str).digest('hex');
|
|
182
|
+
// Take first 8 hex characters and convert to integer
|
|
183
|
+
return parseInt(hash.substring(0, 8), 16);
|
|
176
184
|
}
|
|
177
185
|
executeQuery(command) {
|
|
178
186
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -210,10 +218,19 @@ class PostgreStorage {
|
|
|
210
218
|
if (this.directoryPath && this.hasDumpFiles(this.directoryPath)) {
|
|
211
219
|
yield this.migrateFromSqlite(this.directoryPath);
|
|
212
220
|
}
|
|
213
|
-
|
|
221
|
+
// Use advisory lock to prevent concurrent migrations
|
|
222
|
+
yield this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
223
|
+
yield client.query('SELECT pg_advisory_lock($1)', [this.migrationLockId]);
|
|
224
|
+
try {
|
|
225
|
+
yield this.addTables(client);
|
|
226
|
+
// TODO: temporary code
|
|
227
|
+
yield this.alterTables(client);
|
|
228
|
+
}
|
|
229
|
+
finally {
|
|
230
|
+
yield client.query('SELECT pg_advisory_unlock($1)', [this.migrationLockId]);
|
|
231
|
+
}
|
|
232
|
+
}));
|
|
214
233
|
this._res && this._res();
|
|
215
|
-
// TODO: temporary code
|
|
216
|
-
yield this.executeQuery((client) => this.alterTables(client));
|
|
217
234
|
}
|
|
218
235
|
catch (e) {
|
|
219
236
|
console.error(e);
|
package/package.json
CHANGED