@crowdin/app-project-module 0.86.0 → 0.86.1
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/postgre.d.ts +1 -0
- package/out/storage/postgre.js +38 -0
- package/package.json +1 -1
package/out/storage/postgre.d.ts
CHANGED
|
@@ -114,5 +114,6 @@ export declare class PostgreStorage implements Storage {
|
|
|
114
114
|
saveSyncedData(files: any, integrationId: string, crowdinId: string, type: string): Promise<void>;
|
|
115
115
|
updateSyncedData(files: any, integrationId: string, crowdinId: string, type: string): Promise<void>;
|
|
116
116
|
getSyncedData(integrationId: string, crowdinId: string, type: string): Promise<IntegrationSyncedData | undefined>;
|
|
117
|
+
resetSequences(): Promise<void>;
|
|
117
118
|
}
|
|
118
119
|
export {};
|
package/out/storage/postgre.js
CHANGED
|
@@ -204,6 +204,9 @@ class PostgreStorage {
|
|
|
204
204
|
this._res && this._res();
|
|
205
205
|
// TODO: temporary code
|
|
206
206
|
yield this.executeQuery((client) => this.alterTables(client));
|
|
207
|
+
// Reset sequences for tables with serial primary keys
|
|
208
|
+
// TODO: remove this after migration
|
|
209
|
+
yield this.resetSequences();
|
|
207
210
|
}
|
|
208
211
|
catch (e) {
|
|
209
212
|
console.error(e);
|
|
@@ -798,6 +801,8 @@ class PostgreStorage {
|
|
|
798
801
|
fs_1.default.renameSync(filePath, filePath.replace('dump_table_', 'error_dump_table_'));
|
|
799
802
|
}
|
|
800
803
|
}
|
|
804
|
+
// Reset sequences for tables with serial primary keys
|
|
805
|
+
yield this.resetSequences();
|
|
801
806
|
});
|
|
802
807
|
}
|
|
803
808
|
saveUnsyncedFiles({ integrationId, crowdinId, files }) {
|
|
@@ -918,5 +923,38 @@ class PostgreStorage {
|
|
|
918
923
|
}));
|
|
919
924
|
});
|
|
920
925
|
}
|
|
926
|
+
resetSequences() {
|
|
927
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
928
|
+
yield this.dbPromise;
|
|
929
|
+
yield this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
930
|
+
const tables = Object.keys(this.tables);
|
|
931
|
+
for (const table of tables) {
|
|
932
|
+
try {
|
|
933
|
+
const primaryKeyResult = yield client.query(`
|
|
934
|
+
SELECT a.attname
|
|
935
|
+
FROM pg_index i
|
|
936
|
+
JOIN pg_attribute a ON a.attrelid = i.indrelid AND a.attnum = ANY(i.indkey)
|
|
937
|
+
WHERE i.indrelid = '${table}'::regclass
|
|
938
|
+
AND i.indisprimary;
|
|
939
|
+
`);
|
|
940
|
+
if (primaryKeyResult.rows.length === 0) {
|
|
941
|
+
continue;
|
|
942
|
+
}
|
|
943
|
+
const primaryKey = primaryKeyResult.rows[0].attname;
|
|
944
|
+
const maxIdResult = yield client.query(`SELECT MAX(${primaryKey}) FROM ${table}`);
|
|
945
|
+
const maxId = maxIdResult.rows[0].max;
|
|
946
|
+
// Skip if maxId is not a valid integer
|
|
947
|
+
if (maxId === null || isNaN(Number(maxId))) {
|
|
948
|
+
continue;
|
|
949
|
+
}
|
|
950
|
+
yield client.query(`SELECT setval('${table}_${primaryKey}_seq', ${Number(maxId)}, true)`);
|
|
951
|
+
}
|
|
952
|
+
catch (error) {
|
|
953
|
+
console.error(`Error resetting sequence for table ${table}:`, error);
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
}));
|
|
957
|
+
});
|
|
958
|
+
}
|
|
921
959
|
}
|
|
922
960
|
exports.PostgreStorage = PostgreStorage;
|
package/package.json
CHANGED