Use knex instead of js-data
This commit is contained in:
27
lib/db/connector.js
Normal file
27
lib/db/connector.js
Normal file
@ -0,0 +1,27 @@
|
||||
var path = require('path');
|
||||
var knexModule = require('knex');
|
||||
|
||||
module.exports = function connector(options) {
|
||||
var dbOptions = options.dbOptions;
|
||||
dbOptions.useNullAsDefault = true;
|
||||
if (!dbOptions.migrate) {
|
||||
return knexModule(dbOptions);
|
||||
}
|
||||
|
||||
dbOptions.migrations = { directory: path.resolve(__dirname, 'migrations') };
|
||||
dbOptions.seeds = { directory: path.resolve(__dirname, 'seeds') };
|
||||
var knex = knexModule(dbOptions);
|
||||
|
||||
knex.migrate.latest()
|
||||
.then(function() {
|
||||
return knex.seed.run();
|
||||
})
|
||||
.then(function() {
|
||||
console.log('Migrations are finished.');
|
||||
})
|
||||
.catch(function(error) {
|
||||
console.error(error);
|
||||
});
|
||||
|
||||
return knexModule(dbOptions);
|
||||
};
|
39
lib/db/migrations/reports.js
Normal file
39
lib/db/migrations/reports.js
Normal file
@ -0,0 +1,39 @@
|
||||
exports.up = function(knex, Promise) {
|
||||
return Promise.all([
|
||||
knex.schema.createTable('remotedev_reports', function(table) {
|
||||
table.uuid('id').primary();
|
||||
table.string('type');
|
||||
table.string('title');
|
||||
table.string('description');
|
||||
table.string('action');
|
||||
table.text('payload');
|
||||
table.text('preloadedState');
|
||||
table.text('screenshot');
|
||||
table.string('userAgent');
|
||||
table.string('version');
|
||||
table.string('user');
|
||||
table.string('userId');
|
||||
table.string('meta');
|
||||
table.string('exception');
|
||||
table.timestamp('added');
|
||||
table.uuid('appId')
|
||||
.references('id')
|
||||
.inTable('remotedev_apps');
|
||||
}),
|
||||
|
||||
knex.schema.createTable('remotedev_apps', function(table){
|
||||
table.uuid('id').primary();
|
||||
table.string('title');
|
||||
table.string('description');
|
||||
table.string('url');
|
||||
table.timestamps();
|
||||
})
|
||||
])
|
||||
};
|
||||
|
||||
exports.down = function(knex, Promise) {
|
||||
return Promise.all([
|
||||
knex.schema.dropTable('remotedev_reports'),
|
||||
knex.schema.dropTable('remotedev_apps')
|
||||
])
|
||||
};
|
12
lib/db/seeds/apps.js
Normal file
12
lib/db/seeds/apps.js
Normal file
@ -0,0 +1,12 @@
|
||||
exports.seed = function(knex, Promise) {
|
||||
return Promise.all([
|
||||
knex('remotedev_apps').del()
|
||||
]).then(function() {
|
||||
return Promise.all([
|
||||
knex('remotedev_apps').insert({
|
||||
id: '78626c31-e16b-4528-b8e5-f81301b627f4',
|
||||
title: 'Default'
|
||||
})
|
||||
]);
|
||||
});
|
||||
};
|
Reference in New Issue
Block a user