#!/bin/bash # 创建华东分公司演示管理员(BR002),用于验证订单隔离 set -euo pipefail cd /opt/ai-fresh-delivery/server node <<'NODE' const { Pool } = require('pg'); const bcrypt = require('bcryptjs'); require('dotenv').config(); (async () => { const pool = new Pool({ connectionString: process.env.DATABASE_URL }); const email = 'branchadmin@meoo.local'; const username = 'branchadmin'; const password = 'BranchAdmin@123'; const branchCode = 'BR002'; const existing = await pool.query('SELECT id FROM auth.users WHERE email = $1', [email]); let userId = existing.rows[0]?.id; if (!userId) { userId = 'b0000000-0000-0000-0000-000000000002'; const hash = await bcrypt.hash(password, 10); await pool.query( `INSERT INTO auth.users (id, email, encrypted_password, email_confirmed_at, created_at, updated_at) VALUES ($1, $2, $3, NOW(), NOW(), NOW()) ON CONFLICT (id) DO NOTHING`, [userId, email, hash] ); } else { const hash = await bcrypt.hash(password, 10); await pool.query('UPDATE auth.users SET encrypted_password = $1 WHERE id = $2', [hash, userId]); } await pool.query( `INSERT INTO profiles (id, username, full_name, branch_code, status) VALUES ($1, $2, '华东分公司管理员', $3, 1) ON CONFLICT (id) DO UPDATE SET username = EXCLUDED.username, full_name = EXCLUDED.full_name, branch_code = EXCLUDED.branch_code, status = EXCLUDED.status`, [userId, username, branchCode] ); await pool.query(`DELETE FROM user_roles WHERE user_id = $1`, [userId]); await pool.query(`INSERT INTO user_roles (user_id, role) VALUES ($1, 'admin')`, [userId]); console.log('Branch admin ready:', { email, username, password, branchCode, userId }); await pool.end(); })().catch((e) => { console.error(e); process.exit(1); }); NODE