@effectstream/db 0.103.3 → 0.104.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.
|
@@ -4,11 +4,10 @@ import { until } from "effection";
|
|
|
4
4
|
import * as migrationFiles from "./assets.ts";
|
|
5
5
|
import {
|
|
6
6
|
acquireDBMutex,
|
|
7
|
-
getLatestProcessedBlockHeight,
|
|
8
|
-
getLatestVersion,
|
|
9
7
|
releaseDBMutex,
|
|
10
|
-
|
|
11
|
-
} from "
|
|
8
|
+
} from "../src/pg-connection.ts";
|
|
9
|
+
import { getLatestProcessedBlockHeight } from "../src/sql/block-heights.queries.ts";
|
|
10
|
+
import { getLatestVersion, tableExists } from "../src/sql/system.queries.ts";
|
|
12
11
|
type VERSION = `${number}.${number}.${number}`;
|
|
13
12
|
type VERSION_NUMBER = [number, number, number];
|
|
14
13
|
// NOTE Hardcoded on purpose: the engine cannot read a package manifest at
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effectstream/db",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.104.0",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"homepage": "https://effectstream.github.io/docs/",
|
|
6
6
|
"repository": {
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
"./version": "./migrations/system-version.ts"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@effectstream/coroutine": "0.
|
|
25
|
-
"@effectstream/log": "0.
|
|
26
|
-
"@effectstream/runtime": "0.
|
|
27
|
-
"@effectstream/sync": "0.
|
|
28
|
-
"@effectstream/utils": "0.
|
|
24
|
+
"@effectstream/coroutine": "0.104.0",
|
|
25
|
+
"@effectstream/log": "0.104.0",
|
|
26
|
+
"@effectstream/runtime": "0.104.0",
|
|
27
|
+
"@effectstream/sync": "0.104.0",
|
|
28
|
+
"@effectstream/utils": "0.104.0",
|
|
29
29
|
"@electric-sql/pglite": "^0.3.14",
|
|
30
30
|
"@pgtyped/runtime": "2.4.2",
|
|
31
31
|
"@pgtyped/parser": "2.4.2",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getConnection } from "../src/pg-connection.ts";
|
|
2
2
|
import { getMigrations } from "../migrations/system-version.ts";
|
|
3
3
|
import type { Client } from "pg";
|
|
4
|
-
import { insertPaimaEngineMigration } from "
|
|
4
|
+
import { insertPaimaEngineMigration } from "../src/sql/system.queries.ts";
|
|
5
5
|
|
|
6
6
|
export async function applyMigrations(
|
|
7
7
|
db: Client,
|
package/scripts/start-pglite.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { args, cwd } from "@effectstream/utils/runtime";
|
|
|
10
10
|
export interface PgliteHandle {
|
|
11
11
|
server: net.Server;
|
|
12
12
|
db: PGlite;
|
|
13
|
+
port: number;
|
|
13
14
|
close: () => Promise<void>;
|
|
14
15
|
}
|
|
15
16
|
|
|
@@ -67,18 +68,43 @@ export async function startPglite(port = 5432): Promise<PgliteHandle> {
|
|
|
67
68
|
});
|
|
68
69
|
});
|
|
69
70
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
const sockets = new Set<net.Socket>();
|
|
72
|
+
server.on("connection", (socket) => {
|
|
73
|
+
sockets.add(socket);
|
|
74
|
+
socket.once("close", () => sockets.delete(socket));
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
await new Promise<void>((resolve, reject) => {
|
|
78
|
+
server.once("error", reject);
|
|
79
|
+
server.listen(port, "127.0.0.1", () => {
|
|
80
|
+
server.off("error", reject);
|
|
73
81
|
resolve();
|
|
74
82
|
});
|
|
75
83
|
});
|
|
76
84
|
|
|
85
|
+
const address = server.address();
|
|
86
|
+
if (!address || typeof address === "string") {
|
|
87
|
+
await db.close();
|
|
88
|
+
throw new Error("Unable to determine the PGlite gateway port.");
|
|
89
|
+
}
|
|
90
|
+
const actualPort = address.port;
|
|
91
|
+
console.info(`database: server listening on port ${actualPort}`);
|
|
92
|
+
|
|
93
|
+
let closed = false;
|
|
94
|
+
|
|
77
95
|
return {
|
|
78
96
|
server,
|
|
79
97
|
db,
|
|
98
|
+
port: actualPort,
|
|
80
99
|
close: async () => {
|
|
81
|
-
|
|
100
|
+
if (closed) return;
|
|
101
|
+
closed = true;
|
|
102
|
+
for (const socket of sockets) socket.destroy();
|
|
103
|
+
if (server.listening) {
|
|
104
|
+
await new Promise<void>((resolve, reject) => {
|
|
105
|
+
server.close((error) => error ? reject(error) : resolve());
|
|
106
|
+
});
|
|
107
|
+
}
|
|
82
108
|
await db.close();
|
|
83
109
|
},
|
|
84
110
|
};
|