@memberjunction/cli 6.3.0-edge.1 → 6.3.0-edge.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/README.md +1047 -359
- package/dist/baseline/connection.d.ts.map +1 -1
- package/dist/baseline/connection.js +12 -1
- package/dist/baseline/connection.js.map +1 -1
- package/dist/commands/agent/usage.d.ts +7 -0
- package/dist/commands/agent/usage.d.ts.map +1 -0
- package/dist/commands/agent/usage.js +10 -0
- package/dist/commands/agent/usage.js.map +1 -0
- package/dist/commands/codegen/manifest.d.ts +40 -0
- package/dist/commands/codegen/manifest.d.ts.map +1 -1
- package/dist/commands/codegen/manifest.js +124 -3
- package/dist/commands/codegen/manifest.js.map +1 -1
- package/dist/commands/diag/usage.d.ts +7 -0
- package/dist/commands/diag/usage.d.ts.map +1 -0
- package/dist/commands/diag/usage.js +10 -0
- package/dist/commands/diag/usage.js.map +1 -0
- package/dist/commands/doctor/index.d.ts +6 -0
- package/dist/commands/doctor/index.d.ts.map +1 -1
- package/dist/commands/doctor/index.js +42 -0
- package/dist/commands/doctor/index.js.map +1 -1
- package/dist/commands/explorer/postbuild.d.ts +14 -0
- package/dist/commands/explorer/postbuild.d.ts.map +1 -0
- package/dist/commands/explorer/postbuild.js +49 -0
- package/dist/commands/explorer/postbuild.js.map +1 -0
- package/dist/commands/explorer/usage.d.ts +7 -0
- package/dist/commands/explorer/usage.d.ts.map +1 -0
- package/dist/commands/explorer/usage.js +10 -0
- package/dist/commands/explorer/usage.js.map +1 -0
- package/dist/commands/harness/account/add.d.ts +22 -0
- package/dist/commands/harness/account/add.d.ts.map +1 -0
- package/dist/commands/harness/account/add.js +100 -0
- package/dist/commands/harness/account/add.js.map +1 -0
- package/dist/commands/harness/account/clear-cooldown.d.ts +13 -0
- package/dist/commands/harness/account/clear-cooldown.d.ts.map +1 -0
- package/dist/commands/harness/account/clear-cooldown.js +32 -0
- package/dist/commands/harness/account/clear-cooldown.js.map +1 -0
- package/dist/commands/harness/account/disable.d.ts +13 -0
- package/dist/commands/harness/account/disable.d.ts.map +1 -0
- package/dist/commands/harness/account/disable.js +34 -0
- package/dist/commands/harness/account/disable.js.map +1 -0
- package/dist/commands/harness/account/enable.d.ts +13 -0
- package/dist/commands/harness/account/enable.d.ts.map +1 -0
- package/dist/commands/harness/account/enable.js +34 -0
- package/dist/commands/harness/account/enable.js.map +1 -0
- package/dist/commands/harness/account/index.d.ts +7 -0
- package/dist/commands/harness/account/index.d.ts.map +1 -0
- package/dist/commands/harness/account/index.js +23 -0
- package/dist/commands/harness/account/index.js.map +1 -0
- package/dist/commands/harness/account/list.d.ts +15 -0
- package/dist/commands/harness/account/list.d.ts.map +1 -0
- package/dist/commands/harness/account/list.js +58 -0
- package/dist/commands/harness/account/list.js.map +1 -0
- package/dist/commands/harness/account/login.d.ts +16 -0
- package/dist/commands/harness/account/login.d.ts.map +1 -0
- package/dist/commands/harness/account/login.js +50 -0
- package/dist/commands/harness/account/login.js.map +1 -0
- package/dist/commands/harness/account/remove.d.ts +14 -0
- package/dist/commands/harness/account/remove.d.ts.map +1 -0
- package/dist/commands/harness/account/remove.js +43 -0
- package/dist/commands/harness/account/remove.js.map +1 -0
- package/dist/commands/harness/account/set-strategy.d.ts +13 -0
- package/dist/commands/harness/account/set-strategy.d.ts.map +1 -0
- package/dist/commands/harness/account/set-strategy.js +38 -0
- package/dist/commands/harness/account/set-strategy.js.map +1 -0
- package/dist/commands/harness/index.d.ts +7 -0
- package/dist/commands/harness/index.d.ts.map +1 -0
- package/dist/commands/harness/index.js +22 -0
- package/dist/commands/harness/index.js.map +1 -0
- package/dist/commands/harness/usage.d.ts +7 -0
- package/dist/commands/harness/usage.d.ts.map +1 -0
- package/dist/commands/harness/usage.js +10 -0
- package/dist/commands/harness/usage.js.map +1 -0
- package/dist/commands/migrate/convert.d.ts +25 -1
- package/dist/commands/migrate/convert.d.ts.map +1 -1
- package/dist/commands/migrate/convert.js +156 -38
- package/dist/commands/migrate/convert.js.map +1 -1
- package/dist/commands/migrate/index.d.ts +8 -0
- package/dist/commands/migrate/index.d.ts.map +1 -1
- package/dist/commands/migrate/index.js +41 -2
- package/dist/commands/migrate/index.js.map +1 -1
- package/dist/commands/migrate/rebake.d.ts +13 -0
- package/dist/commands/migrate/rebake.d.ts.map +1 -1
- package/dist/commands/migrate/rebake.js +45 -6
- package/dist/commands/migrate/rebake.js.map +1 -1
- package/dist/commands/queue/export-topology.d.ts +2 -0
- package/dist/commands/queue/export-topology.d.ts.map +1 -1
- package/dist/commands/queue/export-topology.js +3 -1
- package/dist/commands/queue/export-topology.js.map +1 -1
- package/dist/commands/queue/import-bindings.d.ts +2 -0
- package/dist/commands/queue/import-bindings.d.ts.map +1 -1
- package/dist/commands/queue/import-bindings.js +3 -1
- package/dist/commands/queue/import-bindings.js.map +1 -1
- package/dist/commands/queue/index.js +1 -1
- package/dist/commands/queue/index.js.map +1 -1
- package/dist/commands/queue/sweep.d.ts +4 -6
- package/dist/commands/queue/sweep.d.ts.map +1 -1
- package/dist/commands/queue/sweep.js +15 -23
- package/dist/commands/queue/sweep.js.map +1 -1
- package/dist/commands/queue/validate-bindings.d.ts +2 -0
- package/dist/commands/queue/validate-bindings.d.ts.map +1 -1
- package/dist/commands/queue/validate-bindings.js +3 -1
- package/dist/commands/queue/validate-bindings.js.map +1 -1
- package/dist/commands/queue/work.d.ts +2 -19
- package/dist/commands/queue/work.d.ts.map +1 -1
- package/dist/commands/queue/work.js +9 -29
- package/dist/commands/queue/work.js.map +1 -1
- package/dist/commands/rubric/usage.d.ts +7 -0
- package/dist/commands/rubric/usage.d.ts.map +1 -0
- package/dist/commands/rubric/usage.js +10 -0
- package/dist/commands/rubric/usage.js.map +1 -0
- package/dist/commands/test/regression/index.d.ts.map +1 -1
- package/dist/commands/test/regression/index.js +2 -0
- package/dist/commands/test/regression/index.js.map +1 -1
- package/dist/commands/test/regression/new.d.ts +21 -0
- package/dist/commands/test/regression/new.d.ts.map +1 -0
- package/dist/commands/test/regression/new.js +82 -0
- package/dist/commands/test/regression/new.js.map +1 -0
- package/dist/commands/test/regression/up.d.ts +1 -0
- package/dist/commands/test/regression/up.d.ts.map +1 -1
- package/dist/commands/test/regression/up.js +17 -0
- package/dist/commands/test/regression/up.js.map +1 -1
- package/dist/commands/test/scripts.d.ts +6 -4
- package/dist/commands/test/scripts.d.ts.map +1 -1
- package/dist/commands/test/scripts.js +14 -0
- package/dist/commands/test/scripts.js.map +1 -1
- package/dist/commands/test/suite.d.ts +1 -0
- package/dist/commands/test/suite.d.ts.map +1 -1
- package/dist/commands/test/suite.js +6 -0
- package/dist/commands/test/suite.js.map +1 -1
- package/dist/commands/usage.js +2 -1
- package/dist/commands/usage.js.map +1 -1
- package/dist/commands/user/usage.d.ts +7 -0
- package/dist/commands/user/usage.d.ts.map +1 -0
- package/dist/commands/user/usage.js +10 -0
- package/dist/commands/user/usage.js.map +1 -0
- package/dist/config.d.ts +119 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +43 -1
- package/dist/config.js.map +1 -1
- package/dist/init-templates/citizen-builder/.env.example +1 -0
- package/dist/init-templates/citizen-builder/docker-compose.yml +2 -0
- package/dist/init-templates/citizen-builder/scripts/docker-entrypoint.sh +2 -1
- package/dist/lib/db-preflight.d.ts.map +1 -1
- package/dist/lib/db-preflight.js +22 -0
- package/dist/lib/db-preflight.js.map +1 -1
- package/dist/lib/derived-usage.d.ts +8 -0
- package/dist/lib/derived-usage.d.ts.map +1 -1
- package/dist/lib/derived-usage.js +30 -20
- package/dist/lib/derived-usage.js.map +1 -1
- package/dist/lib/domain-profiles.d.ts.map +1 -1
- package/dist/lib/domain-profiles.js +24 -0
- package/dist/lib/domain-profiles.js.map +1 -1
- package/dist/lib/domain-usage-command.js +2 -1
- package/dist/lib/domain-usage-command.js.map +1 -1
- package/dist/lib/explorer-postbuild/public-page-html.d.ts +48 -0
- package/dist/lib/explorer-postbuild/public-page-html.d.ts.map +1 -0
- package/dist/lib/explorer-postbuild/public-page-html.js +284 -0
- package/dist/lib/explorer-postbuild/public-page-html.js.map +1 -0
- package/dist/lib/explorer-postbuild/service-worker-check.d.ts +13 -0
- package/dist/lib/explorer-postbuild/service-worker-check.d.ts.map +1 -0
- package/dist/lib/explorer-postbuild/service-worker-check.js +41 -0
- package/dist/lib/explorer-postbuild/service-worker-check.js.map +1 -0
- package/dist/lib/harness-account.d.ts +34 -0
- package/dist/lib/harness-account.d.ts.map +1 -0
- package/dist/lib/harness-account.js +105 -0
- package/dist/lib/harness-account.js.map +1 -0
- package/dist/lib/pg-preflight/checks.d.ts +28 -0
- package/dist/lib/pg-preflight/checks.d.ts.map +1 -0
- package/dist/lib/pg-preflight/checks.js +94 -0
- package/dist/lib/pg-preflight/checks.js.map +1 -0
- package/dist/lib/pg-preflight/extension-check.d.ts +28 -0
- package/dist/lib/pg-preflight/extension-check.d.ts.map +1 -0
- package/dist/lib/pg-preflight/extension-check.js +86 -0
- package/dist/lib/pg-preflight/extension-check.js.map +1 -0
- package/dist/lib/pg-preflight/extension-scan.d.ts +24 -0
- package/dist/lib/pg-preflight/extension-scan.d.ts.map +1 -0
- package/dist/lib/pg-preflight/extension-scan.js +58 -0
- package/dist/lib/pg-preflight/extension-scan.js.map +1 -0
- package/dist/lib/pg-preflight/pending-migrations.d.ts +28 -0
- package/dist/lib/pg-preflight/pending-migrations.d.ts.map +1 -0
- package/dist/lib/pg-preflight/pending-migrations.js +48 -0
- package/dist/lib/pg-preflight/pending-migrations.js.map +1 -0
- package/dist/lib/pg-preflight/preflight.d.ts +18 -0
- package/dist/lib/pg-preflight/preflight.d.ts.map +1 -0
- package/dist/lib/pg-preflight/preflight.js +43 -0
- package/dist/lib/pg-preflight/preflight.js.map +1 -0
- package/dist/lib/pg-preflight/remediation.d.ts +27 -0
- package/dist/lib/pg-preflight/remediation.d.ts.map +1 -0
- package/dist/lib/pg-preflight/remediation.js +82 -0
- package/dist/lib/pg-preflight/remediation.js.map +1 -0
- package/dist/lib/pg-preflight/render.d.ts +15 -0
- package/dist/lib/pg-preflight/render.d.ts.map +1 -0
- package/dist/lib/pg-preflight/render.js +48 -0
- package/dist/lib/pg-preflight/render.js.map +1 -0
- package/dist/lib/pg-preflight/run-for-config.d.ts +23 -0
- package/dist/lib/pg-preflight/run-for-config.d.ts.map +1 -0
- package/dist/lib/pg-preflight/run-for-config.js +45 -0
- package/dist/lib/pg-preflight/run-for-config.js.map +1 -0
- package/dist/lib/pg-preflight/types.d.ts +67 -0
- package/dist/lib/pg-preflight/types.d.ts.map +1 -0
- package/dist/lib/pg-preflight/types.js +8 -0
- package/dist/lib/pg-preflight/types.js.map +1 -0
- package/dist/lib/regression/test-scaffold.d.ts +52 -0
- package/dist/lib/regression/test-scaffold.d.ts.map +1 -0
- package/dist/lib/regression/test-scaffold.js +237 -0
- package/dist/lib/regression/test-scaffold.js.map +1 -0
- package/dist/lib/work-queue/queue-format.d.ts +4 -0
- package/dist/lib/work-queue/queue-format.d.ts.map +1 -1
- package/dist/lib/work-queue/queue-format.js +15 -0
- package/dist/lib/work-queue/queue-format.js.map +1 -1
- package/dist/lib/work-queue/queue-worker.d.ts +16 -1
- package/dist/lib/work-queue/queue-worker.d.ts.map +1 -1
- package/dist/lib/work-queue/queue-worker.js +18 -0
- package/dist/lib/work-queue/queue-worker.js.map +1 -1
- package/dist/light-commands.d.ts.map +1 -1
- package/dist/light-commands.js +34 -0
- package/dist/light-commands.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/open-app-context.d.ts +1 -0
- package/dist/utils/open-app-context.d.ts.map +1 -1
- package/dist/utils/open-app-context.js +7 -2
- package/dist/utils/open-app-context.js.map +1 -1
- package/oclif.manifest.json +2261 -1382
- package/package.json +31 -28
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Managed-PostgreSQL preflight: checks that a database is ready for `mj migrate` before
|
|
3
|
+
* the first migration runs, and says exactly what an administrator must run when it is
|
|
4
|
+
* not. Without it, a pre-provisioned managed database fails partway through the baseline
|
|
5
|
+
* with a GRANT or `CREATE EXTENSION` error.
|
|
6
|
+
*
|
|
7
|
+
* @module lib/pg-preflight/preflight
|
|
8
|
+
*/
|
|
9
|
+
import type { PgPreflightOptions, PgPreflightQueryRunner, PgPreflightReport } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Runs every check against an open session. A check whose query throws reports `warn`
|
|
12
|
+
* rather than aborting the rest, except the session query every check needs, which throws.
|
|
13
|
+
*
|
|
14
|
+
* @param runner - Connected as the login `mj migrate` uses.
|
|
15
|
+
* @param options - Target schema, the extensions pending migrations create, and so on.
|
|
16
|
+
*/
|
|
17
|
+
export declare function RunPgManagedPreflight(runner: PgPreflightQueryRunner, options: PgPreflightOptions): Promise<PgPreflightReport>;
|
|
18
|
+
//# sourceMappingURL=preflight.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preflight.d.ts","sourceRoot":"","sources":["../../../src/lib/pg-preflight/preflight.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAcH,OAAO,KAAK,EAAwC,kBAAkB,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEnI;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,sBAAsB,EAAE,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAanI"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Managed-PostgreSQL preflight: checks that a database is ready for `mj migrate` before
|
|
3
|
+
* the first migration runs, and says exactly what an administrator must run when it is
|
|
4
|
+
* not. Without it, a pre-provisioned managed database fails partway through the baseline
|
|
5
|
+
* with a GRANT or `CREATE EXTENSION` error.
|
|
6
|
+
*
|
|
7
|
+
* @module lib/pg-preflight/preflight
|
|
8
|
+
*/
|
|
9
|
+
import { POSTGRES_MJ_GROUP_ROLES } from '@memberjunction/installer';
|
|
10
|
+
import { CheckConnections, CheckDatabaseCreate, CheckGroupRoles, CheckServerVersion, CheckTargetSchema, CheckTls, MakeCheck, ReadSessionContext, } from './checks.js';
|
|
11
|
+
import { CheckExtensions } from './extension-check.js';
|
|
12
|
+
/**
|
|
13
|
+
* Runs every check against an open session. A check whose query throws reports `warn`
|
|
14
|
+
* rather than aborting the rest, except the session query every check needs, which throws.
|
|
15
|
+
*
|
|
16
|
+
* @param runner - Connected as the login `mj migrate` uses.
|
|
17
|
+
* @param options - Target schema, the extensions pending migrations create, and so on.
|
|
18
|
+
*/
|
|
19
|
+
export async function RunPgManagedPreflight(runner, options) {
|
|
20
|
+
const session = await ReadSessionContext(runner);
|
|
21
|
+
const roles = options.RequiredRoles ?? POSTGRES_MJ_GROUP_ROLES;
|
|
22
|
+
const checks = [
|
|
23
|
+
CheckServerVersion(session, options.MinimumServerVersionNum),
|
|
24
|
+
await guarded('group-roles', () => CheckGroupRoles(runner, session, roles)),
|
|
25
|
+
CheckDatabaseCreate(session),
|
|
26
|
+
await guarded('target-schema', () => CheckTargetSchema(runner, session, options.TargetSchema)),
|
|
27
|
+
await guarded('extensions', () => CheckExtensions(runner, session, options.RequiredExtensions)),
|
|
28
|
+
await guarded('tls', () => CheckTls(runner, options.Host)),
|
|
29
|
+
await guarded('connections', () => CheckConnections(runner)),
|
|
30
|
+
];
|
|
31
|
+
return { Session: session, TargetSchema: options.TargetSchema, Checks: checks, Passed: !checks.some((c) => c.Status === 'fail') };
|
|
32
|
+
}
|
|
33
|
+
/** Runs one check, turning a query error into a warning that names the check. */
|
|
34
|
+
async function guarded(id, run) {
|
|
35
|
+
try {
|
|
36
|
+
return await run();
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
40
|
+
return MakeCheck(id, 'warn', `Could not run the ${id} check: ${message}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=preflight.js.map
|
|
@@ -0,0 +1 @@
|
|
|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AC7D,CAAC;IACF,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,EAAE,CAAC;AACpI,CAAC;AAED,iFAAiF;AACjF,KAAK,UAAU,OAAO,CAAC,EAAsB,EAAE,GAAoC;IACjF,IAAI,CAAC;QACH,OAAO,MAAM,GAAG,EAAE,CAAC;IACrB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACjE,OAAO,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,qBAAqB,EAAE,WAAW,OAAO,EAAE,CAAC,CAAC;IAC5E,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The SQL an administrator runs to fix a failed preflight check.
|
|
3
|
+
*
|
|
4
|
+
* Every statement is taken from the installer's own step builder
|
|
5
|
+
* (`BuildPostgresSetupSteps` in `@memberjunction/installer`) when the installer has
|
|
6
|
+
* one for it, so `mj migrate` and `mj install` can never tell an administrator two
|
|
7
|
+
* different things. A statement is built here only when the installer has no step for
|
|
8
|
+
* it (an Open App schema, an extension outside `POSTGRES_MJ_EXTENSIONS`), and then
|
|
9
|
+
* with the installer's own quoting helper.
|
|
10
|
+
*
|
|
11
|
+
* @module lib/pg-preflight/remediation
|
|
12
|
+
*/
|
|
13
|
+
import type { PgPreflightReport, PgRemediationStep, PgSessionContext } from './types.js';
|
|
14
|
+
/** `CREATE ROLE ... NOLOGIN` for each missing group role. */
|
|
15
|
+
export declare function RoleRemediation(session: PgSessionContext, missingRoles: readonly string[]): PgRemediationStep[];
|
|
16
|
+
/** `CREATE EXTENSION IF NOT EXISTS` for each extension. */
|
|
17
|
+
export declare function ExtensionRemediation(session: PgSessionContext, extensions: readonly string[]): PgRemediationStep[];
|
|
18
|
+
/** `GRANT CONNECT, CREATE, TEMPORARY ON DATABASE` to the migrate login. */
|
|
19
|
+
export declare function DatabaseCreateRemediation(session: PgSessionContext): PgRemediationStep[];
|
|
20
|
+
/** `ALTER SCHEMA ... OWNER TO` the migrate login. */
|
|
21
|
+
export declare function SchemaOwnerRemediation(session: PgSessionContext, schema: string): PgRemediationStep[];
|
|
22
|
+
/**
|
|
23
|
+
* Renders every failed check's remediation as one script an administrator can paste
|
|
24
|
+
* into psql or any SQL client. Returns an empty string when nothing needs fixing.
|
|
25
|
+
*/
|
|
26
|
+
export declare function RenderRemediationScript(report: PgPreflightReport): string;
|
|
27
|
+
//# sourceMappingURL=remediation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remediation.d.ts","sourceRoot":"","sources":["../../../src/lib/pg-preflight/remediation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAatF,6DAA6D;AAC7D,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,SAAS,MAAM,EAAE,GAAG,iBAAiB,EAAE,CAQ/G;AAED,2DAA2D;AAC3D,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,SAAS,MAAM,EAAE,GAAG,iBAAiB,EAAE,CAMlH;AAED,2EAA2E;AAC3E,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,gBAAgB,GAAG,iBAAiB,EAAE,CAUxF;AAED,qDAAqD;AACrD,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,GAAG,iBAAiB,EAAE,CAGrG;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,CAUzE"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The SQL an administrator runs to fix a failed preflight check.
|
|
3
|
+
*
|
|
4
|
+
* Every statement is taken from the installer's own step builder
|
|
5
|
+
* (`BuildPostgresSetupSteps` in `@memberjunction/installer`) when the installer has
|
|
6
|
+
* one for it, so `mj migrate` and `mj install` can never tell an administrator two
|
|
7
|
+
* different things. A statement is built here only when the installer has no step for
|
|
8
|
+
* it (an Open App schema, an extension outside `POSTGRES_MJ_EXTENSIONS`), and then
|
|
9
|
+
* with the installer's own quoting helper.
|
|
10
|
+
*
|
|
11
|
+
* @module lib/pg-preflight/remediation
|
|
12
|
+
*/
|
|
13
|
+
import { BuildPostgresSetupSteps, QuotePgIdentifier } from '@memberjunction/installer';
|
|
14
|
+
/** The installer's steps for this database and login. Passwords are never printed. */
|
|
15
|
+
function installerSteps(session) {
|
|
16
|
+
return BuildPostgresSetupSteps({ DatabaseName: session.Database, CodeGenUser: session.Login });
|
|
17
|
+
}
|
|
18
|
+
/** The installer step matching `predicate`, or `fallback` when it has none. */
|
|
19
|
+
function pickStep(steps, predicate, fallback) {
|
|
20
|
+
const step = steps.find(predicate);
|
|
21
|
+
return step ? { Description: step.Description, Sql: step.Sql } : fallback;
|
|
22
|
+
}
|
|
23
|
+
/** `CREATE ROLE ... NOLOGIN` for each missing group role. */
|
|
24
|
+
export function RoleRemediation(session, missingRoles) {
|
|
25
|
+
const steps = installerSteps(session);
|
|
26
|
+
return missingRoles.map((role) => pickStep(steps, (s) => s.SkipIf?.Param === role && s.Sql.startsWith('CREATE ROLE') && s.Sql.endsWith(' NOLOGIN'), {
|
|
27
|
+
Description: `Create group role ${role}`,
|
|
28
|
+
Sql: `CREATE ROLE ${QuotePgIdentifier(role)} NOLOGIN`,
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
/** `CREATE EXTENSION IF NOT EXISTS` for each extension. */
|
|
32
|
+
export function ExtensionRemediation(session, extensions) {
|
|
33
|
+
const steps = installerSteps(session);
|
|
34
|
+
return extensions.map((ext) => {
|
|
35
|
+
const sql = `CREATE EXTENSION IF NOT EXISTS ${QuotePgIdentifier(ext)}`;
|
|
36
|
+
return pickStep(steps, (s) => s.Sql === sql, { Description: `Create extension ${ext}`, Sql: sql });
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/** `GRANT CONNECT, CREATE, TEMPORARY ON DATABASE` to the migrate login. */
|
|
40
|
+
export function DatabaseCreateRemediation(session) {
|
|
41
|
+
const steps = installerSteps(session);
|
|
42
|
+
const database = QuotePgIdentifier(session.Database);
|
|
43
|
+
const login = QuotePgIdentifier(session.Login);
|
|
44
|
+
return [
|
|
45
|
+
pickStep(steps, (s) => s.Sql.startsWith('GRANT CONNECT, CREATE, TEMPORARY ON DATABASE'), {
|
|
46
|
+
Description: `Let ${session.Login} connect and create schemas`,
|
|
47
|
+
Sql: `GRANT CONNECT, CREATE, TEMPORARY ON DATABASE ${database} TO ${login}`,
|
|
48
|
+
}),
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
/** `ALTER SCHEMA ... OWNER TO` the migrate login. */
|
|
52
|
+
export function SchemaOwnerRemediation(session, schema) {
|
|
53
|
+
const sql = `ALTER SCHEMA ${QuotePgIdentifier(schema)} OWNER TO ${QuotePgIdentifier(session.Login)}`;
|
|
54
|
+
return [pickStep(installerSteps(session), (s) => s.Sql === sql, { Description: `Make ${session.Login} the owner of schema ${schema}`, Sql: sql })];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Renders every failed check's remediation as one script an administrator can paste
|
|
58
|
+
* into psql or any SQL client. Returns an empty string when nothing needs fixing.
|
|
59
|
+
*/
|
|
60
|
+
export function RenderRemediationScript(report) {
|
|
61
|
+
const steps = uniqueSteps(report.Checks.filter((c) => c.Status === 'fail').flatMap((c) => c.Remediation));
|
|
62
|
+
if (steps.length === 0)
|
|
63
|
+
return '';
|
|
64
|
+
const lines = [
|
|
65
|
+
'-- Run as a PostgreSQL administrator (a superuser, rds_superuser on AWS RDS, or',
|
|
66
|
+
`-- azure_pg_admin on Azure), connected to database ${QuotePgIdentifier(report.Session.Database)}.`,
|
|
67
|
+
'-- Then run `mj migrate` again.',
|
|
68
|
+
];
|
|
69
|
+
steps.forEach((step, index) => lines.push('', `-- ${index + 1}. ${step.Description}`, `${step.Sql};`));
|
|
70
|
+
return lines.join('\n');
|
|
71
|
+
}
|
|
72
|
+
/** Drops repeated statements, keeping the first. */
|
|
73
|
+
function uniqueSteps(steps) {
|
|
74
|
+
const seen = new Set();
|
|
75
|
+
return steps.filter((step) => {
|
|
76
|
+
if (seen.has(step.Sql))
|
|
77
|
+
return false;
|
|
78
|
+
seen.add(step.Sql);
|
|
79
|
+
return true;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=remediation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remediation.js","sourceRoot":"","sources":["../../../src/lib/pg-preflight/remediation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAoB,MAAM,2BAA2B,CAAC;AAGzG,sFAAsF;AACtF,SAAS,cAAc,CAAC,OAAyB;IAC/C,OAAO,uBAAuB,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,QAAQ,EAAE,WAAW,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;AACjG,CAAC;AAED,+EAA+E;AAC/E,SAAS,QAAQ,CAAC,KAA6B,EAAE,SAAyC,EAAE,QAA2B;IACrH,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACnC,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,GAAG,EAAE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,CAAC,GAAG;QACnG,iCAAiC;KAClC,CAAC;IACF,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,KAAK,GAAG,CAAC,KAAK,IAAI,CAAC,WAAW,EAAE,EAAE,GAAG,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;IACvG,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED,oDAAoD;AACpD,SAAS,WAAW,CAAC,KAAmC;IACtD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;QAC3B,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC;QACrC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACnB,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text output for the managed-PostgreSQL preflight, shared by `mj doctor --db` and
|
|
3
|
+
* `mj migrate` so both print the same thing.
|
|
4
|
+
*
|
|
5
|
+
* @module lib/pg-preflight/render
|
|
6
|
+
*/
|
|
7
|
+
import type { PgPreflightReport } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* The report as printable lines: one per check, then (when anything failed) the
|
|
10
|
+
* non-SQL notes and the remediation script.
|
|
11
|
+
*/
|
|
12
|
+
export declare function FormatPgPreflightReport(report: PgPreflightReport): string[];
|
|
13
|
+
/** One-line summary: counts of each status. */
|
|
14
|
+
export declare function SummarizePgPreflightReport(report: PgPreflightReport): string;
|
|
15
|
+
//# sourceMappingURL=render.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../../src/lib/pg-preflight/render.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,iBAAiB,EAAqB,MAAM,SAAS,CAAC;AAgBpE;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,EAAE,CAgB3E;AAED,+CAA+C;AAC/C,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,CAG5E"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text output for the managed-PostgreSQL preflight, shared by `mj doctor --db` and
|
|
3
|
+
* `mj migrate` so both print the same thing.
|
|
4
|
+
*
|
|
5
|
+
* @module lib/pg-preflight/render
|
|
6
|
+
*/
|
|
7
|
+
import chalk from 'chalk';
|
|
8
|
+
import { RenderRemediationScript } from './remediation.js';
|
|
9
|
+
/** `[PASS]`-style tag for a status. */
|
|
10
|
+
function statusTag(status) {
|
|
11
|
+
switch (status) {
|
|
12
|
+
case 'pass':
|
|
13
|
+
return chalk.green('[PASS]');
|
|
14
|
+
case 'fail':
|
|
15
|
+
return chalk.red('[FAIL]');
|
|
16
|
+
case 'warn':
|
|
17
|
+
return chalk.yellow('[WARN]');
|
|
18
|
+
default:
|
|
19
|
+
return chalk.blue('[INFO]');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The report as printable lines: one per check, then (when anything failed) the
|
|
24
|
+
* non-SQL notes and the remediation script.
|
|
25
|
+
*/
|
|
26
|
+
export function FormatPgPreflightReport(report) {
|
|
27
|
+
const { Session } = report;
|
|
28
|
+
const lines = [chalk.bold(`PostgreSQL readiness — database ${Session.Database}, login ${Session.Login}, schema ${report.TargetSchema}`)];
|
|
29
|
+
for (const check of report.Checks) {
|
|
30
|
+
lines.push(`${statusTag(check.Status)} ${check.Message}`);
|
|
31
|
+
}
|
|
32
|
+
const failed = report.Checks.filter((c) => c.Status === 'fail');
|
|
33
|
+
const notes = failed.flatMap((c) => c.Notes);
|
|
34
|
+
if (notes.length > 0) {
|
|
35
|
+
lines.push('', chalk.yellow('Also required:'), ...notes.map((n) => ` - ${n}`));
|
|
36
|
+
}
|
|
37
|
+
const script = RenderRemediationScript(report);
|
|
38
|
+
if (script) {
|
|
39
|
+
lines.push('', chalk.yellow('An administrator must run this SQL first:'), '', script);
|
|
40
|
+
}
|
|
41
|
+
return lines;
|
|
42
|
+
}
|
|
43
|
+
/** One-line summary: counts of each status. */
|
|
44
|
+
export function SummarizePgPreflightReport(report) {
|
|
45
|
+
const count = (s) => report.Checks.filter((c) => c.Status === s).length;
|
|
46
|
+
return `${count('fail')} failed, ${count('warn')} warning(s), ${count('pass')} passed`;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=render.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../../../src/lib/pg-preflight/render.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAGxD,uCAAuC;AACvC,SAAS,SAAS,CAAC,MAAyB;IAC1C,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,MAAM;YACT,OAAO,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAC/B,KAAK,MAAM;YACT,OAAO,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC7B,KAAK,MAAM;YACT,OAAO,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAChC;YACE,OAAO,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAChC,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CAAC,MAAyB;IAC/D,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IAC3B,MAAM,KAAK,GAAG,C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AC,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC;IAC3F,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,YAAY,KAAK,CAAC,MAAM,CAAC,gBAAgB,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC;AACzF,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs the managed-PostgreSQL preflight for an MJ config: reads the pending migrations,
|
|
3
|
+
* connects as the migrate login, runs the checks, and closes the connection.
|
|
4
|
+
*
|
|
5
|
+
* @module lib/pg-preflight/run-for-config
|
|
6
|
+
*/
|
|
7
|
+
import type { SkywayConfig } from '@memberjunction/skyway-core';
|
|
8
|
+
import { type QueryRunner } from '../../baseline/connection.js';
|
|
9
|
+
import type { MJConfig } from '../../config.js';
|
|
10
|
+
import type { PgPreflightQueryRunner, PgPreflightReport } from './types.js';
|
|
11
|
+
/** The config fields the preflight connection needs. */
|
|
12
|
+
export type PgPreflightConnectionConfig = Pick<MJConfig, 'dbHost' | 'dbPort' | 'dbDatabase' | 'codeGenLogin' | 'codeGenPassword'>;
|
|
13
|
+
/**
|
|
14
|
+
* Runs the preflight.
|
|
15
|
+
*
|
|
16
|
+
* @param config - The MJ config `mj migrate` runs with (its CodeGen login is the migrate login).
|
|
17
|
+
* @param skywayProbe - A Skyway config for the same schema and migration location, used only
|
|
18
|
+
* to read pending migrations; its provider is connected and disconnected here.
|
|
19
|
+
*/
|
|
20
|
+
export declare function RunPgPreflightForConfig(config: PgPreflightConnectionConfig, skywayProbe: SkywayConfig): Promise<PgPreflightReport>;
|
|
21
|
+
/** Wraps the baseline connection helper in the preflight's query interface. */
|
|
22
|
+
export declare function AdaptQueryRunner(connection: Pick<QueryRunner, 'query'>): PgPreflightQueryRunner;
|
|
23
|
+
//# sourceMappingURL=run-for-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-for-config.d.ts","sourceRoot":"","sources":["../../../src/lib/pg-preflight/run-for-config.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAkB,KAAK,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC7E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG7C,OAAO,KAAK,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEzE,wDAAwD;AACxD,MAAM,MAAM,2BAA2B,GAAG,IAAI,CAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ,GAAG,YAAY,GAAG,cAAc,GAAG,iBAAiB,CAAC,CAAC;AAElI;;;;;;GAMG;AACH,wBAAsB,uBAAuB,CAAC,MAAM,EAAE,2BAA2B,EAAE,WAAW,EAAE,YAAY,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAoBxI;AAED,+EAA+E;AAC/E,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,GAAG,sBAAsB,CAI/F"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs the managed-PostgreSQL preflight for an MJ config: reads the pending migrations,
|
|
3
|
+
* connects as the migrate login, runs the checks, and closes the connection.
|
|
4
|
+
*
|
|
5
|
+
* @module lib/pg-preflight/run-for-config
|
|
6
|
+
*/
|
|
7
|
+
import { OpenConnection } from '../../baseline/connection.js';
|
|
8
|
+
import { ReadPendingRequirements } from './pending-migrations.js';
|
|
9
|
+
import { RunPgManagedPreflight } from './preflight.js';
|
|
10
|
+
/**
|
|
11
|
+
* Runs the preflight.
|
|
12
|
+
*
|
|
13
|
+
* @param config - The MJ config `mj migrate` runs with (its CodeGen login is the migrate login).
|
|
14
|
+
* @param skywayProbe - A Skyway config for the same schema and migration location, used only
|
|
15
|
+
* to read pending migrations; its provider is connected and disconnected here.
|
|
16
|
+
*/
|
|
17
|
+
export async function RunPgPreflightForConfig(config, skywayProbe) {
|
|
18
|
+
const pending = await ReadPendingRequirements(skywayProbe);
|
|
19
|
+
const connection = await OpenConnection({
|
|
20
|
+
Dialect: 'postgres',
|
|
21
|
+
Host: config.dbHost,
|
|
22
|
+
port: config.dbPort,
|
|
23
|
+
User: config.codeGenLogin,
|
|
24
|
+
Password: config.codeGenPassword,
|
|
25
|
+
Database: config.dbDatabase,
|
|
26
|
+
});
|
|
27
|
+
try {
|
|
28
|
+
return await RunPgManagedPreflight(AdaptQueryRunner(connection), {
|
|
29
|
+
TargetSchema: skywayProbe.Migrations.DefaultSchema ?? '__mj',
|
|
30
|
+
RequiredExtensions: pending.Extensions,
|
|
31
|
+
RequiredRoles: pending.Roles,
|
|
32
|
+
Host: config.dbHost,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
await connection.close();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** Wraps the baseline connection helper in the preflight's query interface. */
|
|
40
|
+
export function AdaptQueryRunner(connection) {
|
|
41
|
+
return {
|
|
42
|
+
Query: (sql, params) => connection.query(sql, params),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=run-for-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-for-config.js","sourceRoot":"","sources":["../../../src/lib/pg-preflight/run-for-config.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,cAAc,EAAoB,MAAM,2BAA2B,CAAC;AAE7E,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAMpD;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,MAAmC,EAAE,WAAyB;IAC1G,MAAM,OAAO,GAAG,MAAM,uBAAuB,CAAC,WAAW,CAAC,CAAC;IAC3D,MAAM,UAAU,GAAG,MAAM,cAAc,CAAC;QACtC,OAAO,EAAE,UAAU;QACnB,IAAI,EAAE,MAAM,CAAC,MAAM;QACnB,IAAI,EAAE,MAAM,CAAC,MAAM;QACnB,IAAI,EAAE,MAAM,CAAC,YAAY;QACzB,QAAQ,EAAE,MAAM,CAAC,eAAe;QAChC,QAAQ,EAAE,MAAM,CAAC,UAAU;KAC5B,CAAC,CAAC;IACH,IAAI,CAAC;QACH,OAAO,MAAM,qBAAqB,CAAC,gBAAgB,CAAC,UAAU,CAAC,EAAE;YAC/D,YAAY,EAAE,WAAW,CAAC,UAAU,CAAC,aAAa,IAAI,MAAM;YAC5D,kBAAkB,EAAE,OAAO,CAAC,UAAU;YACtC,aAAa,EAAE,OAAO,CAAC,KAAK;YAC5B,IAAI,EAAE,MAAM,CAAC,MAAM;SACpB,CAAC,CAAC;IACL,CAAC;YAAS,CAAC;QACT,MAAM,UAAU,CAAC,KAAK,EAAE,CAAC;IAC3B,CAAC;AACH,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,gBAAgB,CAAC,UAAsC;IACrE,OAAO;QACL,KAAK,EAAE,CAAI,GAAW,EAAE,MAAkB,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,CAAI,GAAG,EAAE,MAAM,CAAC;KAChF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for the managed-PostgreSQL preflight (`mj doctor --db`, and the check `mj migrate`
|
|
3
|
+
* runs before it applies anything on PostgreSQL).
|
|
4
|
+
*
|
|
5
|
+
* @module lib/pg-preflight/types
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* The one database call the checks make. An interface rather than a `pg.Client` so the
|
|
9
|
+
* checks can be unit-tested against a fake.
|
|
10
|
+
*/
|
|
11
|
+
export interface PgPreflightQueryRunner {
|
|
12
|
+
/** Run one statement with optional `$n` parameters and return its rows. */
|
|
13
|
+
Query<T>(sql: string, params?: unknown[]): Promise<T[]>;
|
|
14
|
+
}
|
|
15
|
+
/** Outcome of one check. Only `fail` blocks `mj migrate`. */
|
|
16
|
+
export type PgPreflightStatus = 'pass' | 'fail' | 'warn' | 'info';
|
|
17
|
+
/** The checks, in the order they run and print. */
|
|
18
|
+
export type PgPreflightCheckId = 'server-version' | 'group-roles' | 'database-create' | 'target-schema' | 'extensions' | 'tls' | 'connections';
|
|
19
|
+
/** One statement an administrator runs to fix a failed check. */
|
|
20
|
+
export interface PgRemediationStep {
|
|
21
|
+
/** What the statement does, printed as a comment above it. */
|
|
22
|
+
Description: string;
|
|
23
|
+
/** The statement, without a trailing semicolon. */
|
|
24
|
+
Sql: string;
|
|
25
|
+
}
|
|
26
|
+
/** The result of one check. */
|
|
27
|
+
export interface PgPreflightCheck {
|
|
28
|
+
Id: PgPreflightCheckId;
|
|
29
|
+
Status: PgPreflightStatus;
|
|
30
|
+
/** One line describing what was found. */
|
|
31
|
+
Message: string;
|
|
32
|
+
/** SQL that fixes a `fail` (empty otherwise, or when the fix is not SQL). */
|
|
33
|
+
Remediation: PgRemediationStep[];
|
|
34
|
+
/** Fixes that are not SQL, such as a server parameter on a managed host. */
|
|
35
|
+
Notes: string[];
|
|
36
|
+
}
|
|
37
|
+
/** What the session reports about itself; read once and shared by the checks. */
|
|
38
|
+
export interface PgSessionContext {
|
|
39
|
+
Login: string;
|
|
40
|
+
Database: string;
|
|
41
|
+
ServerVersion: string;
|
|
42
|
+
ServerVersionNum: number;
|
|
43
|
+
CanCreateInDatabase: boolean;
|
|
44
|
+
IsSuperuser: boolean;
|
|
45
|
+
}
|
|
46
|
+
/** Inputs to `RunPgManagedPreflight`. */
|
|
47
|
+
export interface PgPreflightOptions {
|
|
48
|
+
/** Schema the migrations target (`__mj`, or an Open App schema). */
|
|
49
|
+
TargetSchema: string;
|
|
50
|
+
/** Extensions the pending migrations `CREATE`. */
|
|
51
|
+
RequiredExtensions: readonly string[];
|
|
52
|
+
/** Group roles the migrations grant to. Defaults to the installer's `POSTGRES_MJ_GROUP_ROLES`. */
|
|
53
|
+
RequiredRoles?: readonly string[];
|
|
54
|
+
/** Host the session connected to; a loopback host downgrades the TLS warning to info. */
|
|
55
|
+
Host?: string;
|
|
56
|
+
/** Lowest supported `server_version_num`. Defaults to 140000 (PostgreSQL 14). */
|
|
57
|
+
MinimumServerVersionNum?: number;
|
|
58
|
+
}
|
|
59
|
+
/** The full preflight outcome. */
|
|
60
|
+
export interface PgPreflightReport {
|
|
61
|
+
Session: PgSessionContext;
|
|
62
|
+
TargetSchema: string;
|
|
63
|
+
Checks: PgPreflightCheck[];
|
|
64
|
+
/** False when any check failed. */
|
|
65
|
+
Passed: boolean;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lib/pg-preflight/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,2EAA2E;IAC3E,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;CACzD;AAED,6DAA6D;AAC7D,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAElE,mDAAmD;AACnD,MAAM,MAAM,kBAAkB,GAC1B,gBAAgB,GAChB,aAAa,GACb,iBAAiB,GACjB,eAAe,GACf,YAAY,GACZ,KAAK,GACL,aAAa,CAAC;AAElB,iEAAiE;AACjE,MAAM,WAAW,iBAAiB;IAChC,8DAA8D;IAC9D,WAAW,EAAE,MAAM,CAAC;IACpB,mDAAmD;IACnD,GAAG,EAAE,MAAM,CAAC;CACb;AAED,+BAA+B;AAC/B,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,kBAAkB,CAAC;IACvB,MAAM,EAAE,iBAAiB,CAAC;IAC1B,0CAA0C;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,6EAA6E;IAC7E,WAAW,EAAE,iBAAiB,EAAE,CAAC;IACjC,4EAA4E;IAC5E,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,iFAAiF;AACjF,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,EAAE,MAAM,CAAC;IACzB,mBAAmB,EAAE,OAAO,CAAC;IAC7B,WAAW,EAAE,OAAO,CAAC;CACtB;AAED,yCAAyC;AACzC,MAAM,WAAW,kBAAkB;IACjC,oEAAoE;IACpE,YAAY,EAAE,MAAM,CAAC;IACrB,kDAAkD;IAClD,kBAAkB,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,kGAAkG;IAClG,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,yFAAyF;IACzF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,iFAAiF;IACjF,uBAAuB,CAAC,EAAE,MAAM,CAAC;CAClC;AAED,kCAAkC;AAClC,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,gBAAgB,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,gBAAgB,EAAE,CAAC;IAC3B,mCAAmC;IACnC,MAAM,EAAE,OAAO,CAAC;CACjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/lib/pg-preflight/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export declare const REGRESSION_TESTS_DIR = "metadata-optional/regression-test/tests/regression";
|
|
2
|
+
export declare const REGRESSION_SUITE_FILE = "metadata-optional/regression-test/test-suites/.regression-suite.json";
|
|
3
|
+
export declare const REGRESSION_PARITY_SCRIPT = ".github/scripts/check-regression-suite.mjs";
|
|
4
|
+
declare const PRIORITIES: readonly ["P0", "P1", "P2", "P3"];
|
|
5
|
+
export type JsonPrimitive = string | number | boolean | null;
|
|
6
|
+
export type JsonValue = JsonPrimitive | JsonValue[] | JsonObject;
|
|
7
|
+
export type JsonObject = {
|
|
8
|
+
[key: string]: JsonValue;
|
|
9
|
+
};
|
|
10
|
+
export type RegressionPriority = (typeof PRIORITIES)[number];
|
|
11
|
+
export interface ScaffoldOptions {
|
|
12
|
+
/** Title without the `T### - ` prefix. */
|
|
13
|
+
Title: string;
|
|
14
|
+
/** What the controller LLM must achieve, stated as the success state. */
|
|
15
|
+
Goal: string;
|
|
16
|
+
/** Judge criteria, checked against the final screenshot. */
|
|
17
|
+
Criteria: string[];
|
|
18
|
+
Priority: RegressionPriority;
|
|
19
|
+
/** Area tags. The priority and `regression` are always added. */
|
|
20
|
+
Tags: string[];
|
|
21
|
+
/** Path after the base URL, e.g. `/app/form-builder`. Empty for the app root. */
|
|
22
|
+
StartPath: string;
|
|
23
|
+
MaxSteps: number;
|
|
24
|
+
/** Defaults to the goal. */
|
|
25
|
+
Description?: string;
|
|
26
|
+
/** Copy `Configuration` from this existing test number. */
|
|
27
|
+
FromNumber?: number;
|
|
28
|
+
}
|
|
29
|
+
export interface ScaffoldResult {
|
|
30
|
+
Number: number;
|
|
31
|
+
Name: string;
|
|
32
|
+
Sequence: number;
|
|
33
|
+
/** Repo-relative path of the new test file. */
|
|
34
|
+
TestFilePath: string;
|
|
35
|
+
TestFileContent: string;
|
|
36
|
+
SuiteFileContent: string;
|
|
37
|
+
}
|
|
38
|
+
export declare function IsRegressionPriority(value: string): value is RegressionPriority;
|
|
39
|
+
/** Formats a test number as `T###`. */
|
|
40
|
+
export declare function FormatTestNumber(n: number): string;
|
|
41
|
+
/** Parses `T149` or `149` into `149`. */
|
|
42
|
+
export declare function ParseTestNumber(text: string): number;
|
|
43
|
+
/** Turns a title into the kebab-case part of a test file name. */
|
|
44
|
+
export declare function SlugifyTitle(title: string): string;
|
|
45
|
+
/** Returns the highest `.T###-*.json` number plus one. */
|
|
46
|
+
export declare function NextTestNumber(fileNames: string[]): number;
|
|
47
|
+
/** Builds the new test record and the updated suite file. Writes nothing. */
|
|
48
|
+
export declare function BuildScaffold(repoRoot: string, options: ScaffoldOptions): ScaffoldResult;
|
|
49
|
+
/** Writes the test file and the updated suite file. Refuses to overwrite a test file. */
|
|
50
|
+
export declare function WriteScaffold(repoRoot: string, result: ScaffoldResult): void;
|
|
51
|
+
export {};
|
|
52
|
+
//# sourceMappingURL=test-scaffold.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-scaffold.d.ts","sourceRoot":"","sources":["../../../src/lib/regression/test-scaffold.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,oBAAoB,uDAAuD,CAAC;AACzF,eAAO,MAAM,qBAAqB,yEAAyE,CAAC;AAC5G,eAAO,MAAM,wBAAwB,+CAA+C,CAAC;AAUrF,QAAA,MAAM,UAAU,mCAAoC,CAAC;AAErD,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAC7D,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,SAAS,EAAE,GAAG,UAAU,CAAC;AACjE,MAAM,MAAM,UAAU,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAEtD,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AA6C7D,MAAM,WAAW,eAAe;IAC9B,0CAA0C;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,yEAAyE;IACzE,IAAI,EAAE,MAAM,CAAC;IACb,4DAA4D;IAC5D,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,iEAAiE;IACjE,IAAI,EAAE,MAA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