/
schema.go
60 lines (58 loc) · 1.54 KB
/
schema.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package database
import (
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
// schema returns a mapping between a collection name and the indexes that
// must exist for that collection.
//
// We return a map literal instead of using a global variable because the global
// variable causes data races when multiple tests are creating their own
// databases and are iterating over the schema at the same time.
func schema() map[string][]mongo.IndexModel {
return map[string][]mongo.IndexModel{
collConfig: {
{
Keys: bson.D{{"key", 1}},
Options: options.Index().SetName("key").SetUnique(true),
},
},
collServerLoad: {
{
Keys: bson.D{{"server_name", 1}},
Options: options.Index().SetName("server_name").SetUnique(true),
},
{
Keys: bson.D{{"load", 1}},
Options: options.Index().SetName("load"),
},
},
collSkylinks: {
{
Keys: bson.D{{"skylink", 1}},
Options: options.Index().SetName("skylink").SetUnique(true),
},
{
Keys: bson.D{{"locked_by", 1}},
Options: options.Index().SetName("locked_by"),
},
{
Keys: bson.D{{"lock_expires", 1}},
Options: options.Index().SetName("lock_expires"),
},
{
Keys: bson.D{{"servers", 1}},
Options: options.Index().SetName("servers"),
},
{
Keys: bson.D{{"pinned", 1}},
Options: options.Index().SetName("pinned"),
},
{
Keys: bson.D{{"failed_attempts", 1}},
Options: options.Index().SetName("failed_attempts"),
},
},
}
}