2023-02-01 17:19:27 +08:00
|
|
|
package migrations
|
|
|
|
|
|
|
|
import (
|
2023-07-13 16:16:13 +08:00
|
|
|
"context"
|
2023-02-01 17:19:27 +08:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/answerdev/answer/internal/entity"
|
|
|
|
"github.com/segmentfault/pacman/log"
|
|
|
|
"xorm.io/xorm"
|
|
|
|
)
|
|
|
|
|
2023-07-13 16:16:13 +08:00
|
|
|
func addPlugin(ctx context.Context, x *xorm.Engine) error {
|
2023-02-01 17:19:27 +08:00
|
|
|
defaultConfigTable := []*entity.Config{
|
|
|
|
{ID: 118, Key: "plugin.status", Value: `{}`},
|
|
|
|
}
|
|
|
|
for _, c := range defaultConfigTable {
|
2023-07-13 16:16:13 +08:00
|
|
|
exist, err := x.Context(ctx).Get(&entity.Config{ID: c.ID, Key: c.Key})
|
2023-02-01 17:19:27 +08:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("get config failed: %w", err)
|
|
|
|
}
|
|
|
|
if exist {
|
|
|
|
continue
|
|
|
|
}
|
2023-07-13 16:16:13 +08:00
|
|
|
if _, err = x.Context(ctx).Insert(&entity.Config{ID: c.ID, Key: c.Key, Value: c.Value}); err != nil {
|
2023-02-01 17:19:27 +08:00
|
|
|
log.Errorf("insert %+v config failed: %s", c, err)
|
|
|
|
return fmt.Errorf("add config failed: %w", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-13 16:16:13 +08:00
|
|
|
return x.Context(ctx).Sync(new(entity.PluginConfig), new(entity.UserExternalLogin))
|
2023-02-01 17:19:27 +08:00
|
|
|
}
|