postgresai 0.18.0-beta.1 → 0.18.0-beta.2
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/bin/postgres-ai.js +161 -66
- package/dist/sql/01.role.sql +2 -0
- package/dist/sql/02.extensions.sql +1 -0
- package/dist/sql/03.permissions.sql +2 -0
- package/dist/sql/04.optional_rds.sql +1 -0
- package/dist/sql/05.optional_self_managed.sql +1 -0
- package/dist/sql/06.helpers.sql +1 -0
- package/dist/sql/uninit/01.helpers.sql +3 -1
- package/dist/sql/uninit/02.permissions.sql +3 -2
- package/dist/sql/uninit/03.role.sql +2 -1
- package/package.json +1 -1
- package/sql/01.role.sql +2 -0
- package/sql/02.extensions.sql +1 -0
- package/sql/03.permissions.sql +2 -0
- package/sql/04.optional_rds.sql +1 -0
- package/sql/05.optional_self_managed.sql +1 -0
- package/sql/06.helpers.sql +1 -0
- package/sql/uninit/01.helpers.sql +3 -1
- package/sql/uninit/02.permissions.sql +3 -2
- package/sql/uninit/03.role.sql +2 -1
package/dist/bin/postgres-ai.js
CHANGED
|
@@ -13533,7 +13533,7 @@ var {
|
|
|
13533
13533
|
// package.json
|
|
13534
13534
|
var package_default = {
|
|
13535
13535
|
name: "postgresai",
|
|
13536
|
-
version: "0.18.0-beta.
|
|
13536
|
+
version: "0.18.0-beta.2",
|
|
13537
13537
|
description: "postgres_ai CLI",
|
|
13538
13538
|
license: "Apache-2.0",
|
|
13539
13539
|
private: false,
|
|
@@ -16893,7 +16893,7 @@ var Result = import_lib.default.Result;
|
|
|
16893
16893
|
var TypeOverrides = import_lib.default.TypeOverrides;
|
|
16894
16894
|
var defaults = import_lib.default.defaults;
|
|
16895
16895
|
// package.json
|
|
16896
|
-
var version = "0.18.0-beta.
|
|
16896
|
+
var version = "0.18.0-beta.2";
|
|
16897
16897
|
var package_default2 = {
|
|
16898
16898
|
name: "postgresai",
|
|
16899
16899
|
version,
|
|
@@ -22045,6 +22045,42 @@ function safeDoDelimiter(...values) {
|
|
|
22045
22045
|
function redactPasswordsInSql(sql) {
|
|
22046
22046
|
return sql.replace(/password\s+'(?:''|[^'])*'/gi, "password '<redacted>'");
|
|
22047
22047
|
}
|
|
22048
|
+
function renderInitPlanSql(plan) {
|
|
22049
|
+
const lines = [
|
|
22050
|
+
"-- Run the complete plan in one session. For psql, use -v ON_ERROR_STOP=1.",
|
|
22051
|
+
"begin;"
|
|
22052
|
+
];
|
|
22053
|
+
for (const step of plan.steps) {
|
|
22054
|
+
const sql = redactPasswordsInSql(step.sql);
|
|
22055
|
+
lines.push(`
|
|
22056
|
+
-- ${step.name}${step.optional ? " (optional)" : ""}`);
|
|
22057
|
+
if (!step.optional) {
|
|
22058
|
+
lines.push(sql);
|
|
22059
|
+
continue;
|
|
22060
|
+
}
|
|
22061
|
+
const delimiter = (base) => {
|
|
22062
|
+
let i = 0;
|
|
22063
|
+
while (sql.includes(`$${base}_${i}$`))
|
|
22064
|
+
i++;
|
|
22065
|
+
return `$${base}_${i}$`;
|
|
22066
|
+
};
|
|
22067
|
+
const outer = delimiter("pgai_optional_outer");
|
|
22068
|
+
const inner = delimiter("pgai_optional_sql");
|
|
22069
|
+
lines.push(`do ${outer}
|
|
22070
|
+
begin
|
|
22071
|
+
begin
|
|
22072
|
+
execute ${inner}
|
|
22073
|
+
${sql}
|
|
22074
|
+
${inner};
|
|
22075
|
+
exception when others then
|
|
22076
|
+
raise warning 'optional SQL step ${step.name} skipped: %', sqlerrm;
|
|
22077
|
+
end;
|
|
22078
|
+
end ${outer};`);
|
|
22079
|
+
}
|
|
22080
|
+
lines.push("commit;");
|
|
22081
|
+
return lines.join(`
|
|
22082
|
+
`);
|
|
22083
|
+
}
|
|
22048
22084
|
function maskConnectionString(dbUrl) {
|
|
22049
22085
|
let masked = dbUrl;
|
|
22050
22086
|
const head = dbUrl.match(/^(\s*[a-z][a-z0-9+.-]*:\/\/)([^:@\/?#]*):([\s\S]*)$/i);
|
|
@@ -24117,10 +24153,7 @@ async function prepareDatabase(url, provider, opts = {}) {
|
|
|
24117
24153
|
}
|
|
24118
24154
|
const plan = await buildInitPlan({ database: me.db, monitoringUser: role, monitoringPassword: "<password>", includeOptionalPermissions: true, provider: pgProvider, keepExistingPassword: true });
|
|
24119
24155
|
return {
|
|
24120
|
-
sql: plan
|
|
24121
|
-
${redactPasswordsInSql(s.sql)}`).join(`
|
|
24122
|
-
|
|
24123
|
-
`),
|
|
24156
|
+
sql: renderInitPlanSql(plan),
|
|
24124
24157
|
next: `Run the SQL as an admin, with a password of your choice in place of <redacted> (or re-run with an admin URL), then pgai mon deploy again with the ${role} URL`
|
|
24125
24158
|
};
|
|
24126
24159
|
} finally {
|
|
@@ -33906,10 +33939,7 @@ async function prepareDatabase2(url, provider, opts = {}) {
|
|
|
33906
33939
|
}
|
|
33907
33940
|
const plan = await buildInitPlan({ database: me.db, monitoringUser: role, monitoringPassword: "<password>", includeOptionalPermissions: true, provider: pgProvider, keepExistingPassword: true });
|
|
33908
33941
|
return {
|
|
33909
|
-
sql: plan
|
|
33910
|
-
${redactPasswordsInSql(s.sql)}`).join(`
|
|
33911
|
-
|
|
33912
|
-
`),
|
|
33942
|
+
sql: renderInitPlanSql(plan),
|
|
33913
33943
|
next: `Run the SQL as an admin, with a password of your choice in place of <redacted> (or re-run with an admin URL), then pgai mon deploy again with the ${role} URL`
|
|
33914
33944
|
};
|
|
33915
33945
|
} finally {
|
|
@@ -36912,6 +36942,42 @@ function safeDoDelimiter2(...values) {
|
|
|
36912
36942
|
function redactPasswordsInSql2(sql) {
|
|
36913
36943
|
return sql.replace(/password\s+'(?:''|[^'])*'/gi, "password '<redacted>'");
|
|
36914
36944
|
}
|
|
36945
|
+
function renderInitPlanSql2(plan) {
|
|
36946
|
+
const lines = [
|
|
36947
|
+
"-- Run the complete plan in one session. For psql, use -v ON_ERROR_STOP=1.",
|
|
36948
|
+
"begin;"
|
|
36949
|
+
];
|
|
36950
|
+
for (const step of plan.steps) {
|
|
36951
|
+
const sql = redactPasswordsInSql2(step.sql);
|
|
36952
|
+
lines.push(`
|
|
36953
|
+
-- ${step.name}${step.optional ? " (optional)" : ""}`);
|
|
36954
|
+
if (!step.optional) {
|
|
36955
|
+
lines.push(sql);
|
|
36956
|
+
continue;
|
|
36957
|
+
}
|
|
36958
|
+
const delimiter = (base) => {
|
|
36959
|
+
let i = 0;
|
|
36960
|
+
while (sql.includes(`$${base}_${i}$`))
|
|
36961
|
+
i++;
|
|
36962
|
+
return `$${base}_${i}$`;
|
|
36963
|
+
};
|
|
36964
|
+
const outer = delimiter("pgai_optional_outer");
|
|
36965
|
+
const inner = delimiter("pgai_optional_sql");
|
|
36966
|
+
lines.push(`do ${outer}
|
|
36967
|
+
begin
|
|
36968
|
+
begin
|
|
36969
|
+
execute ${inner}
|
|
36970
|
+
${sql}
|
|
36971
|
+
${inner};
|
|
36972
|
+
exception when others then
|
|
36973
|
+
raise warning 'optional SQL step ${step.name} skipped: %', sqlerrm;
|
|
36974
|
+
end;
|
|
36975
|
+
end ${outer};`);
|
|
36976
|
+
}
|
|
36977
|
+
lines.push("commit;");
|
|
36978
|
+
return lines.join(`
|
|
36979
|
+
`);
|
|
36980
|
+
}
|
|
36915
36981
|
function maskConnectionString2(dbUrl) {
|
|
36916
36982
|
let masked = dbUrl;
|
|
36917
36983
|
const head = dbUrl.match(/^(\s*[a-z][a-z0-9+.-]*:\/\/)([^:@\/?#]*):([\s\S]*)$/i);
|
|
@@ -45200,6 +45266,7 @@ var LOCAL_INSTALL_MANAGED_ENV_KEYS = [
|
|
|
45200
45266
|
var INSTANCE_JOBS_PROFILE = "instance-jobs";
|
|
45201
45267
|
var DEMO_PROFILE = "demo";
|
|
45202
45268
|
var PRESTARTED_MARKER = ".prestarted";
|
|
45269
|
+
var PRESTARTED_DONE_MARKER = ".prestarted.done";
|
|
45203
45270
|
var PRESTART_SERVICES = [
|
|
45204
45271
|
"sink-postgres",
|
|
45205
45272
|
"sink-prometheus",
|
|
@@ -45224,9 +45291,12 @@ function composeProfilesValue(existing, want, profile = INSTANCE_JOBS_PROFILE) {
|
|
|
45224
45291
|
profiles.splice(at, 1);
|
|
45225
45292
|
return profiles.length > 0 ? profiles.join(",") : null;
|
|
45226
45293
|
}
|
|
45227
|
-
function
|
|
45294
|
+
function profileEnabled(composeProfiles, profile) {
|
|
45228
45295
|
return (composeProfiles ?? "").split(",").map((p) => p.trim()).includes(profile);
|
|
45229
45296
|
}
|
|
45297
|
+
function instanceJobsProfileEnabled(composeProfiles, profile = INSTANCE_JOBS_PROFILE) {
|
|
45298
|
+
return profileEnabled(composeProfiles, profile);
|
|
45299
|
+
}
|
|
45230
45300
|
function resolveInstanceJobsRequest(flag, envValue) {
|
|
45231
45301
|
if (flag !== undefined)
|
|
45232
45302
|
return { enabled: flag };
|
|
@@ -46002,7 +46072,6 @@ program2.command("prepare-db [conn]").description("prepare database for monitori
|
|
|
46002
46072
|
conn = process.env.PGAI_DB_URL || undefined;
|
|
46003
46073
|
}
|
|
46004
46074
|
const shouldPrintSql = !!opts.printSql;
|
|
46005
|
-
const redactPasswords = (sql) => redactPasswordsInSql2(sql);
|
|
46006
46075
|
const { provider, detected } = resolveProvider(opts.provider, conn ?? opts.dbUrl ?? opts.host ?? process.env.PGHOST);
|
|
46007
46076
|
const note = opts.json ? console.error : console.log;
|
|
46008
46077
|
if (detected)
|
|
@@ -46034,11 +46103,7 @@ program2.command("prepare-db [conn]").description("prepare database for monitori
|
|
|
46034
46103
|
console.log(`-- monitoring user: ${opts.monitoringUser}`);
|
|
46035
46104
|
console.log(`-- provider: ${provider}`);
|
|
46036
46105
|
console.log(`-- optional permissions: ${includeOptionalPermissions ? "enabled" : "skipped"}`);
|
|
46037
|
-
|
|
46038
|
-
console.log(`
|
|
46039
|
-
-- ${step.name}${step.optional ? " (optional)" : ""}`);
|
|
46040
|
-
console.log(redactPasswords(step.sql));
|
|
46041
|
-
}
|
|
46106
|
+
console.log(renderInitPlanSql2(plan));
|
|
46042
46107
|
console.log(`
|
|
46043
46108
|
--- end SQL plan ---
|
|
46044
46109
|
`);
|
|
@@ -46200,11 +46265,7 @@ program2.command("prepare-db [conn]").description("prepare database for monitori
|
|
|
46200
46265
|
if (shouldPrintSql) {
|
|
46201
46266
|
console.log(`
|
|
46202
46267
|
--- SQL plan ---`);
|
|
46203
|
-
|
|
46204
|
-
console.log(`
|
|
46205
|
-
-- ${step.name}${step.optional ? " (optional)" : ""}`);
|
|
46206
|
-
console.log(redactPasswords(step.sql));
|
|
46207
|
-
}
|
|
46268
|
+
console.log(renderInitPlanSql2(effectivePlan));
|
|
46208
46269
|
console.log(`
|
|
46209
46270
|
--- end SQL plan ---
|
|
46210
46271
|
`);
|
|
@@ -46492,11 +46553,7 @@ program2.command("prepare-db [conn]").description("prepare database for monitori
|
|
|
46492
46553
|
if (shouldPrintSql) {
|
|
46493
46554
|
console.log(`
|
|
46494
46555
|
--- SQL plan ---`);
|
|
46495
|
-
|
|
46496
|
-
console.log(`
|
|
46497
|
-
-- ${step.name}${step.optional ? " (optional)" : ""}`);
|
|
46498
|
-
console.log(redactPasswords(step.sql));
|
|
46499
|
-
}
|
|
46556
|
+
console.log(renderInitPlanSql2(effectivePlan));
|
|
46500
46557
|
console.log(`
|
|
46501
46558
|
--- end SQL plan ---
|
|
46502
46559
|
`);
|
|
@@ -46688,11 +46745,14 @@ program2.command("unprepare-db [conn]").description("remove monitoring setup: dr
|
|
|
46688
46745
|
console.log(`-- monitoring user: ${opts.monitoringUser}`);
|
|
46689
46746
|
console.log(`-- provider: ${provider}`);
|
|
46690
46747
|
console.log(`-- drop role: ${dropRole}`);
|
|
46748
|
+
console.log("-- Run the complete plan in one session. For psql, use -v ON_ERROR_STOP=1.");
|
|
46749
|
+
console.log("begin;");
|
|
46691
46750
|
for (const step of plan.steps) {
|
|
46692
46751
|
console.log(`
|
|
46693
46752
|
-- ${step.name}`);
|
|
46694
46753
|
console.log(step.sql);
|
|
46695
46754
|
}
|
|
46755
|
+
console.log("commit;");
|
|
46696
46756
|
console.log(`
|
|
46697
46757
|
--- end SQL plan ---
|
|
46698
46758
|
`);
|
|
@@ -46758,11 +46818,14 @@ program2.command("unprepare-db [conn]").description("remove monitoring setup: dr
|
|
|
46758
46818
|
if (shouldPrintSql) {
|
|
46759
46819
|
console.log(`
|
|
46760
46820
|
--- SQL plan ---`);
|
|
46821
|
+
console.log("-- Run the complete plan in one session. For psql, use -v ON_ERROR_STOP=1.");
|
|
46822
|
+
console.log("begin;");
|
|
46761
46823
|
for (const step of plan.steps) {
|
|
46762
46824
|
console.log(`
|
|
46763
46825
|
-- ${step.name}`);
|
|
46764
46826
|
console.log(step.sql);
|
|
46765
46827
|
}
|
|
46828
|
+
console.log("commit;");
|
|
46766
46829
|
console.log(`
|
|
46767
46830
|
--- end SQL plan ---
|
|
46768
46831
|
`);
|
|
@@ -47690,30 +47753,38 @@ function instancesUseDemoTarget(instancesPath) {
|
|
|
47690
47753
|
try {
|
|
47691
47754
|
if (!fs10.statSync(instancesPath).isFile())
|
|
47692
47755
|
return false;
|
|
47693
|
-
return
|
|
47756
|
+
return loadInstances2(instancesPath).some((instance) => {
|
|
47757
|
+
try {
|
|
47758
|
+
return new URL(String(instance.conn_str ?? "")).hostname === "target-db";
|
|
47759
|
+
} catch {
|
|
47760
|
+
return false;
|
|
47761
|
+
}
|
|
47762
|
+
});
|
|
47694
47763
|
} catch {
|
|
47695
47764
|
return false;
|
|
47696
47765
|
}
|
|
47697
47766
|
}
|
|
47698
|
-
function removeDemoContainers() {
|
|
47699
|
-
|
|
47700
|
-
|
|
47701
|
-
|
|
47702
|
-
|
|
47703
|
-
|
|
47704
|
-
|
|
47705
|
-
|
|
47767
|
+
async function removeDemoContainers(projectDir) {
|
|
47768
|
+
const cmd = getComposeCmd();
|
|
47769
|
+
if (!cmd)
|
|
47770
|
+
return;
|
|
47771
|
+
const ps = spawnSync3(cmd[0], [...cmd.slice(1), "-f", path8.resolve(projectDir, "docker-compose.yml"), "ps", "-a", "--format", "{{.Service}}"], { cwd: projectDir, env: { ...process.env, COMPOSE_PROFILES: DEMO_PROFILE }, stdio: "pipe", encoding: "utf8", timeout: 15000 });
|
|
47772
|
+
const present = String(ps.stdout ?? "").split(/\s+/).filter((s) => s === "target-db" || s === "target-standby");
|
|
47773
|
+
if (ps.status !== 0 || present.length === 0)
|
|
47774
|
+
return;
|
|
47775
|
+
console.log(`Removing ${present.join(" and ")}: the demo database is not part of this install (volumes are kept)`);
|
|
47776
|
+
await runCompose(["rm", "-f", "-s", ...present], undefined, { COMPOSE_PROFILES: DEMO_PROFILE });
|
|
47706
47777
|
}
|
|
47707
|
-
function syncDemoProfile(projectDir, instancesPath) {
|
|
47778
|
+
async function syncDemoProfile(projectDir, instancesPath) {
|
|
47708
47779
|
const current = readEnvValue(projectDir, "COMPOSE_PROFILES") ?? null;
|
|
47709
|
-
if (
|
|
47780
|
+
if (profileEnabled(current, DEMO_PROFILE))
|
|
47710
47781
|
return;
|
|
47711
47782
|
if (instancesUseDemoTarget(instancesPath)) {
|
|
47712
47783
|
setEnvValues(projectDir, { COMPOSE_PROFILES: composeProfilesValue(current, true, DEMO_PROFILE) });
|
|
47713
47784
|
console.log(`Enabled the '${DEMO_PROFILE}' compose profile: instances.yml monitors the demo database`);
|
|
47714
47785
|
return;
|
|
47715
47786
|
}
|
|
47716
|
-
removeDemoContainers();
|
|
47787
|
+
await removeDemoContainers(projectDir);
|
|
47717
47788
|
}
|
|
47718
47789
|
async function ensureGrafanaPassword(cfgPath) {
|
|
47719
47790
|
let grafanaPassword = "";
|
|
@@ -47761,16 +47832,27 @@ async function ensureGrafanaPassword(cfgPath) {
|
|
|
47761
47832
|
}
|
|
47762
47833
|
return grafanaPassword;
|
|
47763
47834
|
}
|
|
47835
|
+
function prestartRefusal(projectDir) {
|
|
47836
|
+
for (const marker of [PRESTARTED_MARKER, PRESTARTED_DONE_MARKER]) {
|
|
47837
|
+
if (fs10.existsSync(path8.join(projectDir, marker)))
|
|
47838
|
+
return `this stack was prestarted already (${marker})`;
|
|
47839
|
+
}
|
|
47840
|
+
const { containers } = checkRunningContainers();
|
|
47841
|
+
const pgwatch = containers.filter((c) => c.startsWith("pgwatch"));
|
|
47842
|
+
if (pgwatch.length > 0)
|
|
47843
|
+
return `a configured monitoring stack is running (${pgwatch.join(", ")})`;
|
|
47844
|
+
return null;
|
|
47845
|
+
}
|
|
47846
|
+
function runningComposeServices(projectDir) {
|
|
47847
|
+
const cmd = getComposeCmd();
|
|
47848
|
+
if (!cmd)
|
|
47849
|
+
return [];
|
|
47850
|
+
const ps = spawnSync3(cmd[0], [...cmd.slice(1), "-f", path8.resolve(projectDir, "docker-compose.yml"), "ps", "--status", "running", "--services"], { cwd: projectDir, stdio: "pipe", encoding: "utf8", timeout: 15000 });
|
|
47851
|
+
return ps.status === 0 ? String(ps.stdout ?? "").split(/\s+/).filter(Boolean) : [];
|
|
47852
|
+
}
|
|
47764
47853
|
async function runPrestart(projectDir, instancesPath, imageTag) {
|
|
47765
47854
|
console.log(`Prestart: starting the monitoring infrastructure without a target
|
|
47766
47855
|
`);
|
|
47767
|
-
const { running, containers } = checkRunningContainers();
|
|
47768
|
-
if (running) {
|
|
47769
|
-
console.error(`\u2717 Monitoring services are already running: ${containers.join(", ")}`);
|
|
47770
|
-
console.error(" --prestart is for a stack that has never started; nothing was changed");
|
|
47771
|
-
process.exitCode = 1;
|
|
47772
|
-
return;
|
|
47773
|
-
}
|
|
47774
47856
|
if (!fs10.existsSync(instancesPath)) {
|
|
47775
47857
|
fs10.writeFileSync(instancesPath, `# PostgreSQL instances to monitor
|
|
47776
47858
|
# Add your instances using: postgres-ai mon targets add
|
|
@@ -48398,6 +48480,20 @@ mon.command("local-install").description("install local monitoring stack (genera
|
|
|
48398
48480
|
const { projectDir, instancesFile: instancesPath } = await resolveOrInitPaths();
|
|
48399
48481
|
console.log(`Project directory: ${projectDir}
|
|
48400
48482
|
`);
|
|
48483
|
+
if (opts.prestart) {
|
|
48484
|
+
const identity = opts.instanceId || process.env.PGAI_INSTANCE_ID || opts.instanceJobs !== undefined || (process.env.PGAI_INSTANCE_JOBS ?? "").trim() !== "" || opts.project;
|
|
48485
|
+
if (opts.demo || opts.dbUrl || apiKey || opts.continuePrestarted || identity) {
|
|
48486
|
+
console.error("\u2717 --prestart starts the stack without a target or an identity: it cannot be combined with --demo, --db-url, --api-key, --instance-id, --project, --instance-jobs or --continue-prestarted (or PGAI_INSTANCE_ID / PGAI_INSTANCE_JOBS)");
|
|
48487
|
+
process.exitCode = 1;
|
|
48488
|
+
return;
|
|
48489
|
+
}
|
|
48490
|
+
const refusal = prestartRefusal(projectDir);
|
|
48491
|
+
if (refusal) {
|
|
48492
|
+
console.error(`\u2717 ${refusal}; nothing was changed`);
|
|
48493
|
+
process.exitCode = 1;
|
|
48494
|
+
return;
|
|
48495
|
+
}
|
|
48496
|
+
}
|
|
48401
48497
|
if (opts.project && !applyProjectName(projectDir, opts.project)) {
|
|
48402
48498
|
process.exitCode = 1;
|
|
48403
48499
|
return;
|
|
@@ -48414,12 +48510,7 @@ mon.command("local-install").description("install local monitoring stack (genera
|
|
|
48414
48510
|
return;
|
|
48415
48511
|
}
|
|
48416
48512
|
const instanceJobs = instanceJobsRequest.enabled;
|
|
48417
|
-
|
|
48418
|
-
console.error("\u2717 --prestart starts the stack without a target: it cannot be combined with --demo, --db-url, --api-key, --instance-id or --continue-prestarted");
|
|
48419
|
-
process.exitCode = 1;
|
|
48420
|
-
return;
|
|
48421
|
-
}
|
|
48422
|
-
const { content: envContent, preservedKeys } = buildLocalInstallEnv(existingEnv, imageTag, opts.instanceId || process.env.PGAI_INSTANCE_ID || null, path8.resolve(projectDir, ".pgwatch-config"), instanceJobs, opts.demo);
|
|
48513
|
+
const { content: envContent, preservedKeys } = buildLocalInstallEnv(existingEnv, imageTag, opts.instanceId || process.env.PGAI_INSTANCE_ID || null, path8.resolve(projectDir, ".pgwatch-config"), instanceJobs, opts.demo ? true : undefined);
|
|
48423
48514
|
writeEnvFile(envFile, envContent);
|
|
48424
48515
|
if (preservedKeys.length > 0) {
|
|
48425
48516
|
console.log(`Preserved existing .env settings: ${preservedKeys.join(", ")}
|
|
@@ -48684,23 +48775,26 @@ Searched: ${demoCandidates.join(", ")}
|
|
|
48684
48775
|
console.warn(` ${error instanceof Error ? error.message : String(error)}`);
|
|
48685
48776
|
}
|
|
48686
48777
|
}
|
|
48687
|
-
if (!opts.demo)
|
|
48688
|
-
|
|
48778
|
+
if (!opts.demo) {
|
|
48779
|
+
const profiles = readEnvValue(projectDir, "COMPOSE_PROFILES") ?? null;
|
|
48780
|
+
if (profileEnabled(profiles, DEMO_PROFILE)) {
|
|
48781
|
+
setEnvValues(projectDir, { COMPOSE_PROFILES: composeProfilesValue(profiles, false, DEMO_PROFILE) });
|
|
48782
|
+
}
|
|
48783
|
+
await removeDemoContainers(projectDir);
|
|
48784
|
+
}
|
|
48689
48785
|
await runCompose(["rm", "-f", "-s", "config-init"]);
|
|
48690
48786
|
let code2;
|
|
48691
48787
|
if (onPrestarted) {
|
|
48692
48788
|
console.log("Step 5: Applying the configuration to the prestarted stack...");
|
|
48693
|
-
const readersRunning =
|
|
48694
|
-
|
|
48695
|
-
|
|
48696
|
-
|
|
48697
|
-
}
|
|
48698
|
-
code2 = await runCompose(["up", "-d"], grafanaPassword);
|
|
48699
|
-
if (code2 === 0 && readersRunning.length > 0) {
|
|
48700
|
-
code2 = await runCompose(["up", "-d", "--force-recreate", "--no-deps", ...readersRunning], grafanaPassword);
|
|
48701
|
-
}
|
|
48789
|
+
const readersRunning = runningComposeServices(projectDir).filter((s) => TARGET_READER_SERVICES.includes(s));
|
|
48790
|
+
code2 = readersRunning.length > 0 ? await runCompose(["up", "-d", "--force-recreate", "--no-deps", ...readersRunning], grafanaPassword) : 0;
|
|
48791
|
+
if (code2 === 0)
|
|
48792
|
+
code2 = await runCompose(["up", "-d"], grafanaPassword);
|
|
48702
48793
|
if (code2 === 0)
|
|
48703
48794
|
await reloadHostMetricsFiles(projectDir);
|
|
48795
|
+
if (code2 === 0) {
|
|
48796
|
+
fs10.renameSync(path8.join(projectDir, PRESTARTED_MARKER), path8.join(projectDir, PRESTARTED_DONE_MARKER));
|
|
48797
|
+
}
|
|
48704
48798
|
} else {
|
|
48705
48799
|
console.log("Step 5: Starting monitoring services...");
|
|
48706
48800
|
code2 = await runCompose(["up", "-d", "--force-recreate"], grafanaPassword);
|
|
@@ -48825,7 +48919,7 @@ mon.command("start").description("start monitoring services").action(async () =>
|
|
|
48825
48919
|
return;
|
|
48826
48920
|
}
|
|
48827
48921
|
const { projectDir, instancesFile } = await resolveOrInitPaths();
|
|
48828
|
-
syncDemoProfile(projectDir, instancesFile);
|
|
48922
|
+
await syncDemoProfile(projectDir, instancesFile);
|
|
48829
48923
|
const code = await runCompose(["up", "-d"]);
|
|
48830
48924
|
if (code !== 0)
|
|
48831
48925
|
process.exitCode = code;
|
|
@@ -48931,7 +49025,7 @@ function monitoringHealthServices(instanceJobsEnabled = false, demoEnabled = fal
|
|
|
48931
49025
|
}
|
|
48932
49026
|
mon.command("health").description("health check for monitoring services").option("--wait <seconds>", "wait time in seconds for services to become healthy", parseInt, 0).action(async (opts) => {
|
|
48933
49027
|
const profiles = readComposeProfiles();
|
|
48934
|
-
const services = monitoringHealthServices(instanceJobsProfileEnabled(profiles),
|
|
49028
|
+
const services = monitoringHealthServices(instanceJobsProfileEnabled(profiles), profileEnabled(profiles, DEMO_PROFILE));
|
|
48935
49029
|
const waitTime = opts.wait || 0;
|
|
48936
49030
|
const maxAttempts = waitTime > 0 ? Math.ceil(waitTime / 5) : 1;
|
|
48937
49031
|
console.log(`Checking service health...
|
|
@@ -49035,7 +49129,7 @@ mon.command("update").description("update monitoring stack (migrate .env, pull i
|
|
|
49035
49129
|
process.exitCode = 1;
|
|
49036
49130
|
return;
|
|
49037
49131
|
}
|
|
49038
|
-
syncDemoProfile(projectDir, instancesFile);
|
|
49132
|
+
await syncDemoProfile(projectDir, instancesFile);
|
|
49039
49133
|
console.log("Checking .env for newly-required keys...");
|
|
49040
49134
|
const added = ensureRequiredEnvVars(projectDir);
|
|
49041
49135
|
if (added.length > 0) {
|
|
@@ -51513,6 +51607,7 @@ export {
|
|
|
51513
51607
|
monitoringHealthServices,
|
|
51514
51608
|
persistInstanceId,
|
|
51515
51609
|
planMonitoringRegistration,
|
|
51610
|
+
profileEnabled,
|
|
51516
51611
|
program2 as program,
|
|
51517
51612
|
readComposeProfiles,
|
|
51518
51613
|
readDeployedTag,
|
package/dist/sql/01.role.sql
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
-- Role creation / password update (template-filled by cli/lib/init.ts)
|
|
2
|
+
-- Pin name resolution before the privileged DO block, including for printed SQL.
|
|
3
|
+
set search_path = pg_catalog, pg_temp;
|
|
2
4
|
--
|
|
3
5
|
-- A race-safe pattern: create if missing, then alter to set the password.
|
|
4
6
|
-- `pgai mon deploy` omits the alter, so an existing role keeps its password:
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
-- Required permissions for postgres_ai monitoring user (template-filled by cli/lib/init.ts)
|
|
2
|
+
-- The first DO block also runs as the admin; pin before any name resolution.
|
|
3
|
+
set search_path = pg_catalog, pg_temp;
|
|
2
4
|
|
|
3
5
|
-- Allow connect
|
|
4
6
|
grant connect on database {{DB_IDENT}} to {{ROLE_IDENT}};
|
package/dist/sql/06.helpers.sql
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
-- Helper functions for postgres_ai monitoring user (template-filled by cli/lib/init.ts)
|
|
2
|
+
set search_path = pg_catalog, pg_temp;
|
|
2
3
|
|
|
3
4
|
-- Remove the retired helper from databases prepared by older CLI versions.
|
|
4
5
|
-- Only its owner or a superuser can drop it: anyone else gets a warning here. Releases
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
-- Run before dropping the postgres_ai schema.
|
|
3
3
|
|
|
4
4
|
-- Objects in other schemas (for example, a planted public.format) must not run as the admin.
|
|
5
|
-
|
|
5
|
+
-- Use a session SET because --print-sql plans may be run by psql in autocommit.
|
|
6
|
+
-- SET LOCAL outside an explicit transaction is ignored there.
|
|
7
|
+
set search_path = pg_catalog, pg_temp;
|
|
6
8
|
|
|
7
9
|
drop function if exists postgres_ai.explain_generic(text, text, text);
|
|
8
10
|
drop function if exists postgres_ai.table_describe(text);
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
-- Revoke permissions and drop objects created by prepare-db (template-filled by cli/lib/init.ts)
|
|
2
2
|
|
|
3
3
|
-- Objects in other schemas (for example, a planted public.=) must not run as the admin.
|
|
4
|
-
|
|
4
|
+
-- Printed plans may run in psql autocommit, where SET LOCAL is ignored.
|
|
5
|
+
set search_path = pg_catalog, pg_temp;
|
|
5
6
|
-- The CLI reads the "unprepare-db:" WARNINGs. A higher setting would hide them.
|
|
6
|
-
set
|
|
7
|
+
set client_min_messages = warning;
|
|
7
8
|
|
|
8
9
|
-- Drop the postgres_ai.pg_statistic view
|
|
9
10
|
drop view if exists postgres_ai.pg_statistic;
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
-- This must run after revoking all permissions from the role.
|
|
3
3
|
|
|
4
4
|
-- Objects in other schemas (for example, a planted public.format) must not run as the admin.
|
|
5
|
-
|
|
5
|
+
-- Printed plans may run in psql autocommit, where SET LOCAL is ignored.
|
|
6
|
+
set search_path = pg_catalog, pg_temp;
|
|
6
7
|
|
|
7
8
|
-- Use a DO block to handle the case where the role doesn't exist
|
|
8
9
|
do {{DO_QUOTE}} begin
|
package/package.json
CHANGED
package/sql/01.role.sql
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
-- Role creation / password update (template-filled by cli/lib/init.ts)
|
|
2
|
+
-- Pin name resolution before the privileged DO block, including for printed SQL.
|
|
3
|
+
set search_path = pg_catalog, pg_temp;
|
|
2
4
|
--
|
|
3
5
|
-- A race-safe pattern: create if missing, then alter to set the password.
|
|
4
6
|
-- `pgai mon deploy` omits the alter, so an existing role keeps its password:
|
package/sql/02.extensions.sql
CHANGED
package/sql/03.permissions.sql
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
-- Required permissions for postgres_ai monitoring user (template-filled by cli/lib/init.ts)
|
|
2
|
+
-- The first DO block also runs as the admin; pin before any name resolution.
|
|
3
|
+
set search_path = pg_catalog, pg_temp;
|
|
2
4
|
|
|
3
5
|
-- Allow connect
|
|
4
6
|
grant connect on database {{DB_IDENT}} to {{ROLE_IDENT}};
|
package/sql/04.optional_rds.sql
CHANGED
package/sql/06.helpers.sql
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
-- Helper functions for postgres_ai monitoring user (template-filled by cli/lib/init.ts)
|
|
2
|
+
set search_path = pg_catalog, pg_temp;
|
|
2
3
|
|
|
3
4
|
-- Remove the retired helper from databases prepared by older CLI versions.
|
|
4
5
|
-- Only its owner or a superuser can drop it: anyone else gets a warning here. Releases
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
-- Run before dropping the postgres_ai schema.
|
|
3
3
|
|
|
4
4
|
-- Objects in other schemas (for example, a planted public.format) must not run as the admin.
|
|
5
|
-
|
|
5
|
+
-- Use a session SET because --print-sql plans may be run by psql in autocommit.
|
|
6
|
+
-- SET LOCAL outside an explicit transaction is ignored there.
|
|
7
|
+
set search_path = pg_catalog, pg_temp;
|
|
6
8
|
|
|
7
9
|
drop function if exists postgres_ai.explain_generic(text, text, text);
|
|
8
10
|
drop function if exists postgres_ai.table_describe(text);
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
-- Revoke permissions and drop objects created by prepare-db (template-filled by cli/lib/init.ts)
|
|
2
2
|
|
|
3
3
|
-- Objects in other schemas (for example, a planted public.=) must not run as the admin.
|
|
4
|
-
|
|
4
|
+
-- Printed plans may run in psql autocommit, where SET LOCAL is ignored.
|
|
5
|
+
set search_path = pg_catalog, pg_temp;
|
|
5
6
|
-- The CLI reads the "unprepare-db:" WARNINGs. A higher setting would hide them.
|
|
6
|
-
set
|
|
7
|
+
set client_min_messages = warning;
|
|
7
8
|
|
|
8
9
|
-- Drop the postgres_ai.pg_statistic view
|
|
9
10
|
drop view if exists postgres_ai.pg_statistic;
|
package/sql/uninit/03.role.sql
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
-- This must run after revoking all permissions from the role.
|
|
3
3
|
|
|
4
4
|
-- Objects in other schemas (for example, a planted public.format) must not run as the admin.
|
|
5
|
-
|
|
5
|
+
-- Printed plans may run in psql autocommit, where SET LOCAL is ignored.
|
|
6
|
+
set search_path = pg_catalog, pg_temp;
|
|
6
7
|
|
|
7
8
|
-- Use a DO block to handle the case where the role doesn't exist
|
|
8
9
|
do {{DO_QUOTE}} begin
|