@logto/cli 1.34.0 → 1.36.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.
|
@@ -28,28 +28,47 @@ export const getAvailableAlterations = async (pool, compareMode = 'gt') => {
|
|
|
28
28
|
: getTimestampFromFilename(filename) <= databaseTimestamp);
|
|
29
29
|
};
|
|
30
30
|
const deployAlteration = async (pool, { path: filePath, filename }, action = 'up') => {
|
|
31
|
-
const { up, down } = await importAlterationScript(filePath);
|
|
31
|
+
const { up, down, beforeUp, beforeDown } = await importAlterationScript(filePath);
|
|
32
|
+
const timestamp = getTimestampFromFilename(filename);
|
|
32
33
|
try {
|
|
33
|
-
|
|
34
|
-
if (
|
|
34
|
+
if (action === 'up') {
|
|
35
|
+
if (beforeUp) {
|
|
36
|
+
await beforeUp(pool);
|
|
37
|
+
}
|
|
38
|
+
await pool.transaction(async (connection) => {
|
|
35
39
|
await up(connection);
|
|
36
|
-
await updateDatabaseTimestamp(connection,
|
|
40
|
+
await updateDatabaseTimestamp(connection, timestamp);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
if (action === 'down') {
|
|
44
|
+
if (beforeDown) {
|
|
45
|
+
await beforeDown(pool);
|
|
37
46
|
}
|
|
38
|
-
|
|
47
|
+
await pool.transaction(async (connection) => {
|
|
39
48
|
await down(connection);
|
|
40
|
-
const newTimestamp =
|
|
49
|
+
const newTimestamp = timestamp - 1;
|
|
41
50
|
if (newTimestamp > 0) {
|
|
42
51
|
await updateDatabaseTimestamp(connection, newTimestamp);
|
|
43
52
|
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
46
55
|
}
|
|
47
56
|
catch (error) {
|
|
48
57
|
consoleLog.error(error);
|
|
49
58
|
await pool.end();
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
59
|
+
const hasNonTransactionalSteps =
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
61
|
+
(action === 'up' && beforeUp) || (action === 'down' && beforeDown);
|
|
62
|
+
if (hasNonTransactionalSteps) {
|
|
63
|
+
consoleLog.fatal(`Error occurred while running alteration ${chalk.blue(filename)}.\n\n` +
|
|
64
|
+
' Non-transactional steps (`beforeUp`/`beforeDown`) may have been applied before the failure.\n' +
|
|
65
|
+
' Inspect the database state, fix the issue, then rerun the alteration to reconcile state and timestamp.');
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
consoleLog.fatal(`Error occurred while running alteration ${chalk.blue(filename)}.\n\n` +
|
|
69
|
+
" This alteration didn't change anything since it was in a transaction.\n" +
|
|
70
|
+
' Fix the error and deploy again.');
|
|
71
|
+
}
|
|
53
72
|
}
|
|
54
73
|
consoleLog.info(`Run alteration ${filename} \`${action}()\` function succeeded`);
|
|
55
74
|
};
|
|
@@ -2,7 +2,7 @@ import { readdir, readFile } from 'node:fs/promises';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { createDefaultAdminConsoleConfig, defaultTenantId, adminTenantId, defaultManagementApi, createAdminDataInAdminTenant, createMeApiInAdminTenant, createDefaultSignInExperience, createAdminTenantSignInExperience, createDefaultAdminConsoleApplication, createCloudApi, createTenantApplicationRole, CloudScope, Roles, UsersRoles, LogtoConfigs, SignInExperiences, Applications, OrganizationUserRelations, getTenantOrganizationId, Users, OrganizationRoleUserRelations, TenantRole, AccountCenters, } from '@logto/schemas';
|
|
4
4
|
import { getTenantRole } from '@logto/schemas';
|
|
5
|
-
import { createDefaultAccountCenter } from '@logto/schemas/lib/seeds/account-center.js';
|
|
5
|
+
import { createDefaultAccountCenter, createAdminTenantAccountCenter, } from '@logto/schemas/lib/seeds/account-center.js';
|
|
6
6
|
import { Tenants } from '@logto/schemas/models';
|
|
7
7
|
import { generateStandardId } from '@logto/shared';
|
|
8
8
|
import { sql } from '@silverhand/slonik';
|
|
@@ -116,7 +116,7 @@ export const seedTables = async (connection, latestTimestamp, isCloud) => {
|
|
|
116
116
|
connection.query(insertInto(createAdminTenantSignInExperience(), SignInExperiences.table)),
|
|
117
117
|
connection.query(insertInto(createDefaultAdminConsoleApplication(), Applications.table)),
|
|
118
118
|
connection.query(insertInto(createDefaultAccountCenter(defaultTenantId), AccountCenters.table)),
|
|
119
|
-
connection.query(insertInto(
|
|
119
|
+
connection.query(insertInto(createAdminTenantAccountCenter(), AccountCenters.table)),
|
|
120
120
|
]);
|
|
121
121
|
// The below seed data is for the Logto Cloud only. We put it here for the sake of simplicity.
|
|
122
122
|
// The data is not harmful for OSS, since they are all admin tenant data. OSS will not use them
|
package/lib/database.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { parseTimeoutEnv } from '@logto/shared';
|
|
2
|
+
import { assert, conditional } from '@silverhand/essentials';
|
|
2
3
|
import { createPool, parseDsn, sql, stringifyDsn, createInterceptorsPreset, } from '@silverhand/slonik';
|
|
3
4
|
import decamelize from 'decamelize';
|
|
4
5
|
import { DatabaseError } from 'pg-protocol';
|
|
5
6
|
import { convertToPrimitiveOrSql } from './sql.js';
|
|
6
7
|
import { ConfigKey, consoleLog, getCliConfigWithPrompt } from './utils.js';
|
|
8
|
+
const databaseStatementTimeout = parseTimeoutEnv(process.env.DATABASE_STATEMENT_TIMEOUT);
|
|
7
9
|
export const defaultDatabaseUrl = 'postgresql://localhost:5432/logto';
|
|
8
10
|
export const getDatabaseUrlFromConfig = async () => (await getCliConfigWithPrompt({
|
|
9
11
|
key: ConfigKey.DatabaseUrl,
|
|
@@ -15,6 +17,7 @@ export const createPoolFromConfig = async () => {
|
|
|
15
17
|
assert(parseDsn(databaseUrl).databaseName, new Error('Database name is required in URL'));
|
|
16
18
|
return createPool(databaseUrl, {
|
|
17
19
|
interceptors: createInterceptorsPreset(),
|
|
20
|
+
...conditional(databaseStatementTimeout !== undefined && { statementTimeout: databaseStatementTimeout }),
|
|
18
21
|
});
|
|
19
22
|
};
|
|
20
23
|
/**
|
|
@@ -41,6 +44,9 @@ export const createPoolAndDatabaseIfNeeded = async () => {
|
|
|
41
44
|
const databaseName = dsn.databaseName ?? '?';
|
|
42
45
|
const maintenancePool = await createPool(stringifyDsn({ ...dsn, databaseName: 'postgres' }), {
|
|
43
46
|
interceptors: createInterceptorsPreset(),
|
|
47
|
+
...(databaseStatementTimeout === undefined
|
|
48
|
+
? {}
|
|
49
|
+
: { statementTimeout: databaseStatementTimeout }),
|
|
44
50
|
});
|
|
45
51
|
await maintenancePool.query(sql `
|
|
46
52
|
create database ${sql.identifier([databaseName])}
|
package/lib/package-json.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export const packageJson = {
|
|
2
2
|
"name": "@logto/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.36.0",
|
|
4
4
|
"description": "Logto CLI.",
|
|
5
5
|
"author": "Silverhand Inc. <contact@silverhand.io>",
|
|
6
6
|
"homepage": "https://github.com/logto-io/logto#readme",
|
|
@@ -60,7 +60,7 @@ export const packageJson = {
|
|
|
60
60
|
"p-retry": "^6.0.0",
|
|
61
61
|
"pg-protocol": "^1.6.0",
|
|
62
62
|
"semver": "^7.3.8",
|
|
63
|
-
"tar": "^7.
|
|
63
|
+
"tar": "^7.5.4",
|
|
64
64
|
"yargs": "^17.6.0",
|
|
65
65
|
"zod": "3.24.3"
|
|
66
66
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logto/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.36.0",
|
|
4
4
|
"description": "Logto CLI.",
|
|
5
5
|
"author": "Silverhand Inc. <contact@silverhand.io>",
|
|
6
6
|
"homepage": "https://github.com/logto-io/logto#readme",
|
|
@@ -42,13 +42,13 @@
|
|
|
42
42
|
"p-retry": "^6.0.0",
|
|
43
43
|
"pg-protocol": "^1.6.0",
|
|
44
44
|
"semver": "^7.3.8",
|
|
45
|
-
"tar": "^7.
|
|
45
|
+
"tar": "^7.5.4",
|
|
46
46
|
"yargs": "^17.6.0",
|
|
47
47
|
"zod": "3.24.3",
|
|
48
|
-
"@logto/
|
|
49
|
-
"@logto/
|
|
50
|
-
"@logto/
|
|
51
|
-
"@logto/
|
|
48
|
+
"@logto/core-kit": "^2.7.0",
|
|
49
|
+
"@logto/schemas": "1.36.0",
|
|
50
|
+
"@logto/shared": "^3.3.1",
|
|
51
|
+
"@logto/connector-kit": "^4.7.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@silverhand/eslint-config": "6.0.1",
|