36 lines
918 B
Go
36 lines
918 B
Go
package base
|
|
|
|
import (
|
|
"context"
|
|
"entgo.io/ent/dialect/sql/schema"
|
|
"github.com/saas-mingyang/mingyang-admin-common/msg/logmsg"
|
|
"github.com/zeromicro/go-zero/core/errorx"
|
|
|
|
"mingyang-admin-app-rpc/internal/svc"
|
|
"mingyang-admin-app-rpc/types/app"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type InitDatabaseLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewInitDatabaseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InitDatabaseLogic {
|
|
return &InitDatabaseLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *InitDatabaseLogic) InitDatabase(in *app.Empty) (*app.BaseResp, error) {
|
|
if err := l.svcCtx.DB.Schema.Create(l.ctx, schema.WithForeignKeys(false)); err != nil {
|
|
logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error()))
|
|
return nil, errorx.NewInternalError(err.Error())
|
|
}
|
|
return &app.BaseResp{}, nil
|
|
}
|