-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.go
90 lines (78 loc) · 1.39 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package models
import (
"context"
"log"
"github.com/dgraph-io/dgo"
"github.com/dgraph-io/dgo/protos/api"
)
// LoadSchema makes sure the DGraph schema is loaded into the database on starting
func LoadSchema(db *dgo.Dgraph) {
op := &api.Operation{}
op.Schema = `
# Type predicate
type: [uid] .
# ContentNode Predicates
title: string @index(exact, fulltext) .
imageUri: string .
body: string @index(fulltext) .
created: dateTime @index(hour) .
edited: dateTime @index(hour) .
author: [uid] @reverse .
tags: [uid] @reverse .
score: float .
sentiment: float .
parent: [uid] @reverse .
type ContentNode {
title
imageUri
body
created
edited
author
tags
score
sentiment
parent
}
# Role Predicates
text: string @index(exact).
type Role {
text
}
type Tag {
text
}
# Invite Predicates
code: string @index(hash) .
invitedBy: [uid] .
type Invite {
code
invitedBy
}
# User Predicates
name: string @index(exact) .
password: password .
email: string @index(hash) .
aviImgUri: string .
reputation: float .
spent: float .
role: [uid] @reverse .
invitedBy: [uid] @reverse .
joined: dateTime .
type User {
name
password
email
aviImgUri
reputation
spent
role
invitedBy
joined
}
`
err := db.Alter(context.Background(), op)
if err != nil {
log.Fatal(err)
}
}