| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- /**
- * 为 Store 和 District 表添加 isDeleted(Boolean) 字段
- *
- * 用法: cd backend && npx tsx scripts/add-store-district-isdeleted.ts
- */
- import 'dotenv/config';
- import Parse from '../src/db/parse-client.js';
- async function main(): Promise<void> {
- console.log('=== 为 Store 和 District 添加 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);
- }
- for (const tableName of ['Store', 'District']) {
- const schema = new Parse.Schema(tableName);
- try {
- await schema.addField('isDeleted', 'Boolean');
- await schema.update({ useMasterKey: true });
- console.log(`+ ${tableName}.isDeleted (Boolean) 字段已添加`);
- } catch (err: any) {
- if (err.message?.includes('already')) {
- console.log(`~ ${tableName}.isDeleted 字段已存在,无需添加`);
- } else {
- console.warn(`⚠ ${tableName} isDeleted 添加失败: ${err.message}`);
- }
- }
- }
- console.log('\n=== 完成 ===');
- }
- main().catch((err) => {
- console.error('失败:', err.message);
- process.exit(1);
- });
|