add-store-district-isdeleted.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /**
  2. * 为 Store 和 District 表添加 isDeleted(Boolean) 字段
  3. *
  4. * 用法: cd backend && npx tsx scripts/add-store-district-isdeleted.ts
  5. */
  6. import 'dotenv/config';
  7. import Parse from '../src/db/parse-client.js';
  8. async function main(): Promise<void> {
  9. console.log('=== 为 Store 和 District 添加 isDeleted 字段 ===');
  10. console.log(`Server: ${Parse.serverURL}`);
  11. console.log(`App ID: ${Parse.applicationId}\n`);
  12. try {
  13. const n = await new Parse.Query('_User').count({ useMasterKey: true });
  14. console.log(`✅ Parse 连接正常 (_User: ${n} 条)\n`);
  15. } catch (err: any) {
  16. console.error(`❌ Parse 连接失败: ${err.message}`);
  17. process.exit(1);
  18. }
  19. for (const tableName of ['Store', 'District']) {
  20. const schema = new Parse.Schema(tableName);
  21. try {
  22. await schema.addField('isDeleted', 'Boolean');
  23. await schema.update({ useMasterKey: true });
  24. console.log(`+ ${tableName}.isDeleted (Boolean) 字段已添加`);
  25. } catch (err: any) {
  26. if (err.message?.includes('already')) {
  27. console.log(`~ ${tableName}.isDeleted 字段已存在,无需添加`);
  28. } else {
  29. console.warn(`⚠ ${tableName} isDeleted 添加失败: ${err.message}`);
  30. }
  31. }
  32. }
  33. console.log('\n=== 完成 ===');
  34. }
  35. main().catch((err) => {
  36. console.error('失败:', err.message);
  37. process.exit(1);
  38. });