| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- /**
- * 为 _User 表添加 isDeleted(Boolean) 字段
- *
- * 用法: cd backend && npx tsx scripts/add-user-isdeleted.ts
- */
- import 'dotenv/config';
- import Parse from '../src/db/parse-client.js';
- async function main(): Promise<void> {
- console.log('=== 为 _User 添加 isDeleted 字段 ===');
- console.log(`Server: ${Parse.serverURL}`);
- console.log(`App ID: ${Parse.applicationId}\n`);
- try {
- const n = await new Parse.Query('_User').count({ useMasterKey: true });
- console.log(`✅ Parse 连接正常 (_User: ${n} 条)\n`);
- } catch (err: any) {
- console.error(`❌ Parse 连接失败: ${err.message}`);
- process.exit(1);
- }
- const schema = new Parse.Schema('_User');
- try {
- await schema.addField('isDeleted', 'Boolean');
- console.log('+ isDeleted (Boolean) 字段已添加');
- } catch (err: any) {
- if (err.message?.includes('already')) {
- console.log('~ isDeleted 字段已存在,无需添加');
- } else {
- console.warn(`⚠ isDeleted 添加失败: ${err.message}`);
- }
- }
- await schema.update({ useMasterKey: true });
- console.log('\n=== 完成 ===');
- }
- main().catch((err) => {
- console.error('失败:', err.message);
- process.exit(1);
- });
|