fix: bricks dist mkdir+产物校验;种子脚本(机构/角色/权限/超管);rbac/appbase软链;config database→db

This commit is contained in:
agent.develop 2026-08-28 17:01:01 +08:00
parent 604cffd897
commit 4b183aa7fc
3 changed files with 68 additions and 3 deletions

View File

@ -66,18 +66,24 @@ for m in ${FOUNDATION_PKGS} ${BUSINESS_MODULES}; do
done
echo "==> [3/9] bricks frontend build + symlink"
# dist/ 不入 gitgitignoreclone 后必须本地构建;内层 build.sh 用 cat 拼接,无需 node
mkdir -p pkgs/bricks/dist
if [ ! -f "pkgs/bricks/dist/bricks.js" ]; then
(cd pkgs/bricks/bricks && bash build.sh) || { echo "ERROR: bricks build failed" >&2; exit 1; }
fi
[ -s "pkgs/bricks/dist/bricks.js" ] || { echo "ERROR: bricks.js missing/empty after build" >&2; exit 1; }
mkdir -p wwwroot
ln -sfn "../pkgs/bricks/dist" "wwwroot/bricks"
echo "==> [4/9] database + foundation/initial tables"
echo "==> [4/9] database + foundation/initial tables + seed"
mysql -h "${DB_HOST}" -P "${DB_PORT}" -u "${DB_USER}" -p"${DB_PASSWORD}" \
-e "CREATE DATABASE IF NOT EXISTS ${DB_NAME} CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci" \
|| { echo "ERROR: create database failed" >&2; exit 1; }
mysql -h "${DB_HOST}" -P "${DB_PORT}" -u "${DB_USER}" -p"${DB_PASSWORD}" "${DB_NAME}" \
< "${APP_SRC_DIR}/scripts/ddl.sql" || { echo "ERROR: ddl.sql failed" >&2; exit 1; }
# 种子:默认机构/角色/权限/超管(全新库无此数据则一切请求 401
mysql -h "${DB_HOST}" -P "${DB_PORT}" -u "${DB_USER}" -p"${DB_PASSWORD}" "${DB_NAME}" \
< "${APP_SRC_DIR}/scripts/seed.sql" || { echo "ERROR: seed.sql failed" >&2; exit 1; }
echo "==> [5/9] i18n merge"
mkdir -p wwwroot/i18n/zh wwwroot/i18n/en
@ -119,6 +125,12 @@ for m in ${BUSINESS_MODULES}; do
|| { echo "ERROR: ${m} dbloader failed" >&2; exit 1; }
fi
done
# 基础模块的 wwwroot 也要软链rbac 登录页、appbase 页面),否则登录页 404
for m in appbase rbac; do
if [ -d "pkgs/${m}/wwwroot" ]; then
ln -sfn "../pkgs/${m}/wwwroot" "wwwroot/${m}"
fi
done
echo "==> [7/9] sync app code + runtime dirs"
for d in app conf scripts wwwroot; do

View File

@ -19,8 +19,8 @@
"port": 3306,
"user": "test",
"password": "Kj2wTl+LYpPtDSk3B01U7w==",
"database": "scense",
"charset": "utf8mb4"
"charset": "utf8mb4",
"db": "scense"
}
}
},

53
scripts/seed.sql Normal file
View File

@ -0,0 +1,53 @@
-- =============================================================================
-- scense 初始化种子数据(全新库必备)
-- ddl.sql 只建表结构;本脚本种入:默认机构 / 角色 / 权限 / 超管。
-- 幂等:全部 INSERT IGNORE重跑不重复。
-- =============================================================================
USE scense;
-- ── 默认机构平台自身org_type=owner──
INSERT IGNORE INTO organization (id, orgname, alias_name, org_type, parentid, del_flg)
VALUES ('0', '唤景平台', 'scense', 'owner', NULL, '0');
-- ── 内置角色 ──
-- any/anonymous匿名访问logined登录态owner.superuser超级管理员
INSERT IGNORE INTO role (id, orgtypeid, role, rolelabel, name) VALUES
('any', '0', 'any', 'Anonymous', 'any'),
('anonymous', '0', NULL, NULL, NULL),
('logined', '0', NULL, NULL, NULL),
('owner.superuser','0', 'superuser', '超级管理员', 'superuser');
-- ── 权限permission──
-- any健康检查 + 登录页所需静态资源/登录端点(否则连登录页都打不开)
-- owner.superuser/** 全放行
INSERT IGNORE INTO permission (id, name, ptype, path, title) VALUES
('perm-healthz', 'healthz', 'url', '/healthz', '健康检查'),
('perm-any-bricks', 'bricks', 'url', '/bricks/**', 'bricks 前端资源'),
('perm-any-i18n', 'i18n', 'url', '/i18n/**', 'i18n 资源'),
('perm-any-index', 'index', 'url', '/index.ui', '入口页'),
('perm-any-root', 'root', 'url', '/', '根路径'),
('perm-any-uplogin', 'up_login', 'url', '/rbac/user/up_login.dspy','账号密码登录'),
('perm-any-loginui', 'login_ui', 'url', '/rbac/user/login.ui', '登录页'),
('perm-super-all', 'all', 'url', '/**', '超级管理员全放行');
-- ── 角色-权限绑定rolepermission──
INSERT IGNORE INTO rolepermission (id, roleid, permid) VALUES
('rp-healthz', 'any', 'perm-healthz'),
('rp-any-bricks', 'any', 'perm-any-bricks'),
('rp-any-i18n', 'any', 'perm-any-i18n'),
('rp-any-index', 'any', 'perm-any-index'),
('rp-any-root', 'any', 'perm-any-root'),
('rp-any-uplogin', 'any', 'perm-any-uplogin'),
('rp-any-loginui', 'any', 'perm-any-loginui'),
('rp-super-all', 'owner.superuser', 'perm-super-all');
-- ── 超级管理员 ──
-- 密码 Aa@123456经 password_encode(rc4, key=scense_test_env_key) 加密
INSERT IGNORE INTO users (id, username, password, orgid, nick_name, user_status)
VALUES ('user-01', 'admin', 'QUZVcXg5V1p1STMybG5Ia2/sxzz9580bgw==', '0', 'Admin', '0');
INSERT IGNORE INTO userrole (id, userid, roleid) VALUES
('ur-admin-super', 'user-01', 'owner.superuser');
-- 提交(防 MDL 锁阻塞后续 DDL
COMMIT;