update db versions, fix copy-paste error

This commit is contained in:
or-else
2023-02-01 12:58:28 -08:00
parent 319a5fd421
commit 589046725d
3 changed files with 23 additions and 5 deletions

View File

@ -41,7 +41,7 @@ const (
defaultHost = "localhost:27017"
defaultDatabase = "tinode"
adpVersion = 112
adpVersion = 113
adapterName = "mongodb"
defaultMaxResults = 1024
@ -323,6 +323,11 @@ func (a *adapter) CreateDb(reset bool) error {
SetPartialFilterExpression(b.M{"devices.deviceid": b.M{"$exists": true}}),
},
},
// Index on lastSeen and updatedat for deleting stale user accounts.
{
Collection: "users",
IndexOpts: mdb.IndexModel{Keys: b.D{{"lastseen", 1}, {"updatedat", 1}}},
},
// User authentication records {_id, userid, secret}
// Should be able to access user's auth records by user id
@ -514,6 +519,18 @@ func (a *adapter) UpgradeDb() error {
}
}
if a.version == 112 {
// Create secondary index on Users(lastseen,updatedat) for deleting stale user accounts.
if _, err = a.db.Collection("users").Indexes().CreateOne(a.ctx,
mdb.IndexModel{Keys: b.D{{"lastseen", 1}, {"updatedat", 1}}}); err != nil {
return err
}
if err := bumpVersion(a, 113); err != nil {
return err
}
}
if a.version != adpVersion {
return errors.New("Failed to perform database upgrade to version " + strconv.Itoa(adpVersion) +
". DB is still at " + strconv.Itoa(a.version))
@ -2705,7 +2722,7 @@ func (a *adapter) PCacheExpire(keyPrefix string, olderThan time.Time) error {
return t.ErrMalformed
}
_, err := a.db.Collection("dellog").DeleteMany(a.ctx, b.M{"createdat": b.M{"$lt": olderThan},
_, err := a.db.Collection("kvmeta").DeleteMany(a.ctx, b.M{"createdat": b.M{"$lt": olderThan},
"_id": primitive.Regex{Pattern: "^" + keyPrefix}})
return err
}

View File

@ -34,7 +34,7 @@ const (
defaultHost = "localhost:28015"
defaultDatabase = "tinode"
adpVersion = 112
adpVersion = 113
adapterName = "rethinkdb"
@ -550,7 +550,8 @@ func (a *adapter) UpgradeDb() error {
}
if a.version == 112 {
// No useful indexes can be created, just bump the version.
// Secondary indexes cannot store NULLs, consequently no useful indexes can be created.
// Just bump the version.
if err := bumpVersion(a, 113); err != nil {
return err
}

View File

@ -14,7 +14,7 @@
"mongodb": {
"database": "tinode",
"addresses": "localhost:27017",
"replica_set": "rs0",
//"replica_set": "rs0",
//"auth_source": "admin",
//"username": "tinode",
//"password": "tinode",