-
Notifications
You must be signed in to change notification settings - Fork 0
/
fauna-setup.js
86 lines (77 loc) · 2.41 KB
/
fauna-setup.js
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
const config = require('./env.json')
const faunadb = require('faunadb')
const q = faunadb.query;
const { Collection, CreateCollection, CreateIndex, Exists, If, Index } = q;
async function setup(faunaDBKey) {
try {
const faunadbClient = new faunadb.Client({ secret: faunaDBKey, keepAlive: true });
await faunadbClient.query(If(Exists(Collection('users')), true, CreateCollection({ name: 'users' })));
console.log('"users" collection created.')
await faunadbClient.query(If(Exists(Collection('follows')), true, CreateCollection({ name: 'follows' })));
console.log('"follows" collection created.')
await faunadbClient.query(If(Exists(Index('follows_index')), true,
CreateIndex(
{
name: 'follows_index',
source: Collection('follows'),
terms: [
{
field: ['data', 'from']
},
{
field: ['data', 'to']
}
],
unique: true,
}
)));
console.log('"follows_index" index created.');
await faunadbClient.query(If(Exists(Index('followee_ref_by_follower_index')), true,
CreateIndex(
{
name: 'followee_ref_by_follower_index',
source: Collection('follows'),
terms: [
{
field: ['data', 'to']
}
],
values: [
{
field: ['data', 'from']
}
],
}
)));
console.log('"followee_ref_by_follower_index" index created.');
await faunadbClient.query(If(Exists(Index('follow_record_by_followee_index')), true,
CreateIndex(
{
name: 'follow_record_by_followee_index',
source: Collection('follows'),
terms: [
{
field: ['data', 'to']
}
],
}
)));
console.log('"follow_record_by_followee_index" index created.');
await faunadbClient.query(If(Exists(Index('follow_record_by_follower_index')), true,
CreateIndex(
{
name: 'follow_record_by_follower_index',
source: Collection('follows'),
terms: [
{
field: ['data', 'from']
}
],
}
)));
console.log('"follow_record_by_follower_index" index created.');
} catch (error) {
console.error(error)
}
}
setup(config.FAUNADB_SECRET_KEY).then(() => console.log('finished'))