postgresai 0.15.0-rc.5 → 0.15.0-rc.6

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.
@@ -2265,6 +2265,18 @@ function updatePgwatchConfig(configPath: string, updates: Record<string, string>
2265
2265
  fs.writeFileSync(configPath, lines.join("\n") + "\n", { encoding: "utf8", mode: 0o600 });
2266
2266
  }
2267
2267
 
2268
+ /**
2269
+ * Regenerate pgwatch sources and recreate collectors so target changes take effect without `mon restart`.
2270
+ */
2271
+ async function applyMonitoringTargetsConfig(): Promise<number> {
2272
+ console.log("Applying monitoring target configuration...");
2273
+ const generateCode = await runCompose(["run", "--rm", "sources-generator"]);
2274
+ if (generateCode !== 0) return generateCode;
2275
+
2276
+ console.log("Restarting pgwatch collectors to pick up target changes...");
2277
+ return runCompose(["up", "-d", "--force-recreate", "pgwatch-prometheus", "pgwatch-postgres"]);
2278
+ }
2279
+
2268
2280
  /**
2269
2281
  * Run docker compose command
2270
2282
  */
@@ -3341,6 +3353,14 @@ targets
3341
3353
  try {
3342
3354
  addInstanceToFile(file, buildInstance(instanceName, connStr));
3343
3355
  console.log(`Monitoring target '${instanceName}' added`);
3356
+
3357
+ const applyCode = await applyMonitoringTargetsConfig();
3358
+ if (applyCode !== 0) {
3359
+ console.error("Monitoring target was saved, but applying the generated pgwatch sources failed. Run 'postgresai mon restart' to apply manually.");
3360
+ process.exitCode = 1;
3361
+ return;
3362
+ }
3363
+ console.log("✓ Monitoring target configuration applied");
3344
3364
  } catch (err) {
3345
3365
  // Surface InstancesParseError as-is so we don't silently overwrite a
3346
3366
  // corrupted file (which could discard several targets, including the
@@ -3369,6 +3389,14 @@ targets
3369
3389
  return;
3370
3390
  }
3371
3391
  console.log(`Monitoring target '${name}' removed`);
3392
+
3393
+ const applyCode = await applyMonitoringTargetsConfig();
3394
+ if (applyCode !== 0) {
3395
+ console.error("Monitoring target was removed, but applying the generated pgwatch sources failed. Run 'postgresai mon restart' to apply manually.");
3396
+ process.exitCode = 1;
3397
+ return;
3398
+ }
3399
+ console.log("✓ Monitoring target configuration applied");
3372
3400
  } catch (err) {
3373
3401
  const message = err instanceof Error ? err.message : String(err);
3374
3402
  console.error(`Error processing instances.yml: ${message}`);
@@ -13423,7 +13423,7 @@ var {
13423
13423
  // package.json
13424
13424
  var package_default = {
13425
13425
  name: "postgresai",
13426
- version: "0.15.0-rc.5",
13426
+ version: "0.15.0-rc.6",
13427
13427
  description: "postgres_ai CLI",
13428
13428
  license: "Apache-2.0",
13429
13429
  private: false,
@@ -16254,7 +16254,7 @@ var Result = import_lib.default.Result;
16254
16254
  var TypeOverrides = import_lib.default.TypeOverrides;
16255
16255
  var defaults = import_lib.default.defaults;
16256
16256
  // package.json
16257
- var version = "0.15.0-rc.5";
16257
+ var version = "0.15.0-rc.6";
16258
16258
  var package_default2 = {
16259
16259
  name: "postgresai",
16260
16260
  version,
@@ -35206,6 +35206,14 @@ function updatePgwatchConfig(configPath, updates) {
35206
35206
  `) + `
35207
35207
  `, { encoding: "utf8", mode: 384 });
35208
35208
  }
35209
+ async function applyMonitoringTargetsConfig() {
35210
+ console.log("Applying monitoring target configuration...");
35211
+ const generateCode = await runCompose(["run", "--rm", "sources-generator"]);
35212
+ if (generateCode !== 0)
35213
+ return generateCode;
35214
+ console.log("Restarting pgwatch collectors to pick up target changes...");
35215
+ return runCompose(["up", "-d", "--force-recreate", "pgwatch-prometheus", "pgwatch-postgres"]);
35216
+ }
35209
35217
  async function runCompose(args, grafanaPassword) {
35210
35218
  let composeFile;
35211
35219
  let projectDir;
@@ -36099,6 +36107,13 @@ targets.command("add [connStr] [name]").description("add monitoring target datab
36099
36107
  try {
36100
36108
  addInstanceToFile(file, buildInstance(instanceName, connStr));
36101
36109
  console.log(`Monitoring target '${instanceName}' added`);
36110
+ const applyCode = await applyMonitoringTargetsConfig();
36111
+ if (applyCode !== 0) {
36112
+ console.error("Monitoring target was saved, but applying the generated pgwatch sources failed. Run 'postgresai mon restart' to apply manually.");
36113
+ process.exitCode = 1;
36114
+ return;
36115
+ }
36116
+ console.log("\u2713 Monitoring target configuration applied");
36102
36117
  } catch (err) {
36103
36118
  const message = err instanceof Error ? err.message : String(err);
36104
36119
  console.error(message);
@@ -36120,6 +36135,13 @@ targets.command("remove <name>").description("remove monitoring target database"
36120
36135
  return;
36121
36136
  }
36122
36137
  console.log(`Monitoring target '${name}' removed`);
36138
+ const applyCode = await applyMonitoringTargetsConfig();
36139
+ if (applyCode !== 0) {
36140
+ console.error("Monitoring target was removed, but applying the generated pgwatch sources failed. Run 'postgresai mon restart' to apply manually.");
36141
+ process.exitCode = 1;
36142
+ return;
36143
+ }
36144
+ console.log("\u2713 Monitoring target configuration applied");
36123
36145
  } catch (err) {
36124
36146
  const message = err instanceof Error ? err.message : String(err);
36125
36147
  console.error(`Error processing instances.yml: ${message}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postgresai",
3
- "version": "0.15.0-rc.5",
3
+ "version": "0.15.0-rc.6",
4
4
  "description": "postgres_ai CLI",
5
5
  "license": "Apache-2.0",
6
6
  "private": false,
@@ -0,0 +1,28 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { readFileSync } from "fs";
3
+ import { resolve } from "path";
4
+
5
+ const cliSource = readFileSync(resolve(import.meta.dir, "../bin/postgres-ai.ts"), "utf8");
6
+
7
+ describe("mon targets configuration apply", () => {
8
+ test("targets add regenerates sources and restarts pgwatch collectors after saving", () => {
9
+ expect(cliSource).toContain("async function applyMonitoringTargetsConfig()");
10
+ expect(cliSource).toContain('runCompose(["run", "--rm", "sources-generator"])');
11
+ expect(cliSource).toContain(
12
+ 'runCompose(["up", "-d", "--force-recreate", "pgwatch-prometheus", "pgwatch-postgres"])'
13
+ );
14
+
15
+ const saveIndex = cliSource.indexOf("addInstanceToFile(file, buildInstance(instanceName, connStr))");
16
+ const applyIndex = cliSource.indexOf("await applyMonitoringTargetsConfig()", saveIndex);
17
+ expect(saveIndex).toBeGreaterThan(-1);
18
+ expect(applyIndex).toBeGreaterThan(saveIndex);
19
+ });
20
+
21
+ test("targets remove regenerates sources and restarts pgwatch collectors after saving", () => {
22
+ const removeIndex = cliSource.indexOf("removeInstanceFromFile(file, name)");
23
+ const applyIndex = cliSource.indexOf("await applyMonitoringTargetsConfig()", removeIndex);
24
+ expect(removeIndex).toBeGreaterThan(-1);
25
+ expect(applyIndex).toBeGreaterThan(-1);
26
+ expect(applyIndex).toBeGreaterThan(removeIndex);
27
+ });
28
+ });