Skip to content

Actually disable all REST #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ The usage is based on the node-db-migrate project.

- `dataSource`

[String] : Datasource to connect the Migration and MigrationMap models to. *(default: db)*
[String] : Datasource to connect the Migration model to. *(default: db)*

- `acls`

[Array] : ACLs to apply to Migration and MigrationMap models. *(default: [])*
[Array] : ACLs to apply to Migration model. *(default: [])*


## Running Migrations
Expand Down
31 changes: 6 additions & 25 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var debug = require('debug')('loopback-component-migrate');
var loopback = require('loopback');
var migrationDef = require('./models/migration.json');
var migrationMapDef = require('./models/migration-map.json');

// Remove proerties that will confuse LB
function getSettings(def) {
Expand Down Expand Up @@ -30,12 +29,11 @@ module.exports = function(app, options) {
}

var migrationModelSettings = getSettings(migrationDef);
var migrationMapModelSettings = getSettings(migrationMapDef);

if (typeof options.acls !== 'object') {
migrationModelSettings.acls = migrationMapModelSettings.acls = [];
migrationModelSettings.acls = [];
} else {
migrationModelSettings.acls = migrationMapModelSettings.acls = options.acls;
migrationModelSettings.acls = options.acls;
}

// Support for loopback 2.x.
Expand All @@ -51,27 +49,10 @@ module.exports = function(app, options) {
migrationDef.properties,
migrationModelSettings);

debug('Creating MigrationMap model using settings: %o', migrationModelSettings);
var MigrationMapModel = dataSource.createModel(
migrationMapDef.name,
migrationMapDef.properties,
migrationMapModelSettings);

var Migration = require('./models/migration')(MigrationModel, options);
var MigrationMap = require('./models/migration-map')(MigrationMapModel, options);

app.model(Migration);
app.model(MigrationMap);

if (!options.enableRest) {
if (Migration.disableRemoteMethodByName) {
// Loopback 3.x+
Migration.disableRemoteMethodByName('migrateTo');
Migration.disableRemoteMethodByName('rollbackTo');
} else {
// Loopback 2.x
Migration.disableRemoteMethod('migrateTo', true);
Migration.disableRemoteMethod('rollbackTo', true);
}
}
app.model(Migration, {
public: !!options.enableRest,
dataSource: dataSource
});
};
3 changes: 0 additions & 3 deletions lib/models/migration-map.js

This file was deleted.

35 changes: 0 additions & 35 deletions lib/models/migration-map.json

This file was deleted.

9 changes: 8 additions & 1 deletion lib/models/migration.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@
},
"indexes": {
"name_index": {
"name": 1
"keys": {
"name": 1
},
"options": {
"unique": true
},
"columns": "name",
"kind": "unique"
}
},
"methods": {
Expand Down
3 changes: 0 additions & 3 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ describe('loopback db migrate', function() {
expect(app.models.Migration).to.exist;
expect(app.models.Migration).itself.to.respondTo('migrate');
});
it('should attach a MigrationMap model to the app', function() {
expect(app.models.Migration).to.exist;
});
it('should provide a Migration.migrate() method', function() {
expect(app.models.Migration).itself.to.respondTo('migrate');
});
Expand Down