Skip to content

Commit

Permalink
fix: allow to alter table structure
Browse files Browse the repository at this point in the history
  • Loading branch information
suyuan32 committed Dec 29, 2022
1 parent 1581cc8 commit d07abeb
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions rpc/internal/logic/base/init_database_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ func (l *InitDatabaseLogic) InitDatabase(in *core.Empty) (*core.BaseResp, error)
lock.Release()
}()

// initialize table structure
if err := l.svcCtx.DB.Schema.Create(l.ctx, schema.WithForeignKeys(false), schema.WithDropColumn(true),
schema.WithDropIndex(true)); err != nil {
logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error()))
l.svcCtx.Redis.Setex("database_error_msg", err.Error(), 300)
return nil, statuserr.NewInternalError(err.Error())
}

// judge if the initialization had been done
check, err := l.svcCtx.DB.API.Query().Count(l.ctx)

Expand All @@ -70,13 +78,6 @@ func (l *InitDatabaseLogic) InitDatabase(in *core.Empty) (*core.BaseResp, error)
l.svcCtx.Redis.Setex("database_error_msg", "", 300)
l.svcCtx.Redis.Setex("database_init_state", "0", 300)

// initialize table structure
if err := l.svcCtx.DB.Schema.Create(l.ctx, schema.WithForeignKeys(false)); err != nil {
logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error()))
l.svcCtx.Redis.Setex("database_error_msg", err.Error(), 300)
return nil, statuserr.NewInternalError(err.Error())
}

err = l.insertUserData()
if err != nil {
logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error()))
Expand Down

0 comments on commit d07abeb

Please sign in to comment.