Files
PartsInquiry/backend/db/init_minimal.sql
2025-10-08 19:15:20 +08:00

56 lines
2.1 KiB
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 最小可运行初始化脚本
-- 说明与后端默认上下文保持一致shopId=1, userId=2并创建管理员账号
-- 使用前:请将占位符 <ADMIN_BCRYPT_HASH> 替换为你生成的 BCrypt 哈希
START TRANSACTION;
-- 1) 店铺shopsid=1
INSERT INTO shops (id, name, status, created_at)
VALUES (1, '默认店铺', 1, NOW())
ON DUPLICATE KEY UPDATE
name=VALUES(name), status=VALUES(status);
-- 2) 店主用户usersid=2归属 shop_id=1
-- 说明phone/email 可按需修改;请确保满足唯一约束
INSERT INTO users (
id, shop_id, phone, email, name, role, password_hash, status, is_owner, created_at
) VALUES
(2, 1, '19900000000', NULL, '店主', 'owner', NULL, 1, 1, NOW())
ON DUPLICATE KEY UPDATE
shop_id=VALUES(shop_id),
name=VALUES(name),
role=VALUES(role),
status=VALUES(status),
is_owner=VALUES(is_owner);
-- 3) 计量单位product_units至少 1 条(示例:个)
INSERT INTO product_units (shop_id, user_id, name, created_at)
VALUES (1, 2, '', NOW())
ON DUPLICATE KEY UPDATE
name=VALUES(name);
-- 4) 商品分类product_categories至少 1 条(示例:默认分类)
INSERT INTO product_categories (shop_id, user_id, name, parent_id, sort_order, created_at)
VALUES (1, 2, '默认分类', NULL, 0, NOW())
ON DUPLICATE KEY UPDATE
name=VALUES(name);
-- 5) 管理员账号admins用于管理员端登录用户名与手机号二选一即可
-- 必须提供 BCrypt 哈希,否则登录会报 NO_PASSWORD
-- 将 <ADMIN_BCRYPT_HASH> 替换为你生成的哈希(例如明文口令 Admin@12345 对应的哈希)
INSERT INTO admins (username, phone, password_hash, status, created_at)
VALUES ('admin', '13800000000', '<ADMIN_BCRYPT_HASH>', 1, NOW())
ON DUPLICATE KEY UPDATE
password_hash=VALUES(password_hash),
status=VALUES(status);
COMMIT;
-- 验证建议:
-- 1) 后端默认上下文可用shop_id=1, user_id=2
-- 2) 管理员可用:使用 username=admin 或 phone=13800000000 + 明文口令(与哈希对应)
-- 3) 商品录入不报“缺少单位/分类”