Files
SupplierSystem/scripts/prod-fix-auth-users.sh
T
Ubuntu deb3e72750
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s
chore: 以 AI 生鲜配送系统 当前版本作为 SupplierSystem 起点
来源仓库:jxc/ai-fresh-delivery
来源提交:f0b1a180e2deb7e4673b9d1c8542619f7bc0f73d
快照树:  09f679334ff38f0ff25e907961c94a8223bcaedd(与来源 HEAD 工作树逐字节一致,3801 个文件)

按约定本仓库不带任何历史提交:来源仓库的历史中含真实凭据
(生产 SSH 私钥 deploy/id_rsa_tencent、server/.env、.env.tencent/.env.production/.env.gitea、
deploy/小程序AppSecret.txt,其中 MP_APPSECRET / S3 AccessKey 经哈希比对与线上同值),
整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。
供应商系统后续开发自本提交开始。
2026-10-08 17:35:43 +08:00

141 lines
2.7 KiB
Bash

#!/bin/bash
set -euo pipefail
cd /opt/ai-fresh-delivery/server
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=prod-load-env.sh
source "$SCRIPT_DIR/prod-load-env.sh"
echo "===== fix auth.users columns ====="
psql "$DATABASE_URL" -f /opt/ai-fresh-delivery/migrations/20260607_fix_auth_users_columns.sql
echo "===== upsert superadmin (bcrypt) ====="
node <<'NODE'
const bcrypt = require('bcryptjs');
const { Pool } = require('pg');
(async () => {
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
const hash = await bcrypt.hash(process.env.SUPERADMIN_PASSWORD || (() => { throw new Error('SUPERADMIN_PASSWORD required'); })(), 10);
await pool.query(
`INSERT INTO auth.users (
instance_id, id, aud, role, email, encrypted_password, email_confirmed_at,
raw_app_meta_data, raw_user_meta_data, is_super_admin
) VALUES (
'00000000-0000-0000-0000-000000000000',
'a0000000-0000-0000-0000-000000000001',
'authenticated', 'authenticated', 'superadmin@meoo.local',
$1, NOW(),
'{"provider":"email","providers":["email"]}'::jsonb,
'{"username":"superadmin","full_name":"超级管理员"}'::jsonb,
true
)
ON CONFLICT (email) DO UPDATE SET encrypted_password = EXCLUDED.encrypted_password`,
[hash]
);
const adminHash = await bcrypt.hash('Admin@123', 10);
await pool.query(
`UPDATE auth.users SET encrypted_password = $1 WHERE email = 'admin@meoo.local'`,
[adminHash]
);
await pool.end();
console.log('superadmin + admin passwords updated');
})();
NODE
echo "===== fix superadmin profile & role ====="
psql "$DATABASE_URL" -c "
INSERT INTO profiles (id, username, full_name, status)
VALUES ('a0000000-0000-0000-0000-000000000001', 'superadmin', '超级管理员', 1)
ON CONFLICT (id) DO UPDATE SET username = EXCLUDED.username, full_name = EXCLUDED.full_name, status = 1;
INSERT INTO user_roles (user_id, role)
VALUES ('a0000000-0000-0000-0000-000000000001', 'super_admin')
ON CONFLICT DO NOTHING;
"
echo "===== migrate (remaining) ====="
export MIGRATIONS_DIR=/opt/ai-fresh-delivery/migrations
node migrate.js || true
echo "===== restart api ====="
sudo systemctl restart ai-fresh-api
sleep 2
echo "===== login verify ====="
curl -sS -m 8 -X POST http://127.0.0.1:3001/api/auth/token \
-H 'Content-Type: application/json' \
-d "$(printf '{"email":"%s","password":"%s"}' "superadmin@meoo.local" "$SUPERADMIN_PASSWORD")"
echo
curl -sS -m 8 -X POST http://127.0.0.1/api/auth/token \
-H 'Content-Type: application/json' \
-d "$(printf '{"email":"%s","password":"%s"}' "superadmin@meoo.local" "$SUPERADMIN_PASSWORD")"
echo