joyent-portal/packages/portal-api/bootstrap-data.js

54 lines
1.1 KiB
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 () {
2017-06-21 19:15:17 +03:00
const data = new Data({
db: {
host: process.env.RETHINK_HOST || 'localhost'
}
});
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 () {
2017-06-21 19:15:17 +03:00
const dropData = new Data({
db: {
host: process.env.RETHINK_HOST || 'localhost'
}
});
dropData.connect(() => {
dropData._db.r.dbDrop('portal').run(dropData._db._connection, () => {
bootstrap();
});
});
};
main();