mirror of
https://github.com/ergochat/ergo.git
synced 2024-12-22 18:52:41 +01:00
schema change for #1274
This commit is contained in:
parent
1f6afa31d6
commit
4296ff02a4
@ -24,7 +24,7 @@ const (
|
|||||||
// 'version' of the database schema
|
// 'version' of the database schema
|
||||||
keySchemaVersion = "db.version"
|
keySchemaVersion = "db.version"
|
||||||
// latest schema of the db
|
// latest schema of the db
|
||||||
latestDbSchema = 17
|
latestDbSchema = 18
|
||||||
|
|
||||||
keyCloakSecret = "crypto.cloak_secret"
|
keyCloakSecret = "crypto.cloak_secret"
|
||||||
)
|
)
|
||||||
@ -854,6 +854,55 @@ func schemaChangeV16ToV17(config *Config, tx *buntdb.Tx) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #1274: we used to suspend accounts by deleting their "verified" key,
|
||||||
|
// now we save some metadata under a new key
|
||||||
|
func schemaChangeV17ToV18(config *Config, tx *buntdb.Tx) error {
|
||||||
|
now := time.Now().UTC()
|
||||||
|
|
||||||
|
exists := "account.exists "
|
||||||
|
suspended := "account.suspended "
|
||||||
|
verif := "account.verified "
|
||||||
|
verifCode := "account.verificationcode "
|
||||||
|
|
||||||
|
var accounts []string
|
||||||
|
|
||||||
|
tx.AscendGreaterOrEqual("", exists, func(key, value string) bool {
|
||||||
|
if !strings.HasPrefix(key, exists) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
account := strings.TrimPrefix(key, exists)
|
||||||
|
_, verifiedErr := tx.Get(verif + account)
|
||||||
|
_, verifCodeErr := tx.Get(verifCode + account)
|
||||||
|
if verifiedErr != nil && verifCodeErr != nil {
|
||||||
|
// verified key not present, but there's no code either,
|
||||||
|
// this is a suspension
|
||||||
|
accounts = append(accounts, account)
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
|
type accountSuspensionV18 struct {
|
||||||
|
TimeCreated time.Time
|
||||||
|
Duration time.Duration
|
||||||
|
OperName string
|
||||||
|
Reason string
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, account := range accounts {
|
||||||
|
var sus accountSuspensionV18
|
||||||
|
sus.TimeCreated = now
|
||||||
|
sus.OperName = "*"
|
||||||
|
sus.Reason = "[unknown]"
|
||||||
|
susBytes, err := json.Marshal(sus)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
tx.Set(suspended+account, string(susBytes), nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func getSchemaChange(initialVersion int) (result SchemaChange, ok bool) {
|
func getSchemaChange(initialVersion int) (result SchemaChange, ok bool) {
|
||||||
for _, change := range allChanges {
|
for _, change := range allChanges {
|
||||||
if initialVersion == change.InitialVersion {
|
if initialVersion == change.InitialVersion {
|
||||||
@ -944,4 +993,9 @@ var allChanges = []SchemaChange{
|
|||||||
TargetVersion: 17,
|
TargetVersion: 17,
|
||||||
Changer: schemaChangeV16ToV17,
|
Changer: schemaChangeV16ToV17,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
InitialVersion: 17,
|
||||||
|
TargetVersion: 18,
|
||||||
|
Changer: schemaChangeV17ToV18,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,14 @@ import (
|
|||||||
"github.com/oragono/oragono/irc/utils"
|
"github.com/oragono/oragono/irc/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// produce a hardcoded version of the database schema
|
||||||
|
// XXX instead of referencing, e.g., keyAccountExists, we should write in the string literal
|
||||||
|
// (to ensure that no matter what code changes happen elsewhere, we're still producing a
|
||||||
|
// db of the hardcoded version)
|
||||||
|
importDBSchemaVersion = 18
|
||||||
|
)
|
||||||
|
|
||||||
type userImport struct {
|
type userImport struct {
|
||||||
Name string
|
Name string
|
||||||
Hash string
|
Hash string
|
||||||
@ -66,11 +74,7 @@ func doImportDBGeneric(config *Config, dbImport databaseImport, credsType Creden
|
|||||||
return fmt.Errorf("unsupported version of the db for import: version %d is required", requiredVersion)
|
return fmt.Errorf("unsupported version of the db for import: version %d is required", requiredVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
// produce a hardcoded version of the database schema
|
tx.Set(keySchemaVersion, strconv.Itoa(importDBSchemaVersion), nil)
|
||||||
// XXX instead of referencing, e.g., keyAccountExists, we should write in the string literal
|
|
||||||
// (to ensure that no matter what code changes happen elsewhere, we're still producing a
|
|
||||||
// db of the hardcoded version)
|
|
||||||
tx.Set(keySchemaVersion, "17", nil)
|
|
||||||
tx.Set(keyCloakSecret, utils.GenerateSecretKey(), nil)
|
tx.Set(keyCloakSecret, utils.GenerateSecretKey(), nil)
|
||||||
|
|
||||||
for username, userInfo := range dbImport.Users {
|
for username, userInfo := range dbImport.Users {
|
||||||
|
Loading…
Reference in New Issue
Block a user