Skip to content

Commit 924650e

Browse files
committed
Bump version to v1.0.3-canary.1
1 parent e7cbeee commit 924650e

File tree

6 files changed

+150
-3
lines changed

6 files changed

+150
-3
lines changed

desktop/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "badger-desktop",
33
"productName": "Badger Desktop",
4-
"version": "1.0.3-canary.0",
4+
"version": "1.0.3-canary.1",
55
"description": "My Electron application description",
66
"main": "./out/main/index.js",
77
"scripts": {

jobrunner/jest.config.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/** @type {import('ts-jest').JestConfigWithTsJest} */
2+
module.exports = {
3+
preset: "ts-jest",
4+
testEnvironment: "node",
5+
coverageProvider: "v8",
6+
transform: {
7+
"\\.[jt]sx?$": "ts-jest",
8+
},
9+
globals: {
10+
"ts-jest": {
11+
useESM: true,
12+
},
13+
},
14+
moduleNameMapper: {
15+
"(.+)\\.js": "$1",
16+
},
17+
extensionsToTreatAsEsm: [".ts"],
18+
};

jobrunner/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "badger-jobrunner",
3-
"version": "1.0.3-canary.0",
3+
"version": "1.0.3-canary.1",
44
"packageManager": "[email protected]",
55
"devDependencies": {
66
"@sentry/esbuild-plugin": "^2.7.0",

server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "badger-server",
3-
"version": "1.0.3-canary.0",
3+
"version": "1.0.3-canary.1",
44
"private": true,
55
"scripts": {
66
"dev": "next dev",

utility/testing/dbDevServer.ts

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import { URL } from "node:url";
2+
import pg from "pg";
3+
import { exec as execRaw } from "node:child_process";
4+
import { promisify } from "node:util";
5+
import Express from "express";
6+
7+
const exec = promisify(execRaw);
8+
9+
function invariant(cond: any, message: string): asserts cond {
10+
if (!cond) {
11+
throw new Error("Invariant violation: " + message);
12+
}
13+
}
14+
15+
const __dirname = new URL(".", import.meta.url).pathname;
16+
17+
const rawUrl = process.env.DATABASE_URL;
18+
invariant(rawUrl, "DATABASE_URL not set");
19+
const url = new URL(rawUrl);
20+
invariant(
21+
url.protocol === "postgresql:",
22+
"DATABASE_URL must be a postgres URL",
23+
);
24+
25+
const client = new pg.Client({
26+
user: url.username,
27+
host: url.hostname,
28+
database: url.pathname.slice(1),
29+
password: url.password,
30+
port: parseInt(url.port || "5432", 10),
31+
});
32+
await client.connect();
33+
34+
// First, create a template database
35+
await client.query("DROP DATABASE IF EXISTS badger_test_template");
36+
await client.query("CREATE DATABASE badger_test_template");
37+
// Run migrations against it
38+
const templateURL = new URL(rawUrl);
39+
templateURL.pathname = "badger_test_template";
40+
await exec("npx -y prisma migrate deploy --schema ../prisma/schema.prisma", {
41+
env: {
42+
...process.env,
43+
DATABASE_URL: templateURL.toString(),
44+
},
45+
cwd: __dirname,
46+
});
47+
// Disable connections
48+
await client.query(
49+
"UPDATE pg_database SET datallowconn = false WHERE datname = 'badger_test_template'",
50+
);
51+
await client.query(
52+
"SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = 'badger_test_template' AND pid <> pg_backend_pid()",
53+
);
54+
55+
// Now start our dev server.
56+
const app = Express();
57+
58+
const dbPool = new Set<string>();
59+
60+
function randomString() {
61+
return Math.round(Math.random() * 1e9).toString(36);
62+
}
63+
64+
async function prepareDB() {
65+
const dbName = "badger_test_" + randomString();
66+
await client.query(`CREATE DATABASE ${dbName} TEMPLATE badger_test_template`);
67+
dbPool.add(dbName);
68+
return dbName;
69+
}
70+
71+
async function getPooledDBOrPrepare() {
72+
if (dbPool.size > 0) {
73+
const next = dbPool.values().next();
74+
dbPool.delete(next.value);
75+
process.nextTick(async () => {
76+
dbPool.add(await prepareDB());
77+
});
78+
return next.value;
79+
}
80+
return await prepareDB();
81+
}
82+
83+
app.get("/healthz", async (_, res) => {
84+
res.json({ ok: true });
85+
});
86+
87+
app.post("/db", async (req, res) => {
88+
const db = await getPooledDBOrPrepare();
89+
const url = new URL(rawUrl);
90+
url.pathname = db;
91+
res.json({ db: db, url: url.toString() });
92+
});
93+
94+
app.delete("/db/:db", async (req, res) => {
95+
await client.query(`DROP DATABASE ${req.params.db}`);
96+
res.json({ ok: true });
97+
});
98+
99+
process.on("beforeExit", async () => {
100+
for (const db of dbPool) {
101+
await client.query(`DROP DATABASE ${db}`);
102+
}
103+
await client.query("DROP DATABASE badger_test_template");
104+
await client.end();
105+
console.log("Goodbye!");
106+
});
107+
108+
const port = process.env.DB_DEV_SERVER_PORT
109+
? parseInt(process.env.DB_DEV_SERVER_PORT, 10)
110+
: 5937;
111+
app.listen(port, () => {
112+
console.log(`DB server listening on http://localhost:${port}`);
113+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { got } from "got";
2+
3+
const port = process.env.DB_DEV_SERVER_PORT
4+
? parseInt(process.env.DB_DEV_SERVER_PORT, 10)
5+
: 5937;
6+
7+
export async function getDB() {
8+
const res = await got.post(`http://localhost:${port}/db`, {
9+
responseType: "json",
10+
});
11+
return res.body as { db: string; url: string };
12+
}
13+
14+
export async function releaseDB(name: string) {
15+
await got.delete(`http://localhost:${port}/db/${name}`);
16+
}

0 commit comments

Comments
 (0)