@logto/cli 1.34.0 → 1.35.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
|
};
|
package/lib/package-json.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logto/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.35.0",
|
|
4
4
|
"description": "Logto CLI.",
|
|
5
5
|
"author": "Silverhand Inc. <contact@silverhand.io>",
|
|
6
6
|
"homepage": "https://github.com/logto-io/logto#readme",
|
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
"tar": "^7.0.0",
|
|
46
46
|
"yargs": "^17.6.0",
|
|
47
47
|
"zod": "3.24.3",
|
|
48
|
-
"@logto/connector-kit": "^4.
|
|
49
|
-
"@logto/
|
|
50
|
-
"@logto/
|
|
51
|
-
"@logto/
|
|
48
|
+
"@logto/connector-kit": "^4.7.0",
|
|
49
|
+
"@logto/schemas": "1.35.0",
|
|
50
|
+
"@logto/shared": "^3.3.0",
|
|
51
|
+
"@logto/core-kit": "^2.6.1"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@silverhand/eslint-config": "6.0.1",
|