-
Notifications
You must be signed in to change notification settings - Fork 0
/
seed.js
executable file
·63 lines (58 loc) · 2.11 KB
/
seed.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
'use strict';
var Database = require('./packages/server/Database');
var Configurator = require('archivist-js').ServerConfigurator;
var StorePackage = require('archivist-js').ArchivistStorePackage;
var db = new Database();
var configurator = new Configurator().import(StorePackage);
if (process.argv[2] === 'dev') {
var devSeed = require('./data/devSeed');
// eslint-disable-next-line
console.log('Development seeding...');
db.reset() // Clear the database, set up the schema
.then(function() {
// We should drop connection and establish it again,
// so massive will have new tables attached
db.shutdown();
db = new Database();
configurator.setDBConnection(db);
var userStore = configurator.getStore('user');
return userStore.seed(devSeed.users);
}).then(function() {
var sessionStore = configurator.getStore('session');
return sessionStore.seed(devSeed.sessions);
}).then(function() {
var entityStore = configurator.getStore('entity');
return entityStore.seed(devSeed.entities);
}).then(function() {
var documentStore = configurator.getStore('document');
return documentStore.seed(devSeed.documents);
}).then(function() {
var changeStore = configurator.getStore('change');
return changeStore.seed(devSeed.changes);
}).then(function() {
// eslint-disable-next-line
console.log('Done seeding.');
db.shutdown();
});
} else {
var seed = require('./data/seed');
// eslint-disable-next-line
console.log('Database setup...');
db.reset()
.then(function() {
// We should drop connection and establish it again,
// so massive will have new tables attached
db.shutdown();
db = new Database();
configurator.setDBConnection(db);
var userStore = configurator.getStore('user');
return userStore.seed(seed.users);
}).then(function() {
var sessionStore = configurator.getStore('session');
return sessionStore.seed(seed.sessions);
}).then(function() {
// eslint-disable-next-line
console.log('Done seeding.');
db.shutdown();
});
}