1
0
mirror of https://github.com/yldio/copilot.git synced 2024-11-28 14:10:04 +02:00
copilot/packages/portal-api/bootstrap-data.js

46 lines
930 B
JavaScript
Raw Normal View History

2017-05-03 22:48:15 +03:00
'use strict';
2017-06-05 23:54:44 +03:00
const Data = require('portal-data');
2017-05-03 22:48:15 +03:00
2017-06-05 23:54:44 +03:00
const ifError = function (err) {
if (err) {
console.error(err);
process.exit(1);
}
};
const bootstrap = function () {
const data = new Data();
2017-06-05 23:54:44 +03:00
data.connect(() => {
data.createDatacenter({ region: 'us-sw-1', name: 'us-sw-1' }, (err, datacenter) => {
2017-06-05 23:54:44 +03:00
ifError(err);
data.createUser({ firstName: 'Nikola', lastName: 'Tesla', email: 'nikola@tesla.com', login: 'nikola' }, (err, user) => {
2017-06-05 23:54:44 +03:00
ifError(err);
data.createPortal({
user,
datacenter
}, (err, portal) => {
2017-06-05 23:54:44 +03:00
ifError(err);
console.log('data bootstrapped');
process.exit(0);
});
});
2017-05-03 22:48:15 +03:00
});
});
};
const main = function () {
const dropData = new Data();
dropData.connect(() => {
dropData._db.r.dbDrop('portal').run(dropData._db._connection, () => {
bootstrap();
});
});
};
main();