@massalabs/gossip-sdk 0.0.2-dev.20260225133037 → 0.0.2-dev.20260225142738
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/dist/db/migrate.js +10 -1
- package/package.json +1 -1
package/dist/db/migrate.js
CHANGED
|
@@ -6,6 +6,15 @@
|
|
|
6
6
|
* a failure at migration N leaves 0..N-1 committed.
|
|
7
7
|
*/
|
|
8
8
|
import { MIGRATIONS } from './generated-migrations.js';
|
|
9
|
+
function makeCreateStatementsIdempotent(statement) {
|
|
10
|
+
if (/^\s*CREATE\s+TABLE\s+(?!IF\s+NOT\s+EXISTS)/i.test(statement)) {
|
|
11
|
+
return statement.replace(/^(\s*CREATE\s+TABLE\s+)/i, '$1IF NOT EXISTS ');
|
|
12
|
+
}
|
|
13
|
+
if (/^\s*CREATE\s+(UNIQUE\s+)?INDEX\s+(?!IF\s+NOT\s+EXISTS)/i.test(statement)) {
|
|
14
|
+
return statement.replace(/^(\s*CREATE\s+(?:UNIQUE\s+)?INDEX\s+)/i, '$1IF NOT EXISTS ');
|
|
15
|
+
}
|
|
16
|
+
return statement;
|
|
17
|
+
}
|
|
9
18
|
export async function runMigrations(execRaw, withTransaction) {
|
|
10
19
|
await execRaw(`CREATE TABLE IF NOT EXISTS _migrations (
|
|
11
20
|
idx INTEGER PRIMARY KEY,
|
|
@@ -18,7 +27,7 @@ export async function runMigrations(execRaw, withTransaction) {
|
|
|
18
27
|
for (const migration of pending) {
|
|
19
28
|
await withTransaction(async () => {
|
|
20
29
|
for (const stmt of migration.statements) {
|
|
21
|
-
await execRaw(stmt);
|
|
30
|
+
await execRaw(makeCreateStatementsIdempotent(stmt));
|
|
22
31
|
}
|
|
23
32
|
await execRaw('INSERT INTO _migrations (idx, tag, applied_at) VALUES (?, ?, ?)', [migration.idx, migration.tag, Date.now()]);
|
|
24
33
|
});
|
package/package.json
CHANGED