Skip to content

Commit d453b11

Browse files
committed
[remove] useless Batch mode of Import Script in new Migrator framework
[optimize] update Upstream packages
1 parent c476305 commit d453b11

File tree

7 files changed

+645
-579
lines changed

7 files changed

+645
-579
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"typescript.tsdk": "node_modules\\typescript\\lib"
3+
}

package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
"dependencies": {
1010
"@arshiash80/strapi-plugin-iconhub": "^1.1.1",
1111
"@ckeditor/strapi-plugin-ckeditor": "^1.1.1",
12-
"@strapi/plugin-cloud": "~5.23.6",
13-
"@strapi/plugin-color-picker": "~5.23.6",
14-
"@strapi/plugin-documentation": "~5.23.6",
15-
"@strapi/plugin-users-permissions": "~5.23.6",
16-
"@strapi/strapi": "~5.23.6",
17-
"better-sqlite3": "^12.2.0",
12+
"@strapi/plugin-cloud": "~5.24.1",
13+
"@strapi/plugin-color-picker": "~5.24.1",
14+
"@strapi/plugin-documentation": "~5.24.1",
15+
"@strapi/plugin-users-permissions": "~5.24.1",
16+
"@strapi/strapi": "~5.24.1",
17+
"better-sqlite3": "^12.4.1",
1818
"cross-env": "^10.0.0",
19-
"mobx-restful-migrator": "^0.1.0",
19+
"mobx-restful-migrator": "^0.1.1",
2020
"pg": "^8.16.3",
2121
"react": "^18.3.1",
2222
"react-dom": "^18.3.1",
@@ -33,16 +33,16 @@
3333
"@types/react-dom": "^18.3.7",
3434
"husky": "^9.1.7",
3535
"koajax": "^3.1.2",
36-
"lint-staged": "^16.1.6",
36+
"lint-staged": "^16.2.1",
3737
"mobx-restful": "^2.1.3",
3838
"mobx-strapi": "^0.8.1",
3939
"prettier": "^3.6.2",
40-
"swagger-typescript-api": "^13.2.13",
41-
"tsx": "^4.20.5",
40+
"swagger-typescript-api": "13.2.7",
41+
"tsx": "^4.20.6",
4242
"typescript": "~5.9.2",
4343
"web-utility": "^4.6.1",
4444
"xlsx": "^0.18.5",
45-
"zx": "^8.8.2"
45+
"zx": "^8.8.3"
4646
},
4747
"pnpm": {
4848
"onlyBuiltDependencies": [

pnpm-lock.yaml

Lines changed: 623 additions & 546 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/README.md

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ EXCEL_FILE=my-data.xlsx STRAPI_TOKEN=your_api_token tsx import-data.ts
128128
| `STRAPI_URL` | `http://localhost:1337` | Strapi 服务器地址 |
129129
| `STRAPI_TOKEN` | - | Strapi API Token(必填,除非 DRY_RUN) |
130130
| `EXCEL_FILE` | `教育公益开放式数据库.xlsx` | Excel 文件路径 |
131-
| `BATCH_SIZE` | `10` | 批量处理大小 |
132131
| `DRY_RUN` | `false` | 是否为模拟模式 |
133132

134133
### 命令行选项
@@ -207,13 +206,7 @@ tsx import-data.ts --dry-run
207206
DRY_RUN=true tsx import-data.ts
208207
```
209208

210-
2. **减少批次大小**
211-
212-
```bash
213-
BATCH_SIZE=1 STRAPI_TOKEN=your_token tsx import-data.ts
214-
```
215-
216-
3. **查看详细错误信息**
209+
2. **查看详细错误信息**
217210
- 脚本会输出详细的错误信息
218211
- 检查 Strapi 服务器日志
219212
- 查看 `logs/` 目录下自动生成的错误日志文件
@@ -234,9 +227,7 @@ tsx import-data.ts --dry-run
234227

235228
### 性能优化
236229

237-
1. 调整 `BATCH_SIZE` 参数
238-
2. 实现并行处理
239-
3. 添加数据缓存机制
230+
1. 添加数据缓存机制
240231

241232
## 日志文件
242233

scripts/import-data.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ const CONFIG: Config = {
1919
STRAPI_TOKEN: process.env.STRAPI_TOKEN || '',
2020
EXCEL_FILE: process.env.EXCEL_FILE || '教育公益开放式数据库.xlsx',
2121
SHEET_NAME: process.env.SHEET_NAME || null,
22-
BATCH_SIZE: parseInt(process.env.BATCH_SIZE || '10'),
23-
BATCH_DELAY: parseInt(process.env.BATCH_DELAY || '0'),
2422
DRY_RUN: process.env.DRY_RUN === 'true',
2523
MAX_ROWS: parseInt(process.env.MAX_ROWS || '0'),
2624
};
@@ -65,13 +63,14 @@ async function main(): Promise<void> {
6563
migrationMapping,
6664
logger,
6765
);
68-
6966
console.log('开始数据迁移...\n');
7067

7168
let count = 0;
72-
for await (const organization of migrator.boot()) {
69+
70+
for await (const organization of migrator.boot({
71+
dryRun: CONFIG.DRY_RUN,
72+
}))
7373
count++;
74-
}
7574

7675
// Print final statistics
7776
logger.printStats();
@@ -112,8 +111,6 @@ Strapi 数据导入工具
112111
STRAPI_TOKEN Strapi API Token
113112
EXCEL_FILE Excel 文件路径 (默认: 教育公益开放式数据库.xlsx)
114113
SHEET_NAME 工作表名称 (默认: 使用第一个工作表)
115-
BATCH_SIZE 批次大小 (默认: 10) - 由迁移框架自动处理
116-
BATCH_DELAY 批次间延迟秒数 (默认: 0) - 由迁移框架自动处理
117114
MAX_ROWS 最大处理行数 (默认: 0,表示全部)
118115
DRY_RUN 模拟运行 (true/false, 默认: false)
119116
VERBOSE_LOGGING 详细日志 (true/false, 默认: false)

scripts/types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ export interface Config {
1515
STRAPI_TOKEN: string;
1616
EXCEL_FILE: string;
1717
SHEET_NAME: string | null;
18-
BATCH_SIZE: number;
19-
BATCH_DELAY: number;
2018
DRY_RUN: boolean;
2119
MAX_ROWS: number;
2220
}

scripts/utils/strapi-api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { StrapiListModel, UserModel } from 'mobx-strapi';
44

55
import { TargetOrganization, TargetUser } from '../types';
66

7-
const { STRAPI_API_URL, STRAPI_TOKEN } = process.env;
7+
const { STRAPI_URL = 'http://localhost:1337', STRAPI_TOKEN } = process.env;
88

99
export const strapiClient = new HTTPClient({
10-
baseURI: new URL('api/', STRAPI_API_URL) + '',
10+
baseURI: new URL('api/', STRAPI_URL) + '',
1111
responseType: 'json',
1212
}).use(({ request }, next) => {
1313
request.headers = {

0 commit comments

Comments
 (0)