-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpopulateDB.js
141 lines (136 loc) · 3.71 KB
/
populateDB.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
const mongoose = require('mongoose');
const { uid } = require('uid/secure');
require('dotenv').config({ path: '../../.env' });
const connection = mongoose.createConnection(process.env.MONGO_DB || 'mongodb://root:example@localhost:27017/admin');
const orionURL = process.env.REACT_APP_ORION || 'http://localhost:1026';
const TenantConfig = new mongoose.Schema({
name: String,
icon: String,
primaryColor: String,
secondaryColor: String,
customImage: mongoose.Schema.Types.Mixed
});
const ResourceType = new mongoose.Schema({
ID: {
type: String,
unique: true
},
userID: String,
name: String,
tenantName: String,
endpointUrl: String
});
const Config = connection.model('TenantConfig', TenantConfig);
const userSettings = new mongoose.Schema({
userName: {
type: String,
unique: true
},
language: String,
lastTenantSelected: String
});
const Resource = connection.model('ResourceType', ResourceType);
const Settings = connection.model('userSettings', userSettings);
Resource.deleteMany({}, function (err) {
Resource.create(
{
ID: uid(16),
userID: '',
name: 'entity',
tenantName: 'Tenant1',
endpointUrl: orionURL + '/v2/entities?attrs=id&orderBy=id'
},
function (err) {
if (err) {
console.log(err);
} else {
Resource.create(
{
ID: uid(16),
userID: '',
name: 'entity',
tenantName: 'Tenant2',
endpointUrl: orionURL + '/v2/entities?attrs=id&orderBy=id'
},
function (err) {
if (err) {
console.log(err);
} else {
Resource.create(
{
ID: uid(16),
userID: '',
name: 'entityType',
tenantName: 'Tenant1',
endpointUrl: orionURL + '/v2/types'
},
function (err) {
if (err) {
console.log(err);
} else {
Resource.create(
{
ID: uid(16),
userID: '',
name: 'entityType',
tenantName: 'Tenant2',
endpointUrl: orionURL + '/v2/types'
},
function (err) {
if (err) {
console.log(err);
}
}
);
}
}
);
}
}
);
}
}
);
Settings.deleteMany({}, function (err) {
Config.deleteMany({}, function (err) {
console.log('PopulateDB: clear old data...');
if (err) {
console.log(err);
} else {
Config.create(
{
name: 'Tenant1',
icon: 'none',
primaryColor: '#8086ba',
secondaryColor: '#8086ba',
customImage: ''
},
function (err) {
if (err) {
console.log(err);
} else {
console.log('Tenant1 created!');
Config.create(
{
name: 'Tenant2',
icon: 'none',
primaryColor: '#8086ba',
secondaryColor: '#8086ba',
customImage: ''
},
function (err) {
if (err) {
console.log(err);
} else {
console.log('Tenant2 created!');
process.exit();
}
}
);
}
}
);
}
});
});
});