Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

feat(migrations): add default login site info config

LinkinStarf7869b15bddb
diff --git a/internal/migrations/init.go b/internal/migrations/init.go
index 397a94ae..86f7e60c 100644
--- a/internal/migrations/init.go
+++ b/internal/migrations/init.go
@@ -116,6 +116,17 @@ func initSiteInfo(engine *xorm.Engine, language, siteName, siteURL, contactEmail
Content: string(generalDataBytes),
Status: 1,
})
+
+ loginConfig := map[string]bool{
+ "allow_new_registrations": true,
+ "login_required": false,
+ }
+ loginConfigDataBytes, _ := json.Marshal(loginConfig)
+ _, err = engine.InsertOne(&entity.SiteInfo{
+ Type: "login",
+ Content: string(loginConfigDataBytes),
+ Status: 1,
+ })
return err
}
diff --git a/internal/migrations/v5.go b/internal/migrations/v5.go
index 6bae0353..fc4b057a 100644
--- a/internal/migrations/v5.go
+++ b/internal/migrations/v5.go
@@ -2,6 +2,7 @@ package migrations
import (
"encoding/json"
+ "fmt"
"github.com/answerdev/answer/internal/entity"
"xorm.io/xorm"
@@ -13,10 +14,17 @@ func addThemeAndPrivateMode(x *xorm.Engine) error {
"login_required": false,
}
loginConfigDataBytes, _ := json.Marshal(loginConfig)
- _, err := x.InsertOne(&entity.SiteInfo{
+ siteInfo := &entity.SiteInfo{
Type: "login",
Content: string(loginConfigDataBytes),
Status: 1,
- })
+ }
+ exist, err := x.Get(&entity.SiteInfo{Type: siteInfo.Type})
+ if err != nil {
+ return fmt.Errorf("get config failed: %w", err)
+ }
+ if !exist {
+ _, err = x.InsertOne(siteInfo)
+ }
return err
}