-
Notifications
You must be signed in to change notification settings - Fork 11
/
setup.js
309 lines (284 loc) · 7.42 KB
/
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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
import Realm from 'realm'
import context from './context.js'
import fs from './fs.js'
import agent from './agent.js'
async function setup(reset) {
context.settings.configured = false;
console.log("begin pervasync setup.js, setup(), context.settings.path=" + context.settings.path);
if (reset) {
console.log("will reset");
await agent.destroy();
if (context.pvcAdminRealm) {
context.pvcAdminRealm.close();
}
await fs.rmrf(context.settings.path);
}
let exists = await fs.exists(context.settings.path);
if (!exists) {
await fs.mkdir(context.settings.path);
}
let dbFolder = context.settings.path + "/db";
exists = await fs.exists(dbFolder);
if (!exists) {
await fs.mkdir(dbFolder);
}
let filesFolder = context.settings.path + "/files";
exists = await fs.exists(filesFolder);
if (!exists) {
await fs.mkdir(filesFolder);
}
let adminDbPath = dbFolder + "/" + context.settings.adminDbName;
let encryptionKey = context.settings.encryptionKey;
let schemaVersion = -1;
try {
if (encryptionKey) {
schemaVersion = Realm.schemaVersion(adminDbPath, encryptionKey);
} else {
schemaVersion = Realm.schemaVersion(adminDbPath);
}
} catch (err) {
console.log("pervasync setup.js, setup(), err=" + err);
}
console.log("pervasync setup.js, setup(), schemaVersion =" + schemaVersion);
let pvc__sync_client_properties = {
name: "pvc__sync_client_properties",
primaryKey: "NAME",
properties: {
NAME: "string",
VALUE: "string"
}
};
let pvc__sync_schemas = {
name: "pvc__sync_schemas",
primaryKey: "SYNC_SCHEMA_ID",
properties: {
SYNC_SCHEMA_ID: "int",
SYNC_CLIENT_ID: "int",
SYNC_SCHEMA_NAME: "string",
SERVER_DB_TYPE: "string",
SERVER_DB_SCHEMA: "string",
CLIENT_DB_SCHEMA: "string",
DEF_CN: "int",
SUB_CN: "int",
DATA_CN: "int",
NO_INIT_SYNC_NETWORKS: { type: "string", optional: true },
NO_SYNC_NETWORKS: { type: "string", optional: true },
ADDED: "date"
}
};
let pvc__sync_table_columns = {
name: "pvc__sync_table_columns",
primaryKey: "SYNC_TABLE_ID__NAME",
properties: {
SYNC_TABLE_ID__NAME: "string",
SYNC_TABLE_ID: { type: 'int', indexed: true },
NAME: "string",
DEVICE_COL_DEF: "string",
JDBC_TYPE: "int",
NATIVE_TYPE: "string",
COLUMN_SIZE: "int",
SCALE: "int",
NULLABLE: "string",
PK_SEQ: "int",
ORDINAL_POSITION: "int",
ADDED: "date"
}
};
let pvc__sync_tables = {
name: "pvc__sync_tables",
primaryKey: "ID",
properties: {
ID: "int",
SYNC_SCHEMA_ID: { type: 'int', indexed: true },
NAME: "string",
RANK: "int",
DEF_CN: "int",
DEF_CT: "string",
SUBSETTING_MODE: "string",
SUBSETTING_QUERY: "string",
IS_NEW: "string",
ALLOW_CHECK_IN: "string",
ALLOW_REFRESH: "string",
CHECK_IN_SUPER_USERS: "string",
COLUMNS: { type: "list", objectType: "pvc__sync_table_columns" },
ADDED: "date"
}
};
let pvc__sequences = {
name: "pvc__sequences",
primaryKey: "PVC_COMPOSITE_PK",//SEQ_SCHEMA__SEQ_NAME
properties: {
PVC_COMPOSITE_PK: "string",
SEQ_SCHEMA: { type: "string", indexed: true },
SEQ_NAME: "string",
START_VALUE: "int",
MAX_VALUE: "int",
CURRENT_VALUE: "int"
}
};
let pvc__sync_files = {
name: "pvc__sync_files",
primaryKey: "SYNC_FOLDER_ID__FILE_NAME",
properties: {
SYNC_FOLDER_ID__FILE_NAME: "string",
SYNC_FOLDER_ID: { type: "int", indexed: true },
FILE_NAME: "string",
IS_DIRECTORY: "string",
LENGTH: "int",
LAST_MODIFIED: "int",
FILE_CN: "int",
FILE_CT: "string",
TXN__: { type: "int", optional: true },
ADDED: "date"
}
};
let pvc__sync_folders = {
name: "pvc__sync_folders",
primaryKey: "ID",
properties: {
ID: "int",
SYNC_CLIENT_ID: "int",
SYNC_FOLDER_NAME: "string",
SERVER_FOLDER_PATH: "string",
CLIENT_FOLDER_PATH: "string",
RECURSIVE: "string",
FILE_PATH_STARTS_WITH: "string",
FILE_NAME_ENDS_WITH: "string",
ALLOW_CHECK_IN: "string",
ALLOW_REFRESH: "string",
CHECK_IN_SUPER_USERS: "string",
DEF_CN: "int",
SUB_CN: "int",
FILE_CN: "int",
NO_INIT_SYNC_NETWORKS: { type: "string", optional: true },
NO_SYNC_NETWORKS: { type: "string", optional: true },
ADDED: "date"
}
};
let pvc__lob_locators = {
name: "pvc__lob_locators",
primaryKey: "ID",
properties: {
ID: "int",
COMMAND: "string",
LOB_LOCATOR: "string",
ADDED: "date"
}
};
let pvc__sync_history = {
name: "pvc__sync_history",
primaryKey: "ID",
properties: {
ID: "int",
USER_NAME: "string",
DEVICE_NAME: "string",
BEGIN_TIME: "date",
SYNC_TYPE: "string",
SYNC_DIRECTION: "string",
DURATION: "int",
CHECK_IN_STATUS: "string",
CHECK_IN_DELETES: "int",
CHECK_IN_INSERTS: "int",
CHECK_IN_UPDATES: "int",
REFRESH_STATUS: "string",
REFRESH_DELETES: "int",
REFRESH_INSERTS: "int",
REFRESH_UPDATES: "int",
HAS_DEF_CHANGES: "string",
ERROR_CODE: "int",
MESSAGES: "string"
}
};
let pvc__payload_out = {
name: "pvc__payload_out",
primaryKey: "ID",
properties: {
ID: "int",
PAYLOAD: "string"
}
};
let pvc__payload_in = {
name: "pvc__payload_in",
primaryKey: "ID",
properties: {
ID: "int",
PAYLOAD: "string"
}
};
let migrationFunction = function () { };
let realmDef = {
path: adminDbPath,
schema: [
pvc__sync_client_properties,
pvc__sync_schemas,
pvc__sync_table_columns,
pvc__sync_tables,
pvc__sequences,
pvc__sync_files,
pvc__sync_folders,
pvc__lob_locators,
pvc__sync_history,
pvc__payload_out,
pvc__payload_in
],
schemaVersion: 1,
migration: migrationFunction
}
if (encryptionKey) {
realmDef.encryptionKey = encryptionKey;
}
/*
let sync_client_properties_1 = Object.assign({}, sync_client_properties);
let migrationFunction1 = function(oldRealm, newRealm) {};
let schema_1 = {
path: path,
schema: [
pvc__sync_client_properties_1,
pvc__sync_schemas,
pvc__sync_table_columns,
pvc__sync_tables,
pvc__sequences,
pvc__sync_files,
pvc__sync_folders,
pvc__sync_history
],
schemaVersion: 1,
migration: migrationFunction1
}
*/
/*/ migration
let schemas = [
schema_0//, schema_1
]
if (schemaVersion > -1) {
schemaVersion++;
while (schemaVersion < schemas.length) {
let migratedRealm;
if (encryptionKey) {
migratedRealm = new Realm(schemas[schemaVersion++], encryptionKey);
} else {
migratedRealm = new Realm(schemas[schemaVersion++]);
}
migratedRealm.close();
}
}
if (encryptionKey) {
realm = new Realm(schemas[schemas.length - 1], encryptionKey);
} else {
realm = new Realm(schemas[schemas.length - 1]);
}*/
/*let realm;
if (encryptionKey) {
realm = new Realm(schema, encryptionKey);
} else {
realm = new Realm(schema);
}*/
let realm = await Realm.open(realmDef);
context.pvcAdminRealm = realm;
await agent.init();
context.settings.configured = true;
console.log("end pervasync setup.js, setup()");
}
export default {
setup
}