Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5725e84971 | |||
| 86baaf3a1c | |||
| fcf92675b1 | |||
| d81b2d1fac |
@@ -33,6 +33,21 @@ jobs:
|
|||||||
SHOPS: ${{ github.event.inputs.shops }}
|
SHOPS: ${{ github.event.inputs.shops }}
|
||||||
CLEAR: ${{ github.event.inputs.clear }}
|
CLEAR: ${{ github.event.inputs.clear }}
|
||||||
run: |
|
run: |
|
||||||
|
# 第一步:若需要清空,先把所有门店都清掉再写入
|
||||||
|
# 避免 S001(id=1 硬编码) 因 S002 占用 id=1 而被 INSERT IGNORE 跳过
|
||||||
|
if [ "$CLEAR" = "true" ]; then
|
||||||
|
echo "=== 清空阶段 ==="
|
||||||
|
for SHOP in $(echo "$SHOPS" | tr ',' ' '); do
|
||||||
|
echo " 清空 ${SHOP}..."
|
||||||
|
printf "SET @shop_code='%s';\n" "$SHOP" | cat - backend/seeds/clear_shop.sql | \
|
||||||
|
ssh -i ~/.ssh/ec2_deploy.pem ${EC2_USER}@${EC2_HOST} \
|
||||||
|
"docker exec -i jiu_mysql mysql -uroot -p${DB_PASSWORD} --default-character-set=utf8mb4 jiu_db"
|
||||||
|
done
|
||||||
|
echo "✓ 清空完成"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 第二步:依次写入所有门店
|
||||||
|
echo "=== 写入阶段 ==="
|
||||||
for SHOP in $(echo "$SHOPS" | tr ',' ' '); do
|
for SHOP in $(echo "$SHOPS" | tr ',' ' '); do
|
||||||
FILE="backend/seeds/${SHOP}.sql"
|
FILE="backend/seeds/${SHOP}.sql"
|
||||||
if [ ! -f "$FILE" ]; then
|
if [ ! -f "$FILE" ]; then
|
||||||
@@ -40,12 +55,6 @@ jobs:
|
|||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
echo "→ Seeding $SHOP ..."
|
echo "→ Seeding $SHOP ..."
|
||||||
if [ "$CLEAR" = "true" ]; then
|
|
||||||
echo " 清空 ${SHOP} 数据..."
|
|
||||||
printf "SET @shop_code='%s';\n" "$SHOP" | cat - backend/seeds/clear_shop.sql | \
|
|
||||||
ssh -i ~/.ssh/ec2_deploy.pem ${EC2_USER}@${EC2_HOST} \
|
|
||||||
"docker exec -i jiu_mysql mysql -uroot -p${DB_PASSWORD} --default-character-set=utf8mb4 jiu_db"
|
|
||||||
fi
|
|
||||||
ssh -i ~/.ssh/ec2_deploy.pem ${EC2_USER}@${EC2_HOST} \
|
ssh -i ~/.ssh/ec2_deploy.pem ${EC2_USER}@${EC2_HOST} \
|
||||||
"docker exec -i jiu_mysql mysql -uroot -p${DB_PASSWORD} --default-character-set=utf8mb4 jiu_db" \
|
"docker exec -i jiu_mysql mysql -uroot -p${DB_PASSWORD} --default-character-set=utf8mb4 jiu_db" \
|
||||||
< "$FILE"
|
< "$FILE"
|
||||||
|
|||||||
@@ -132,21 +132,21 @@ func main() {
|
|||||||
hash := mustHash("password123")
|
hash := mustHash("password123")
|
||||||
admin := upsert(db, &model.User{}, "shop_id = ? AND username = ?", shop.ID, "admin", func() any {
|
admin := upsert(db, &model.User{}, "shop_id = ? AND username = ?", shop.ID, "admin", func() any {
|
||||||
return &model.User{
|
return &model.User{
|
||||||
TenantBase: model.TenantBase{ShopID: shop.ID},
|
ShopID: shop.ID,
|
||||||
Username: "admin", PasswordHash: hash, RealName: "张三(管理员)",
|
Username: "admin", PasswordHash: hash, RealName: "张三(管理员)",
|
||||||
Phone: "13800000001", Role: "admin", IsActive: true,
|
Phone: "13800000001", Role: "admin", IsActive: true,
|
||||||
}
|
}
|
||||||
}).(model.User)
|
}).(model.User)
|
||||||
operator := upsert(db, &model.User{}, "shop_id = ? AND username = ?", shop.ID, "operator", func() any {
|
operator := upsert(db, &model.User{}, "shop_id = ? AND username = ?", shop.ID, "operator", func() any {
|
||||||
return &model.User{
|
return &model.User{
|
||||||
TenantBase: model.TenantBase{ShopID: shop.ID},
|
ShopID: shop.ID,
|
||||||
Username: "operator", PasswordHash: hash, RealName: "李四(操作员)",
|
Username: "operator", PasswordHash: hash, RealName: "李四(操作员)",
|
||||||
Phone: "13800000002", Role: "operator", IsActive: true,
|
Phone: "13800000002", Role: "operator", IsActive: true,
|
||||||
}
|
}
|
||||||
}).(model.User)
|
}).(model.User)
|
||||||
upsert(db, &model.User{}, "shop_id = ? AND username = ?", shop.ID, "test", func() any {
|
upsert(db, &model.User{}, "shop_id = ? AND username = ?", shop.ID, "test", func() any {
|
||||||
return &model.User{
|
return &model.User{
|
||||||
TenantBase: model.TenantBase{ShopID: shop.ID},
|
ShopID: shop.ID,
|
||||||
Username: "test", PasswordHash: hash, RealName: "王五(只读)",
|
Username: "test", PasswordHash: hash, RealName: "王五(只读)",
|
||||||
Phone: "13800000003", Role: "readonly", IsActive: true,
|
Phone: "13800000003", Role: "readonly", IsActive: true,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ func (h *UserHandler) Create(c *gin.Context) {
|
|||||||
role = "operator"
|
role = "operator"
|
||||||
}
|
}
|
||||||
u := model.User{
|
u := model.User{
|
||||||
TenantBase: model.TenantBase{ShopID: shopID},
|
ShopID: shopID,
|
||||||
Username: req.Username,
|
Username: req.Username,
|
||||||
PasswordHash: string(hash),
|
PasswordHash: string(hash),
|
||||||
RealName: req.RealName,
|
RealName: req.RealName,
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
TenantBase
|
Base
|
||||||
|
ShopID uint64 `gorm:"not null;index;uniqueIndex:uk_shop_username" json:"shop_id"`
|
||||||
Username string `gorm:"size:50;uniqueIndex:uk_shop_username" json:"username"`
|
Username string `gorm:"size:50;uniqueIndex:uk_shop_username" json:"username"`
|
||||||
PasswordHash string `gorm:"size:255" json:"-"`
|
PasswordHash string `gorm:"size:255" json:"-"`
|
||||||
RealName string `gorm:"size:50" json:"real_name"`
|
RealName string `gorm:"size:50" json:"real_name"`
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
-- 或由脚本拼接:
|
-- 或由脚本拼接:
|
||||||
-- echo "SET @shop_code='S001';" | cat - clear_shop.sql | mysql ...
|
-- echo "SET @shop_code='S001';" | cat - clear_shop.sql | mysql ...
|
||||||
|
|
||||||
SET @sid = (SELECT id FROM shops WHERE code = @shop_code LIMIT 1);
|
SET @sid = (SELECT id FROM shops WHERE BINARY code = BINARY @shop_code LIMIT 1);
|
||||||
|
|
||||||
SET FOREIGN_KEY_CHECKS = 0;
|
SET FOREIGN_KEY_CHECKS = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -349,10 +349,7 @@ func hashPassword(plain string) string {
|
|||||||
func CreateTestUser(db *gorm.DB, shopID uint64, username, password, role string) *model.User {
|
func CreateTestUser(db *gorm.DB, shopID uint64, username, password, role string) *model.User {
|
||||||
hash := hashPassword(password)
|
hash := hashPassword(password)
|
||||||
user := &model.User{
|
user := &model.User{
|
||||||
TenantBase: model.TenantBase{
|
ShopID: shopID,
|
||||||
Base: model.Base{},
|
|
||||||
ShopID: shopID,
|
|
||||||
},
|
|
||||||
Username: username,
|
Username: username,
|
||||||
PasswordHash: hash,
|
PasswordHash: hash,
|
||||||
RealName: "Test User " + username,
|
RealName: "Test User " + username,
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ server {
|
|||||||
ssl_protocols TLSv1.2 TLSv1.3;
|
ssl_protocols TLSv1.2 TLSv1.3;
|
||||||
ssl_ciphers HIGH:!aNULL:!MD5;
|
ssl_ciphers HIGH:!aNULL:!MD5;
|
||||||
|
|
||||||
|
client_max_body_size 20m;
|
||||||
|
|
||||||
# 商品图片静态文件
|
# 商品图片静态文件
|
||||||
location ^~ /images/ {
|
location ^~ /images/ {
|
||||||
alias /opt/jiu/images/;
|
alias /opt/jiu/images/;
|
||||||
|
|||||||
Reference in New Issue
Block a user